UNPKG

2.36 kBJavaScriptView Raw
1const path = require('path')
2const { resolveCwd, isPlainObject } = require('./lib/utils')
3
4const webpack = require('webpack')
5const merge = require('webpack-merge')
6const CopyWebpackPlugin = require('copy-webpack-plugin')
7const HtmlWebpackPlugin = require('html-webpack-plugin')
8const ExtractTextPlugin = require('extract-text-webpack-plugin')
9const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
10
11const config = require('./config').build
12let baseWebpackConfig = require('./webpack.base')(config)
13
14function getAssetsPath(_path) {
15 return path.posix.join(config.assetsSubDirectory, _path)
16}
17
18const tofurc = require('../lib/get-config')()
19
20let chunks = ['vendor','tofu']
21if (tofurc && tofurc.webpack && isPlainObject(tofurc.webpack)) {
22 baseWebpackConfig = merge(baseWebpackConfig, tofurc.webpack)
23}
24
25if(tofurc && tofurc.entries){
26 for(let item in tofurc.entries){
27 if(item != 'app'){
28 chunks.push(item);
29 }
30 }
31}
32
33chunks.push('manifest');
34
35const webpackConfig = merge(baseWebpackConfig, {
36 devtool: config.productionSourceMap ? '#source-map' : false,
37 output: {
38 path: config.assetsRoot,
39 filename: getAssetsPath('js/[name].[chunkhash].js'),
40 chunkFilename: getAssetsPath('js/[id].[chunkhash].js')
41 },
42 plugins: [
43 new webpack.DefinePlugin({
44 'process.env': config.env
45 }),
46 new webpack.optimize.UglifyJsPlugin({
47 sourceMap: true
48 }),
49 new ExtractTextPlugin({
50 filename: getAssetsPath('css/[name].css')
51 }),
52 new OptimizeCSSPlugin({
53 cssProcessorOptions: {
54 safe: true
55 }
56 }),
57 new HtmlWebpackPlugin({
58 title: require(resolveCwd('config')).title,
59 filename: config.index,
60 template: 'template.html',
61 inject: true,
62 minify: {
63 removeComments: true,
64 removeAttributeQuotes: true
65 },
66 chunksSortMode: 'dependency'
67 }),
68
69 new webpack.optimize.CommonsChunkPlugin({
70 names: chunks,
71 minChunks:2
72 }),
73 new CopyWebpackPlugin([{
74 from: resolveCwd('static'),
75 to: config.assetsSubDirectory,
76 ignore: ['.*']
77 }])
78 ]
79})
80module.exports = webpackConfig;