【问题标题】:How to specifig the webpack configuration file name using webpack-cli init?如何使用 webpack-cli init 指定 webpack 配置文件名?
【发布时间】:2019-04-06 23:33:20
【问题描述】:

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

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

【问题讨论】:

    标签: webpack webpack-cli


    【解决方案1】:

    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

    如您所见,影响名称的方式有很多;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-24
      • 2017-06-06
      • 2018-05-14
      • 2019-01-03
      • 2018-09-10
      • 2018-08-12
      • 1970-01-01
      • 2020-08-11
      相关资源
      最近更新 更多