Skip to content

Latest commit

 

History

History
126 lines (106 loc) · 4.06 KB

javascript.md

File metadata and controls

126 lines (106 loc) · 4.06 KB

JavaScript の全般メモ(あとで整理する)

// package.json
"type": "module"
// ES6のモジュール側
export const helloWorld = function() {
    console.log('Hello World!!');
}

// ES6の読み込み側
import { helloWorld } from './module'
helloWorld();
// ==========================================================================
//CommonJSのモジュール側
module.exports = function() {
    console.log('Hello World!!');
}

//CommonJSの読み込み側
const helloWorldModule = require('./module.js');
helloWorldModule();
// 出力:Hello World!!

eslint&prettier

完全版 eslint&prettier&vscode

  • Prettier.コードフォーマッター(ソースコードを整形してくれるツール)のこと
  • eslint.リンター.問題点を指摘してくれる静的解析ツール
  • prettier でフォーマット後 eslint で解析する.eslint のフォーマットは無効にする
  • eslint-config-prettier.Prettier と競合する ESLint ルールを無効化するためのプラグイン
  1. vscode のプラグインである eslint,prettier インストール
yarn add eslint prettier eslint-config-prettier
  1. eslint の設定
touch .eslintrc.json
{
    "env": {
        "browser": true,
        "es2021": true
    },
    "extends": ["eslint:recommended", "prettier"],
    "parserOptions": {
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "rules": {}
}
  1. prettier の設置
touch .prettierrc
{
    "doubleQuote": true,
    "trailingComma": "all",
    "tabWidth": 4
}
  1. vscode の設定
  • ユーザワークスペースの settings.json に記入
{
    // このファイルは/.vscode/settings.jsonです
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
    },
    "eslint.format.enable": false,
    "editor.formatOnSave": true,
    "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[json]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "editor.lineNumbers": "on",
    "editor.rulers": [80],
    "editor.wordWrap": "on",
    "eslint.packageManager": "yarn",
    "files.insertFinalNewline": true,
    "files.trimTrailingWhitespace": true,
    "npm.packageManager": "yarn",
    "typescript.enablePromptUseWorkspaceTsdk": true
}

Client Side Rendering(CSR) Server Side Rendering(SSR) Static Site Generation(SSG) Incremental Static Regeneration(ISR) Server Side Component(SSC)