gpt4 book ai didi

javascript - 从 webpack 输出到更多文件

转载 作者:行者123 更新时间:2023-11-30 14:36:58 25 4
gpt4 key购买 nike

是否有一些选项可以分别捆绑 React Core 和我的脚本?例如两个文件:

  1. bundle-ract.js(包括 react、react-dom、redux、immutable)
  2. bundle.js(我的应用程序和脚本)

最佳答案

当然有这种方法。您必须在 webpack 配置中定义多个条目。与此类似:

const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
entry: {
'SubItems': './src/modules/sub-items/sub.items.module.js',
'UniversalDiscovery': './src/modules/universal-discovery/universal.discovery.module.js',
'MultiFileUpload': './src/modules/multi-file-upload/multi.file.upload.module.js',
},
output: {
filename: '[name].module.js',
path: path.resolve(__dirname, 'Resources/public/js'),
library: ['eZ', 'modules', '[name]'],
libraryTarget: 'umd',
libraryExport: 'default',
},
devtool: 'source-map',
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
externals: {
'react': {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react'
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom'
}
},
plugins: [
new CleanWebpackPlugin(['Resources']),
new UglifyJSPlugin({
sourceMap: true,
uglifyOptions: {
ecma: 6
}
})
]
};

关于javascript - 从 webpack 输出到更多文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50286071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com