【问题标题】:Is it possible in Webpack to have multiple subdirectory entry points with multiple relative outputs在 Webpack 中是否可以有多个具有多个相对输出的子目录入口点
【发布时间】:2019-10-10 13:28:54
【问题描述】:

是否可以为每个子目录设置一个入口点,然后输出到一个相对的构建文件夹。结果将是这样的结构:

 blockholder
│
│
├── package.json
├── webpack.config.js
│
│
├── block1
│   ├── index.js
│   └── build
│           └── index.build.js
│
└── block2
    ├── index.js
    └── build
            └── index.build.js

多个文件夹,每个文件夹都有自己的条目和构建。

【问题讨论】:

    标签: webpack entry-point multiple-entries


    【解决方案1】:

    是的。可以在一个 webpack 配置文件中设置多个配置。

    如果您在配置文件中使用数组,则该配置中的所有配置都将被构建。

    小例子:

    module.exports = [
    {
      entry: {
        block1: "./block1/index.js"
      },
      output: {
        filename: "[name].build.js",
        path: path.resolve(__dirname, "block1/build")
      }
    }, 
    {
      entry: {
        block2: "./block2/index.js"
      },
      output: {
        filename: "[name].build.js",
        path: path.resolve(__dirname, "block2/build")
      }
    }]
    

    如果您的配置对于每个捆绑包都相同,我认为您也可以使用单个配置,如下所示:

    module.exports =
    {
      entry: {
        block1: "./block1/index.js"
        block2: "./block2/index.js"
      },
      output: {
        filename: "./[name]/build/[name].build.js"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-08-31
      • 1970-01-01
      • 1970-01-01
      • 2016-01-07
      • 2018-05-21
      • 2020-12-26
      • 2018-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多