如何使用webpack-cli init指定webpack配置文件名?

问题描述 投票:0回答:1

当我使用webpack-cli init创建一个新的webpack配置时,它会生成文件webpack.prod.jswebpack.dev.js,具体取决于我是否回答问题哪个模块将是第一个进入应用程序的模块? [默认:./ src / index]

如何自定义生成的配置文件的文件名?例如webpack.config.dev.js

webpack webpack-cli
1个回答
0
投票

webpack.config.js的默认名称是webpack.config.js,但您也可以在此对象中设置它,它们将被命名为。

Webpack Scaffold Part 1

您还可以使用查询创建3个配置,最后由您决定。默认入口点是index.js,但您也可以在提示中影响它们。

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

您也可以在webpackOptions中更改webpack.config.js名称,因为您还没有发布任何代码我假设您已经使用yeoman生成器扩展了目前为止的类。

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

Name your webpack config something special

如您所见,有很多方法可以影响名称;)

© www.soinside.com 2019 - 2024. All rights reserved.