简体   繁体   English

无论如何,有没有用webpack减少节点模块的组件并对其做出反应而不捆绑它们?

[英]Is there anyway only minify less and react components for node_modules with webpack without bundling them?

I'm creating a node_modules package with many React components that can be installed into node_modules folder later on, each component has got a few import js and less ... 我正在创建一个具有许多React组件的node_modules包,以后可以将其安装到node_modules文件夹中,每个组件都有一些import js更少 ...

I'd like to minify each component separately, make it es5 module exported to be used in react-app separately, minify them separately (both javascript and less) without bundling imported modules from npm (they stay required)... 我想分别缩小每个组件,使其导出为要在react-app中单独使用的es5模块,分别缩小它们(javascript和更少版本),而不必将导入的模块与npm捆绑在一起(需要保留)...

I tried some ways which kind of working, but any good way to stop webpack bundling? 我尝试了某种方式进行工作,但是有什么好方法可以阻止Webpack捆绑? how the webpack.config.js gonna look like in this case? 在这种情况下, webpack.config.js外观如何?

You could export webpack config as an array of configs for each modules: 您可以将webpack配置导出为每个模块的配置数组:

module.exports = [
  {
    entry: './src/apple',
    mode: 'production',
    output: {
      library: 'apple',
      libraryTarget: 'umd',
      filename: 'apple.min.js',
    },
  },
  {
    entry: './src/orange',
    mode: 'production',
    output: {
      library: 'orange',
      libraryTarget: 'umd',
      filename: 'orange.min.js',
    },
  },
];

Note this is a webpack 4 example, but previous versions also allow an array (they don't have mode though). 请注意,这是一个webpack 4示例,但是以前的版本也允许使用数组(尽管它们没有mode )。 If there is shared config you can of course spread/merge in shared parts for each item. 如果有共享配置,您当然可以为每个项目散布/合并共享部分。

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

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