Webpack只有一个入口点吗?

6

我有两个入口点的webpack.config.js文件,到目前为止,它按照我的期望构建了两个不同的文件。是否有一种方法可以运行webpack命令并仅构建其中一个入口点,而不是构建两个?例如,如果我只更改第二个入口点中的文件,则不希望等待也构建第一个入口点。这是我的webpack.config.js文件:

var webpack = require('webpack');
var CleanPlugin = require('clean-webpack-plugin');

module.exports = {
  entry: {app:'./src/Main.js',theme:'./src/Theme.js'},

  output: {
    filename: '[name].bundle.js',
    chunkFilename: '[id].[hash].bundle.js',
  path: 'build',
    publicPath: '/corp/build/'
  },
  plugins: [
    /*
        // This plugin minifies all the Javascript code of the final bundle
        new webpack.optimize.UglifyJsPlugin({
            mangle:   true,
            compress: {
                warnings: false, // Suppress uglification warnings
            },
        }),
    */
        new webpack.optimize.CommonsChunkPlugin({
            name:      'main', // Move dependencies to our main file
            children:  true, // Look for common dependencies in all children,
            minChunks: 2, // How many times a dependency must come up before being extracted
        })
  ],
  module: {
    loaders: [
      { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?presets[]=es2015&presets[]=react' },
      { test: /\.scss$/, loaders: [ 'style', 'css', 'sass' ]},
      { test: /\.(jpg|gif|png|eot|woff|svg|ttf)(\?.*)?$/, loader: "file-loader" }
    ]
  }
}

我尝试运行 webpack --entry theme,但是我遇到了错误 ERROR in Entry module not found: Error: Cannot resolve module 'theme' in /var/www/html/corp
1个回答

2
你可以创建两个独立的Webpack配置文件,其中:
  1. 第一个配置文件通过使用DLL Plugin来为主题入口点进行构建
  2. 在第二个bundle中,你可以通过使用DLL Reference Plugin来引用预构建的主题
然后运行以下命令: webpack --config _first.config_ && webpack --watch --config _second.config 主代码的任何更改都不会影响预构建的主题bundle。
参考链接:https://robertknight.me.uk/posts/webpack-dll-plugins/https://webpack.js.org/plugins/dll-plugin/

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接