11

I have Webpack configuration for transpiled app:

entry: {
    'polyfill': './app/polyfill.js',
    'lib': './app/lib.js',
    'main': './app/main.js'
},
output: {
    path: './bundles',
    filename: '[name].js',
    sourceMapFilename: '[name].map'
},
...

I would like to have polyfill and main to be loaded from <script> tag in browser, and lib to be exported as CommonJS library.

lib is used by Node backend but contains some of app modules, so it is built alongside with other entry points). The application is being transpiled, so it is not possible to just require modules from ./app in Node.

What are the options here? Is using separate Webpack configs and separate Webpack runs the only one?

4

1 回答 1

2

我会说最好将与libwebpackapp配置分开。由于lib两个模块(前端和后端)都可以使用它,因此它可以是一个可以在两端使用的库。

要使用 webpack 创建库,您可以使用以下配置,

 entry: { lib: './app/lib' },
 output: {
    path: __dirname + '/lib', // path to output
    filename: outputFile, // library file name
    library: libraryName, // library name
    libraryTarget: 'umd', // the umd format
    umdNamedDefine: true // setting this to true will name the AMD module
  },

这将在此处详细讨论。

于 2017-02-01T07:10:32.290 回答