How to specifig the webpack configuration file name using webpack-cli init?

1k views Asked by At

When I use webpack-cli init to create a new webpack configuration, it generates the file webpack.prod.js or webpack.dev.js depending if I answer the question Which module will be the first to enter the application? [default: ./src/index]

How can I customize the filename of the generated config file ? for example webpack.config.dev.js

1

There are 1 answers

0
prod3v3loper On

Default name for the webpack.config.js is webpack.config.js but you can also set this in this object and they will be named like that.

Webpack Scaffold Part 1

You can also create 3 configurations with the query, that's up to you at the end. The default entry point is index.js, but you can also influence them in the prompts too.

prompting() {

    return this.prompt(
        [
            List( 'confirm', 'Welcome to the tnado Scaffold! Are you ready?', ['Yes', 'No', 'tnado'] ),
            Input( 'entry', 'What is the entry point in your app?' )
        ]
    ).then( answer => {

        // Build a configuration if the user chooses tnado. (custom config)
        if ( answer['confirm'] === 'tnado' ) {

            // Insert in config

            // Common
            this.options.env.configuration.config.webpackOptions = createCommonConfig( answer );
            this.options.env.configuration.config.topScope = [
                'const path = require("path")',
                'const webpack = require("webpack")'
            ];

Check Webpack Scaffolding

You can change the webpack.config.js name in the webpackOptions too, because you have not posted any code I assume that you have already extended so far a class with the yeoman generator.

const Generator = require( 'yeoman-generator' );
module.exports = class WebpackGenerator extends Generator {

Name your webpack config something special

As you can see, there are many ways to influence the name ;)