npm init
npm install eslint --save-dev
- create
src
directory
- add
exporting.js
Nodejs module, exportuser
object from it - add
importing.js
module and import previously exporteduser
object
npm install eslint --save-dev
eslit --init
- add
check
task topackage.json
for analyzation all js files insrc
directory
npm install webpack --save-dev
- create
webpack.config.js
file and addconst path = require('path'); module.exports = { mode: "development", entry: "./src/index.js", output: { filename: "main.js", path: path.resolve(__dirname, 'dist') } };
- create
index.html
,index.js
andindex.scss
files - load
index.js
toindex.html
file npm install sass-loader node-sass style-loader css-loader --save-dev
- change output filename to
index.js
in dist folder - add rule to handle
scss
files by webpack npm i --save-dev html-webpack-plugin
- add
html-webpack-plugin
to configuration and use existingindex.html
as template npm i webpack-merge --save-dev
- divide configuration to dev/prod
- npm
build
task should run prod configuration, npmdev
task should run dev configuration npm i webpack-dev-server --save-dev
- configure npm
dev
task to serve files fromdist
directory and automatically open browser withindex.html
as main page npm i file-loader html-loader --save-dev
- add image to
src/assets
directory and attach it toindex.html
- configure webpack to handle images using
file-loader
andhtml-loader
npm i clean-webpack-plugin --save-dev
- configure webpack to use
clean-webpack-plugin
and cleandist
directory before next build
- Create
src/vendor.js
file which will keep all external dependencies e.g.bootstrap
,jquery
etc. - Configure webpack to load js from two entry points:
index.js
andvendor.js
- Configure prod configuration to output this two scripts as
index.bundle.js
andvendor.bundle.js
(you can usecontentHash
too in the name) npm install mini-css-extract-plugin --save-dev
- Configure webpack dev config to handle css like so far
- Configure webpack prod config to output css to separate files
- Configure
saas-loader
to not minify css (which by default is enabled) - Add
optimize-css-assets-webpack-plugin
as a css optimizer - Add
terser-webpack-plugin
as js optimizer
npm install mocha mocha-webpack webpack-node-externals
- add test configuration file
- add npm
test-mocha
task to test files ending with.spec.js
ext usingmocha-webpack
npm install glob jest
- add configuration for
jest
module.exports = { 'moduleNameMapper': { // eslint-disable-next-line max-len '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': 'tests/mocks/fileMock.js', '\\.scss$': 'tests/mocks/styleMock.js', }, 'moduleFileExtensions': ['js'], 'testMatch': ['**/*.js'], 'rootDir': 'dist_tests', };
- add npm
test-jest
task to test files ending with.spec.js
ext using purejest
- add example tests
- enable
source mapping
fordev
mode - throw Error in
index.js
file and see stack trace - enable
source mapping
forwebpack-mocha
to be able debug in IDE
npm install sinon mockttp --save-dev
npm install node-fetch
- Write async function making http request using
await
andnode-fetch
- Write test for previous async function using
sinon
to stubnode-fetch
library - Write test for async function using
mockhttp