javascript - 从 webpack 输出到更多文件
问题描述
是否有一些选项可以分别捆绑反应核心和我的脚本?例如两个文件:
bundle-ract.js
(包括 react、react-dom、redux、immutable)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
}
})
]
};
推荐阅读
- ruby-on-rails - 如何为 ruby 2.7.1 解决 AWS Elastic Beanstalk 上的 Rail 6 部署错误
- installation - 使用 cargo 安装 deno 时“找不到名为 `map_or` 的方法”
- r - sh 权限在exams2pdf 中被拒绝
- django - Heroku 不断更改我的 heroku-redis 插件的 url
- random-forest - 如何仅获得概率大于 x 的预测
- keras - Keras-tuner Hyperband 仅运行 2 个 epoch
- sql - 性能调优 SparkSQL 查询(带反连接)
- java - JAVA:图形创建
- javac - 为什么我只能在cmd中以管理员身份运行javac?
- json - 如何在 Delphi 中解析这种类型的 JSON 数据?