Main Tool: prettier
(https://prettier.io/)
{
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
{
"scripts": {
"format": "prettier --write",
"format:all": "prettier --write 'src/**/*.js'",
}
π VSCode extension: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
husky
- tool for githooks (https://www.npmjs.com/package/husky)pretty-quick
- prettier githook implementation (https://www.npmjs.com/package/pretty-quick)
{
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged --pattern 'src/**/*.js'"
}
}
}
Main Tool: eslint
(https://eslint.org/)
{
"scripts": {
"lint": "eslint 'src/**/*.js'",
}
{
"env": {
"browser": true,
"es6": true
},
"extends": ["eslint:recommended", "prettier"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"no-console": "off"
}
}
eslint:recomendder
rules - https://eslint.org/docs/rules/
{
"env": {
"browser": true,
"es6": true
},
"extends": ["eslint:recommended", "prettier"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"prettier/prettier": "error",
"no-console": "off"
},
"plugins": ["prettier"]
}
Airbnb javascript: https://github.com/airbnb/javascript
Tools: eslint-config-airbnb-base
(https://www.npmjs.com/package/eslint-config-airbnb-base)
{
"env": {
"browser": true,
"es6": true
},
"extends": ["eslint:recommended", "airbnb-base/legacy", "prettier"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"prettier/prettier": "error",
"no-console": "off"
},
"plugins": ["prettier"]
}
π VSCode extension for eslint: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
Main Tool: babel
(https://babeljs.io)
{
"presets": ["@babel/preset-env"]
}
{
"scripts": {
"babel": "babel 'src/**/*.js' -d transpiled/",
}
> 0.25%
not dead
browserslist project - https://github.com/browserslist/browserslist
Main Tool: webpack
(https://webpack.js.org/)
{
"scripts": {
"build": "webpack",
}
webpack-dev-server
(https://webpack.js.org/configuration/dev-server/)webpack-merge
(https://github.com/survivejs/webpack-merge)clean-webpack-plugin
(https://github.com/johnagan/clean-webpack-plugin)html-webpack-plugin
(https://github.com/jantimon/html-webpack-plugin)uglifyjs-webpack-plugin
(https://github.com/webpack-contrib/uglifyjs-webpack-plugin)babel-loader
(https://github.com/babel/babel-loader)
Installation: npm i --save webpack-dev-server webpack-merge clean-webpack-plugin html-webpack-plugin uglifyjs-webpack-plugin babel-loader
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
filename: '[hash]-bundle.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
plugins: [new CleanWebpackPlugin(), new HtmlWebpackPlugin()]
};
const merge = require('webpack-merge');
const mainConfig = require('./webpack.config.js');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = merge(mainConfig, {
mode: 'production',
devtool: 'source-map',
optimization: {
minimizer: [
new UglifyJsPlugin({
test: /\.(js)$/
})
]
}
});
const path = require('path');
const merge = require('webpack-merge');
const mainConfig = require('./webpack.config.js');
module.exports = merge(mainConfig, {
mode: 'development',
devtool: 'inline-source-map',
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000
}
});
{
"scripts": {
"build": "webpack --config webpack.prod.js",
"dev": "webpack-dev-server --open --config webpack.dev.js"
}
}