CodeCoupler Webpack Configuration Factory Commands
No dependencies need to be installed for any of the following commands. They are already installed, and the generated Webpack configuration supports 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 usual. Below, all the scripts from the above
package.json are listed alongside their corresponding Webpack CLI commands.
One quick note about the option --mode: If not set, the default value is development and not
production as it is in Webpack.
Override CodeCoupler Webpack Configuration from CLI
Your webpack.config.js file will typically call the CodeCoupler Webpack Configuration Factory
function as follows:
const ccWebpack = require("@codecoupler/cc-webpack");
module.exports = (env) => ccWebpack({}, env, {});
The first argument specifies which CodeCoupler Webpack configuration to use. The second argument is
an additional configuration that can be used to override the Webpack CLI argument --env.
To run a build, for example, you would use the following command:
You can override the following settings in the CodeCoupler Webpack Configuration Factory:
By doing the following:
Values assigned as "true" or "false" 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 open the browser pointing to the server. Each time you modify your code, the page will reloaded automatically.
npm run watchnpx webpack watch --mode development-
This will build the library and save the results in the
distfolder. Each time you modify your code the compilation will start automatically.You can use this environment if you need to use a server other than 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 remain active after the production build in the watch mode and will recompile whenever a source file is modified.
CDN Builds:
Instead of copying to the dist folder,you can build your code to include CDN links to your
external modules 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-
Simply 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 displayed in the console. npm run lint:fix-
This command is equivalent to
npm run lint. It will automatically fix any errors that can be fixed and display any other errors in the console. npm run format-
This command will only format all the script, stylesheet, and Markdown files in the
srcfolder. Any errors will be displayed in the console. npm run format:fix-
This command is equivalent to
npm run format. It will automatically fix any errors that can be fixed and display any other errors in the console. npm run lint:eslint-
This command will lint all the script files in the
srcfolder. Any errors will be displayed in the console. npm run lint:eslint:fix-
This command is equivalent to
npm run eslint. It will automatically fix any errors that can be fixed and display any other errors in the console. npm run lint:stylelint-
This command will lint all the stylesheet files in the
srcfolder. Any errors will be displayed in the console. npm run lint:stylelint:fix-
This command is equivalent to
npm run stylelint. It will automatically fix any errors that can be fixed and display any other errors in the console. npm run lint:markdownlint-
This command will lint all Markdown files in the
srcfolder. Any errors will be displayed in the console. npm run lint:markdownlint:fix-
This command is equivalent to
npm run markdownlint. It will automatically fix any errors that can be fixed and display any other errors in the console.
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.Specifying the keyword "raw" will prevent the use of ANSI escape codes for colorizing in the output.
-
Script available from version 4. ↩