UNPKG

1.76 kBJavaScriptView Raw
1/**
2 * 生产环境webpack配置
3 * Created by liuzhengdong on 2018/4/3.
4 */
5const path = require('path')
6const config = require('./webpack.config.base')('prod')
7const ExtractCssChunks = require("extract-css-chunks-webpack-plugin")
8const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
9const appConfig = require(path.join(process.cwd(), 'app.config'))
10require('./cp-files')(appConfig.enableCordova, 'prod')
11
12config.output.filename = '[name].[chunkhash:8].js'
13config.output.chunkFilename = '[id].[chunkhash:8].js'
14
15config.devtool = false
16config.mode = 'production'
17
18config.module.rules.push(
19 {
20 test: /\.css$/,
21 use: [ExtractCssChunks.loader, 'css-loader', {
22 loader: 'postcss-loader', options: !appConfig.postcssNodeModules ? { exclude: /node_modules/ } : {}
23 }],
24 },
25 {
26 test: /\.less$/,
27 use: [ExtractCssChunks.loader, 'css-loader', 'postcss-loader', 'less-loader'],
28 }
29)
30config.optimization = {
31 runtimeChunk: {
32 name: 'sweet-mobile'
33 },
34 splitChunks: {
35 cacheGroups: {
36 commons: {
37 chunks: 'initial',
38 minChunks: 5,
39 },
40 vendor: {
41 chunks: 'all',
42 name: 'vendor',
43 test: /node_modules/,
44 priority: -10,
45 reuseExistingChunk: false,
46 },
47 },
48 },
49}
50config.plugins = (config.plugins || []).concat([
51 // 分离css文件
52 new ExtractCssChunks({
53 filename: '[name].[chunkhash:8].css',
54 chunkFilename: '[id].[chunkhash:8].css',
55 }),
56 new OptimizeCssAssetsPlugin(
57 {
58 cssProcessorOptions: {
59 safe: true,
60 // postcss那边已经处理过autoprefixer了,这里把它关掉,否则会导致浏览器前缀兼容范围问题
61 autoprefixer: false,
62 },
63 }
64 ),
65])
66
67module.exports = config