This is a demo for creating a project using Webpack. It utilizes JavaScript modules for clearer code and portability.
First, you will need NodeJS installed on your system. This program is compatible with version 8.11.* LTS.
Installing NodeJS will also install the Node Package managaer - NPM. This will add the npm
command line tool to the Windows path. From a command line, enter the following command to install the dependencies.
$ npm install
The following commands are available for this demo. They should work from both the Windows and Mac/Linux command line.
Alias to npm run build:dev
.
Create a development build. The output will be saved in the dist/
folder.
$ npm run build:dev
Create a production build. The output will be saved in the dist/
folder. See the Webpack documentation for details on the differences between development and production build.
$ npm run build:prod
Run the program. This will create a development build of the program, and it will use a watch to keep the bundle up to date and refresh your browser window.
$ npm run start
Unit tests are written in Jest. Jest requires tests to be written in NodeJS-compatible module syntax, so the babbel-jest plugin is required change ES6 modules to Node modules.
The output should be similar to the following. Hint: more tests may have been written since this README was last updated.
$ npm run test
> npm-web-demo@1.0.0 test C:\work\webpack-demo
> npx jest
C:\work\webpack-demo\node_modules\jest\bin\jest.js
PASS tests\stringifyArray.test.js
√ returns a simple string - [1, 2] (7ms)
√ returns a nested array - [[1, 2], [3, 4]]
√ returns a deeply nested array - [[1, 2], [3, 4], [[5]]] (1ms)
√ can stringify an empty array (1ms)
Test Suites: 1 passed, 1 total
Tests: 4 passed, 4 total
Snapshots: 0 total
Time: 2.294s
Ran all test suites.