

Now that you have a basic build together you should move on to the next guide Asset Management to learn how to manage assets like images and fonts with webpack. Ĭustom parameters can be passed to webpack by adding two dashes between the npm run build command and your parameters, e.g. You can also set it to 'none' to disable any default behavior. Now run the following command and see if your script alias works: npm run build

This convention is the standard in most npm-based projects because it allows all contributors to use the same set of common scripts (each with flags like -config if necessary). Note that within scripts we can reference locally installed npm packages by name the same way we did with npx. Now the npm run build command can be used in place of the npx command we used earlier. "test": "echo \"Error: no test specified\" & exit 1" + "test": "echo \"Error: no test specified\" & exit 1", + "build": "webpack" Let's adjust our package.json by adding an npm script:

Given it's not particularly fun to run a local copy of webpack from the CLI, we can set up a little shortcut. See the configuration documentation to learn more. We can specify loader rules, plugins, resolve options and many other enhancements this way. This will be useful for more complex configurations that need to be split into multiple files.Ī configuration file allows far more flexibility than simple CLI usage. We use the -config option here only to show that you can pass a config of any name. If a is present, the webpack command picks it up by default. Set 'mode' option to 'development' or 'production' to enable defaults for each environment. The 'mode' option has not been set, webpack will fallback to 'production' for this value. Now, let's run the build again but instead using our new configuration file: npx webpack -config Now we'll create the following directory structure, files and their contents: Throughout the Guides we will use diff blocks to show you what changes we're making to directories, files, and code.
UNPKG MOCHA INSTALL
Basic Setupįirst let's create a directory, initialize npm, install webpack locally, and install the webpack-cli (the tool used to run webpack on the command line): mkdir webpack-demo If you're still new to webpack, please read through the core concepts and this comparison to learn why you might use it over the other tools that are out in the community. Once installed, you can interface with webpack either from its CLI or API. Webpack is used to compile JavaScript modules.
