CodeCoupler Webpack Configuration Factory Commands
You do not need to install any dependencies for any of the following commands. They are already installed, and the generated Webpack configuration is ready to use these features.
You can use the script shortcuts defined in the package.json file to run commands for compiling,
testing, linting, etc. The recommended configuration for the scripts section of the package.json
file is as follows:
Otherwise, you can use the Webpack CLI as normal. Below, all the scripts from the above
package.json are listed alongside the corresponding Webpack CLI commands.
One short note to the option --mode: If not set, the default value is development and not
production like in Webpack.
Override CodeCoupler Webpack Configuration from CLI
Your webpack.config.js file will normally call the CodeCoupler Webpack Configuration Factory
function as follows:
const ccWebpack = require("@codecoupler/cc-webpack");
module.exports = (env) => ccWebpack({}, env, {});
The first argument specifies the CodeCoupler Webpack configuration to be used. The second argument
is another configuration that can be used to override the Webpack CLI argument --env.
For example, to run a build, you would use the following command:
You can override the following CodeCoupler Webpack Configuration Factory configuration settings:
By doing the following:
Values assigned with "false" or "true" will be converted to Boolean values. Values consisting of
digits only will be converted to integer values. All other values are strings (or the boolean value
"true" if omitted). Read more about the --env argument.
Scripts Overview
Development Builds:
npm startnpx webpack serve --mode development-
This will build the library, start the webpack development server and the browser pointing to the server. Everytime you modify your code the page will be automatically reloaded.
npm run watchnpx webpack watch --mode development-
This will build the library and save the results in the
distfolder. Everytime you modify your code the compilation will start automatically again.You can use this environment if you have to use another server then the webpack development server.
npm run build:devnpx webpack --mode development-
This will build the library and save the results in the
distfolder. Nothing more.
Analyze Builds:
npm run analyzenpx webpack --analyze --mode development-
Analyze your output bundles emitted by webpack 1.
Production Builds:
npm run buildnpx webpack --mode production-
Start the production build.
npm run build:watchnpx webpack watch --mode production-
This command will stay after the production build in the watch mode and will recompile whenever a source file is changed.
CDN Builds:
You can build your code to include CDN links to your external modules instead of copying to the
dist folder with these commands:
npm run start:cdnnpx webpack serve --env cdn.enabled --mode development-
Development Server running with CDN build.
npm run watch:cdnnpx webpack watch --env cdn.enabled --mode development-
Watching mode with CDN build.
npm run build:dev:cdnnpx webpack --env cdn.enabled --mode development-
Just build a CDN version in development mode.
npm run build:cdnnpx webpack --env cdn.enabled --mode production-
Final production CDN build.
npm run build:watch:cdnnpx webpack watch --env cdn.enabled --mode production-
Watching mode with final production CDN build.
Format & Linting Tools:
To use the format & linting features you have to create the following configuration files:
eslint.config.js.prettierrc.stylelintrc.markdownlint.json
npm run lint-
This command will format and lint all script-, stylesheet- and markdown files in the
srcfolder. Any errors will be printed out in the command line. npm run lint:fix-
This command is equivalent to
npm run lint. Any errors that can be fixed automatically will be fixed by this command; any other errors will be printed out in the command line. npm run format-
This command will only format all script, stylesheet and markdown files in the
srcfolder. Any errors will be printed out in the command line. npm run format:fix-
This command is equivalent to
npm run format. Any errors that can be fixed automatically will be fixed by this command; any other errors will be printed out in the command line. npm run lint:eslint-
This command will lint all script files in the
srcfolder. Any errors will be printed out in the command line. npm run lint:eslint:fix-
This command is equivalent to
npm run eslint. Any errors that can be fixed automatically will be fixed by this command; any other errors will be printed out in the command line. npm run lint:stylelint-
This command will lint all stylesheet files in the
srcfolder. Any errors will be printed out in the command line. npm run lint:stylelint:fix-
This command is equivalent to
npm run stylelint. Any errors that can be fixed automatically will be fixed by this command; any other errors will be printed out in the command line. npm run lint:markdownlint-
This command will lint all markdown files in the
srcfolder. Any errors will be printed out in the command line. npm run lint:markdownlint:fix-
This command is equivalent to
npm run markdownlint. Any errors that can be fixed automatically will be fixed by this command; any other errors will be printed out in the command line.
Debuging:
npm run test:cc-webpacknpm run test:cc-webpack:devnpx webpack --env test[=raw] --env plugins.WebpackBar=false --mode [production|development]-
This will print the Webpack configuration generated by
cc-webpackand some other details.If you specify the keyword
rawno ANSI escape codes for colorizing will be used in the output.
-
Script available from version 4. ↩