Open light212 opened 4 years ago
方便贴下你的配置吗?
还是说你的意思是:
module.exports = {
entry:{
app:'./app.js',
other:'./other.js',
}
}
然后期望打包出
// app.icon.js
// other.icon.js
对就是这个意思 var webpack = require('webpack') const path = require('path') const UglifyJSWebpackPlugin = require('uglifyjs-webpack-plugin') const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; const rootPath = process.cwd() module.exports = { mode: process.env.NODE_ENV, entry: { // admin: './admin/src/app.js', travel: './travel/src/app.js', // history: './history/src/app.js', // h5: './h5/src/app.js' //vendors: ['react','jquery'] }, resolve: { extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'], alias: { '@adminUtils': path.join(rootPath, 'admin/src/utils'), '@adminImages': path.join(rootPath, 'admin/images') } }, output: { publicPath: '/conversation/', filename: '[name]/build.js', path: path.resolve(__dirname, './'), chunkFilename: 'travel/antd.icon.js' }, devtool:false, module: { rules: [ { loader: 'webpack-ant-icon-loader', enforce: 'pre', include: [ path.resolve('node_modules/@ant-design/icons/lib/dist'), ] }, { test: /.(ttf|eot|svg|gif|jpg|png|woff|woff2)(\?v=[0-9].[0-9].[0-9])?$/, use:[{ loader:'url-loader', options:{ limit: 819200 } }] }, { test: /(.jsx|.js)$/, exclude: /node_modules|node_modules\/moment/, use:{ loader: 'babel-loader', options: { plugins:[ [ "import", { "libraryName": "antd", "libraryDirectory": "es", "style": true } ], ['transform-runtime'] ], compact: true, cacheDirectory: true, presets: ['env','react', 'stage-0'], babelrc:false } } }, { test: /.css$/i, use: ['style-loader', 'css-loader'], }, { test: /.less$/, use: [ { loader: 'style-loader', }, { loader: 'css-loader', }, { loader: 'less-loader', options: { paths: [path.resolve(__dirname, 'node_modules')], }, }, ], }, { test: /.scss$/, loader: "style!css!sass?sourceMap" }, { test: /.json$/i, type: 'javascript/auto', loader: 'json-loader' }, // { // test: /.(ttf|otf|svg|eot|woff|woff2|png|jpg|gif)$/, // use: { // loader: "file-loader", // options: { // name: "fonts/[name].[ext]", // }, // }, // } ] }, optimization:{ minimizer: [new UglifyJSWebpackPlugin({ cache: true, parallel:true })], }, plugins: [ new webpack.ContextReplacementPlugin(/moment[/\]locale$/, /ja|it/), new BundleAnalyzerPlugin({ analyzerPort: 8989 }), ] }
现在我的做法是,每次打包都得修改配置文件,很麻烦!
有看到吗?
chunkFilename 的名称能不能设置成动态的, 比如说有多个入口 其中的app入口 app.js 这个是入口文件 icon提取出来的名字是 app.icon.js 能这样实现吗?