UNPKG

2.59 kBJavaScriptView Raw
1'use strict'
2
3const webpack = require('webpack')
4const config = require('../config')
5const { banner, isObject } = require('../libs/utils')
6const webpackBaseConf = require('./webpack.base.conf')()
7const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
8const maraConf = require(config.paths.marauder)
9const { babelLoader } = require('./loaders/babel-loader')
10const isProd = process.env.NODE_ENV === 'production'
11const library = '[name]_lib'
12
13// 支持两种格式配置
14// 数组 vendor: ['react', 'react-dom']
15// 对象 vendor: {libs: ['react', 'react-dom']}
16const vendor = isObject(maraConf.vendor)
17 ? maraConf.vendor.libs
18 : maraConf.vendor
19// 为多页面准备,生成 xxx_vender 文件夹
20const namespace = maraConf.vendor.name ? `${maraConf.vendor.name}_` : ''
21
22module.exports = function() {
23 return {
24 entry: {
25 vendor
26 },
27
28 output: {
29 filename: '[name].dll.js',
30 path: `${config.paths.dist}/${namespace}vendor`,
31 library
32 },
33
34 resolve: webpackBaseConf.resolve,
35
36 module: {
37 rules: [babelLoader(isProd)]
38 },
39
40 plugins: [
41 new webpack.DefinePlugin(config.build.env.stringified),
42 new webpack.DllPlugin({
43 path: `${config.paths.dll}/${namespace}manifest.json`,
44 // This must match the output.library option above
45 name: library
46 }),
47 new UglifyJsPlugin({
48 uglifyOptions: {
49 ecma: 5,
50 compress: {
51 warnings: false,
52 // Disabled because of an issue with Uglify breaking seemingly valid code:
53 // https://github.com/facebook/create-react-app/issues/2376
54 // Pending further investigation:
55 // https://github.com/mishoo/UglifyJS2/issues/2011
56 comparisons: false
57 },
58 mangle: {
59 safari10: true
60 },
61 output: {
62 comments: false,
63 // Turned on because emoji and regex is not minified properly using default
64 // https://github.com/facebook/create-react-app/issues/2488
65 ascii_only: true
66 }
67 },
68 // Use multi-process parallel running to improve the build speed
69 // Default number of concurrent runs: os.cpus().length - 1
70 parallel: true,
71 // Enable file caching
72 cache: true,
73 sourceMap: false
74 }),
75 // 确保在 UglifyJsPlugin 后引入
76 new webpack.BannerPlugin({
77 banner: banner(), // 其值为字符串,将作为注释存在
78 entryOnly: true // 如果值为 true,将只在入口 chunks 文件中添加
79 })
80 ]
81 }
82}