1 | const path = require('path')
|
2 | const { resolveCwd, isPlainObject } = require('./lib/utils')
|
3 |
|
4 | const webpack = require('webpack')
|
5 | const merge = require('webpack-merge')
|
6 | const CopyWebpackPlugin = require('copy-webpack-plugin')
|
7 | const HtmlWebpackPlugin = require('html-webpack-plugin')
|
8 | const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
9 | const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
|
10 |
|
11 | const config = require('./config').build
|
12 | let baseWebpackConfig = require('./webpack.base')(config)
|
13 |
|
14 | function getAssetsPath(_path) {
|
15 | return path.posix.join(config.assetsSubDirectory, _path)
|
16 | }
|
17 |
|
18 | const tofurc = require('../lib/get-config')()
|
19 |
|
20 | let chunks = ['vendor','tofu']
|
21 | if (tofurc && tofurc.webpack && isPlainObject(tofurc.webpack)) {
|
22 | baseWebpackConfig = merge(baseWebpackConfig, tofurc.webpack)
|
23 | }
|
24 |
|
25 | if(tofurc && tofurc.entries){
|
26 | for(let item in tofurc.entries){
|
27 | if(item != 'app'){
|
28 | chunks.push(item);
|
29 | }
|
30 | }
|
31 | }
|
32 |
|
33 | chunks.push('manifest');
|
34 |
|
35 | const 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 | })
|
80 | module.exports = webpackConfig;
|