Source: [https://github.com/datadoodler/ts-00-active-webpack.git]
Webpack Notes
There are many options for using webpack. These notes won’t be an exhaustive treatise on the subject, but merely cover how to implement webpack for my usage current scenario, namely, the DataDoodler Administration Dashboard.
Installation
Basic webpack, and (optionally) the dev server, which provides a basic express app.
1 | npm-install --save-dev webpack, webpack-dev-server |
Loaders: Webpack assumes all files are javascript unless additional loaders are invoked to handle other file types.
npm install –save-dev css-loader style-loader
Running
1 | webpack --devtool source-map ./entry.js bundle.js -w |
- source-map: Browser will show source files individually under the “webpack/.” namespace.
- ./entry.js: The starting point. Webpack will not only compile this file, but will use it as a starting point and recursively compile any external files that it detects are dependencies.
- bundle.js: the target file that will receive all the Webpack goodness.
- -w: webpack will watch for changes and automatically recompile.
More convenint to use a config file
You can use the command line to specify a lot of the options for running webpack, but using a config file is much more convenient. Webpack will look for webpack.config.js
1 | module.exports = { |
Install the command line interface for the webpack dev server.
1 | webpack-dev-server -g |
package.json
this is package.json
1 | { |