0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vue.js Nuxt.js 初期インストールおよびプロジェクト作成(Mac)

0
Last updated at Posted at 2020-06-17

node.js インストール

$ brew install nodebrew
$ mkdir -p ~/.nodebrew/src
$ nodebrew -v
nodebrew 1.0.1

インストール可能なnode.jsのリストを表示

$ nodebrew ls-remote

version8.9.4をインストール

$ nodebrew install-binary v8.9.4
$ nodebrew ls
$ nodebrew use v8.9.4

nodeとnpmコマンドのパスを通す

$ nodebrew setup
$ echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bash_profile
$ source ~/.bash_profile

バージョン確認

$ node -v
v8.9.4
$ npm -v
5.6.0

vue-cli インストール

$ npm install -g @vue/cli
$ vue --version
@vue/cli 4.4.1

プロジェクト作成

  1. createコマンドで作成 (vue-cli3.x系)
$ vue create <プロジェクト名>
  1. nuxt.js のプロジェクト作成
$ npx create-nuxt-app <プロジェクト名>

起動

# npm なら
$ npm install
$ npm run dev

# yarn なら
$ yarn install
$ yarn run dev

sass導入

yarn add node-sass sass-loader

nuxt.config.jsに追記

module.exports = {
	css: [
		'@/assets/css/main.scss'
	]
}

フォーマッタを設定する

Prettier インストール

  1. eslint-plugin-prettierESLint と一緒に Prettier の機能を利用したい場合に導入するeslint-config-prettier
  2. Prettier とバッティングする、ESLint のフォーマット関係のルールを無効化する
yarn add prettier eslint-config-prettier eslint-plugin-prettier

プロジェクト配下に.eslintrc.js を作成する

module.exports = {
    root: true
    env: {
        node: true
    },
    extends: [
        'plugin:vue/essential',
        'eslint:recommended',
        'plugin:prettier/recommended' // EsLintとprettierを両方使用する場合に必要な設定
    ],
    plugins: ['vue'],
    rules: {
        // コーディングのルールを設定できる。設定項目に則った内容でエラーが出力されるようになる
        'prettier/prettier': [
        'error',
        {
            semi: true, // 文末にセミコロンを使用するか
            singleQuote: true, // 文字列にシングルコーテーションを使用すか
            trailingComma: 'es5' // es5の記法に従う
        }
        ],
        'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
        'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
    },
    parserOptions: {
        parser: 'babel-eslint'
    }
};

VSCode で「Prettier - Code formatter」をインストールする

setting.json に以下を追加

// JavaScriptでのみ保存時フォーマットを有効化
 "[javascript]": {
     "editor.formatOnSave": true
 },
 // prettierのシングルクオーテーションオプションをon
 "prettier.singleQuote" : true,
 // Eslintによって不適切と指摘された箇所をファイルの保存時に自動的にフォーマットする。
 "eslint.autoFixOnSave": true,

Tips

# yarn を入れてパッケージ管理をyarnでやる
npm install -g yarn
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?