Next.js: Is there a way to add new entry points in custom webpack config?

Created on 15 Jan 2017  路  4Comments  路  Source: vercel/next.js

So Im using 2.0.0-beta.17 and trying to extend webpack config in next.config.js by adding a new entry point.

// next.config.js

let merge = require('webpack-merge');
module.exports = {
    webpack: (config, {dev}) => {
        return merge(config, {
            entry: { fooEntry: './bar' }
        });
    }
}

It seems like I'm not able to do so since config.entry is an async function. Is there a way for me to extend and add to config.entry?

Most helpful comment

You can just create a new function like:

module.exports = {
  webpack (config) {
    return merge(config, {
      entry () {
        return config.entry().then((entry) => {
          return Object.assign({}, entry, { fooEntry: './bar' })
        })
      }
    }
  }
}

All 4 comments

You can just create a new function like:

module.exports = {
  webpack (config) {
    return merge(config, {
      entry () {
        return config.entry().then((entry) => {
          return Object.assign({}, entry, { fooEntry: './bar' })
        })
      }
    }
  }
}

@nkzawa , I am trying to add an additional entry point as per your suggestion. But the code provided results in a maximum callstack error.

I got it:

module.exports = {
  webpack: function (config) {
    if (ANALYZE) {
      config.plugins.push(new BundleAnalyzerPlugin({
        analyzerMode: 'server',
        analyzerPort: 8888,
        openAnalyzer: true
      }))
    }

    return Object.assign({}, config, { entry: function() {
      return config.entry().then((entry) => {
        return Object.assign({}, entry, { '../static/worker.js': './Worker'})
      })
    }})
  }
}

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kenji4569 picture kenji4569  路  3Comments

knipferrc picture knipferrc  路  3Comments

jesselee34 picture jesselee34  路  3Comments

renatorib picture renatorib  路  3Comments

swrdfish picture swrdfish  路  3Comments