-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack-prod-config.js
113 lines (107 loc) · 2.97 KB
/
webpack-prod-config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const find = require('find');
const path = require('path');
const files = find.fileSync('./src/js/');
const entrys = {};
const entrysArr = [];
const re = /[\w\W]*src\/([\w\W]+)\.js$/;
for (let i = 0; i < files.length; i++) {
if (/\.entry\.js$/.test(files[i])) {
const filei = files[i].replace(re, '$1');
entrys[filei] = `./${files[i]}`;
entrysArr.push(filei);
}
}
const config = {
entry: entrys,
output: {
path: path.join(__dirname, 'dist'),
publicPath: '//www.wuliangren.com/dist/',
filename: '[name].js',
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false,
},
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__DEV__: false,
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
filename: 'js/common/common.js',
chunks: entrysArr,
minChunks: Math.ceil(entrysArr.length * 2 / 3),
}),
new ExtractTextPlugin('[name].css')
// new ExtractTextPlugin({
// filename: (getPath) => {
// console.log(getPath('[name].css'));
// return getPath('[name].css').replace('js','css');
// }
// })
],
resolve: {
modulesDirectories: ['node_modules', path.join(__dirname, '../node_modules')],
extensions: ['', '.web.js', '.js', '.json', '.jsx', '.less'],
alias: {
app: path.resolve(__dirname, 'src/js'),
style: path.resolve(__dirname, 'src/styles'),
},
},
module: {
loaders: [
{
test: /\.jsx?$/,
loaders: ['babel'],
exclude: /node_modules/,
},
{
test: /\.(less|css)$/,
exclude: /\.mod\.(less|css)/,
loader: ExtractTextPlugin.extract('style', 'css!postcss?parser=postcss-less')
},
{
test: /\.mod\.(less|css)$/,
loader: ExtractTextPlugin.extract('style','css?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss?parser=postcss-less')
},
{
test: /\.(otf|eot|svg|ttf|woff|woff2).*$/,
loader: 'url?limit=10000',
},
{
test: /\.(gif|jpe?g|png|ico)$/,
loader: 'url?limit=10000',
},
],
},
postcss() {
return [
require('precss'),
require('autoprefixer'),
];
},
};
for (let j = 0; j < entrysArr.length; j++) {
const pathname = path.basename(entrysArr[j]).split('.')[0];
const conf = {
filename: `${pathname}.html`,
template: './src/template.html',
inject: 'body',
favicon: './favicon.ico',
title: '仁者无敌__吴亮仁',
hash: false,
minify: {
removeComments: true,
collapseWhitespace: false,
},
chunks: ['common', entrysArr[j]],
};
config.plugins.push(new HtmlWebpackPlugin(conf));
}
module.exports = config;