webpack-cli init is used to initialize webpack projects quickly by scaffolding configuration and installing modules required for the project as per user preferences.
A. Local setup
Follow given steps to locally setup webpack-cli init by installing dependencies:
-
Create
package.jsonthrough npm$ npm init
-
Install
webpackandwebpack-clias devDependencies$ npm install --save-dev webpack webpack-cli
-
Install
@webpack-cli/initpackage to add init scaffold$ npm install --save-dev @webpack-cli/init
B. Global Setup
Follow following steps to setup webpack-cli init globally:
-
Install
webpackandwebpack-cliglobally$ npm install -g webpack webpack-cli
-
Install
@webpack-cli/initpackage to add init scaffold$ npm install -g @webpack-cli/init
A. For local setup:
$ npx webpack-cli initB. For global setup
$ webpack-cli initWill your application have multiple bundles? (Y/n)
Property/key to resolve: entry
What we are meaning here, is if you want to provide your bundle a single or multiple entry points. If you have more than one entry point to your app, answer yes. If you only have one, answer no.
Which folder will your generated bundles be in? [default: dist]
Property/key to resolve: output.path
This answers to the output directory of your application. The output directory is where servers or your index.html will read the generated bundle from.
Will you be using ES2015? (Y/n)
Property/key to resolve: module.rules (for .js files)
If you answer Yes to this question, we will add ES2015 to your webpack configuration, which will allow you to use modern JavaScript in your project.
Will you use one of the below CSS solutions?
Property/key to resolve: module.rules (for .scss,.less,.css,.postCSS files)
If you use any sort of style in your project, such as .less, .scss, .css or postCSS you will need to declare this here. If you don't use CSS, answer no.
If you want to bundle your CSS files, what will you name the bundle? (press enter to skip)
If you indicate based on previous questions that you are using production, this will be enabled. The default value for your generated CSS file is style.[contentHash].css, which will collect all your .less, .scss or .css into one file. This will make your build faster in production.