【问题标题】:Webpack only one entry point?Webpack 只有一个入口点?
【发布时间】:2016-11-26 13:47:27
【问题描述】:

我的 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

【问题讨论】:

    标签: webpack


    【解决方案1】:

    您可以制作 2 个单独的 Webpack 配置,

    1. 首先使用 DLL Plugin For Theme 入口点
    2. 在第二个包中,您可以通过 DLL Reference Plugin 引用预构建的主题

    然后你就可以运行了

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

    主代码的任何更改都不会影响预构建的主题包

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-30
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多