简体   繁体   English

CRA webpack - 输出单独的文件

[英]CRA webpack - output separate files

I've got a CRA app that I have built as a Chrome Extension, however I need to implement https://github.com/tshaddix/react-chrome-redux我有一个作为 Chrome 扩展构建的 CRA 应用程序,但是我需要实现https://github.com/tshaddix/react-chrome-redux

To do so, I need to build my background.js as its own file, as well as the main.js为此,我需要将我的 background.js 构建为自己的文件,以及 main.js

I've added my path to config/paths.js我已将我的路径添加到 config/paths.js

  backgroundJs: resolveApp('src/background.js'),

and my config contains:我的配置包含:

entry: [require.resolve('./polyfills'), paths.appIndexJs],
  output: {
    path: paths.appBuild,
    filename: 'static/js/[name].js',
    publicPath: publicPath,

Does anyone know how I can keep my src file built into main.js, but have background.js build to its own file?有谁知道如何将我的 src 文件内置到 main.js 中,但将 background.js 构建到它自己的文件中?

You can pass an object to entry :您可以将对象传递给entry

module.exports = {
   /* ... */
   entry: {
      main: [require.resolve('./polyfills'), paths.appIndexJs],
      background: resolveApp('src/background.js'),
   }
   /* ... */
}

Check the document: https://webpack.js.org/concepts/entry-points/ .检查文档: https : //webpack.js.org/concepts/entry-points/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM