How could I build only one of multiple entries with webpack

I ask this question in webpack/gitter,but nobody answered ,so I come here
with webpack ,we can build multiple entries just like below:

{
       entry:{
         'a':'a.js',
         'b':'b.js'
       },
       ...
       plugins:[
          new webpack.optimize.CommonsChunkPlugin({
            name:'vendor'
            }),

       ]
    }

I just change the a.js,I only want to rebuild a.js,But the vendor.js and b.js should not change,how could I do that?

Author: Fantashit

3 thoughts on “How could I build only one of multiple entries with webpack

  1. The watch mode does only rebuild changed chunks.

    A whole compilation need to build all chunks, because they affect eachother

  2. I have the same issue.
    @sokra I agree that build process need to build all chunks, but assume that we have to build chunks for different purpose(different app), but shares some set of files/compoents. In such case when we are developing one of the apps, we must run webpack in watch mode for all chunks, thus webpack is watching on all files related to all apps. When we working at one of the apps, it is unnecessary to watch changes on those files which are not related.

    Currently I have such case, and by having such feature to run webpack for one of the entries, I think that the development process would be much faster.

  3. You could dynamically filter your entry points in your config based on environment variables.

    // webpack.config.js
    module.exports =  {
      entry: Object.entries({
        a: 'a.js',
        b: 'b.js'
      })
        .filter(/* some function of process.env */)
        .reduce((a, [name, entry]) => Object.assign(a, {[name]: entry}), {}),
      // rest of your config
    }
    

    or with object-rest-spread:

    module.exports = {
      entry: {
        ...(process.env.a && {a: 'a.js'}), 
        ...(process.env.b && {b: 'b.js'})
      }
      // more config
    }
    

Comments are closed.