WebPack仅一个入口点



我有两个针对我的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

您可以制作2个独立的WebPack配置,

  1. 首先使用DLL插件进行主题入口点
  2. 在第二套中您可以通过DLL参考插件引用预先构建的主题

然后您可以运行

webpack --config _first.config_ && webpack --watch --config _second.config

主代码中的任何更改都不会影响预先构建的主题捆绑

https://robertknight.me.uk/posts/webpack-dll-plugins/

https://webpack.js.org/plugins/dll-plugin/

相关内容

最新更新