$ touch .gitignore
$ mkdir src
$ touch src/index.js
$ mkdir styles
$ touch styles/index.css
Yarn is a package manager.
Using Homebrew
$ brew install yarn
If you use nvm, intall without node.
$ brew install yarn --without-node
$ brew upgrade yarn
Starting a new project:
$ yarn init
Adding a dependency:
$ yarn add [package]
$ yarn add [package]@[version]
$ yarn add [package]@[tag]
$ yarn add --dev [package]
Removing dependency:
$ yarn remove [package]
Installing all the dependencies of project:
$ yarn
$ yarn install
$ yarn add --dev webpack webpack-cli webpack-merge
$ touch webpack.common.config.js
$ touch webpack.dev.config.js
$ touch webpack.prod.config.js
Include in package.json
:
"scripts": {
"build": "webpack --config webpack.prod.config.js",
"start": "webpack-dev-server --config webpack.dev.config.js --hot --inline"
}
$ yarn add --dev style-loader css-loader mini-css-extract-plugin
From your js file, you can just import:
import './style.css';
$ yarn add --dev file-loader
Now you can import in your JavaScript file:
import Icon from './icon.png';
...
var myIcon = new Image();
myIcon.src = Icon;
element.appendChild(myIcon);
And use the image in CSS:
.hello {
background: url('./icon.png');
}
@font-face {
font-family: 'MyFont';
src: url('./my-font.woff2') format('woff2'),
url('./my-font.woff') format('woff');
font-weight: 600;
font-style: normal;
}
.hello {
font-family: 'MyFont';
}
$ yarn add --dev html-webpack-plugin html-loader
$ touch src/index.html
$ yarn add --dev clean-webpack-plugin
$ yarn add --dev webpack-dev-server
Include into webpack.config.js
devServer: {
contentBase: './dist'
},
Include into scripts in package.json
:
"start": "webpack-dev-server --open"
$ yarn add --dev express webpack-dev-middleware
$ touch server.js
In webpack.config.js, add publicPath into output:
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
}
$ yarn add --dev @babel/core babel-loader @babel/preset-env @babel/preset-react
$ touch .babelrc
Add loader to webpack.config.js
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader']
},
$ yarn add --dev eslint eslint-loader
$ touch .eslintignore
$ ./node_modules/.bin/eslint --init
package.json
"scripts": {
"lint": "eslint . --ext .js",
}
$ yarn add --dev jest
$ yarn add --dev babel-jest regenerator-runtime
package.json
"scripts": {
"test": "jest",
"test-watch": "jest --watch"
}
$ yarn add react react-dom