-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prd.config.js
145 lines (129 loc) · 3.85 KB
/
webpack.prd.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
var webpack = require('webpack');
var path = require('path');
var glob = require('glob');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
var fs = require('fs-extra');
var productionConfig = {
entry: getEntry(),
output: {
path : path.resolve('./dist'),
publicPath : '/',
filename : './[name]/bundle.js',
library : 'EntryPoint'
},
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css')
},
//{
//test: /\.(png|jpg)$/,
//loader: 'url?limit=8192&context=client&name=[path][name].[ext]'
//},
{
test: /\.html$/,
loader: "html?-minimize"
},
{
//test: /\.(woff|woff2|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
//loader: 'file-loader?name=fonts/[name].[ext]'
test : /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
//loader : 'file-loader'
loader: 'file-loader?name=fonts/[name].[ext]'
},
{
test: /\.(png|jpe?g|gif)$/,
//loader: 'url-loader?limit=8192&name=imgs/[name]-[hash].[ext]'
loader: 'url-loader?limit=8192&context=client&name=[path][name].[ext]'
},
{
loader: 'babel-loader',
include: [path.resolve(__dirname, "client")],
test: /\.(js|jsx|es6)$/,
exclude: /(node_modules|bower_components|ueditor)/,
query: {
plugins: [['transform-runtime'], ['import', [{ 'libraryName': 'antd', 'style': 'css' }]]],
presets: ['es2015', 'stage-0', 'react'],
}
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
'jQuery': 'jquery',
'window.jQuery': 'jquery',
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new ExtractTextPlugin("./[name]/bundle.css"),
new UglifyJsPlugin({
compress: {
warnings: false
},
//except: ['$super', '$', 'exports', 'require'],
sourceMap: false,
minimize: true,
}),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
}),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require(path.resolve(__dirname, './client/vendor-manifest.json'))
})
],
resolve: {
root: [
process.cwd() + '/client',
process.cwd() + '/node_modules',
process.cwd() + '/node_modules/bootstrap/dist/css',
process.cwd() + '/node_modules/bootstrap/dist/js',
],
extensions: ['', '.js', '.css', '.scss', '.ejs', '.png', '.jpg'],
alias: {}
}
};
function getFileMap(globPath, pathDir, fileName) {
var result = {};
var entry, dirname, basename, pathname, extname;
var files = glob.sync(globPath);
for (var i = 0; i < files.length; i++) {
entry = files[i];
dirname = path.dirname(entry);
extname = path.extname(entry);
basename = path.basename(entry, extname);
pathname = path.join(dirname, basename);
pathname = pathDir ? pathname.replace(new RegExp('^' + pathDir), '') : pathname;
pathname = fileName ? pathname.replace(new RegExp(fileName + '$'), '') : pathname;
result[pathname] = ['./' + entry];
}
return result;
}
function getEntry() {
copyPlugins();
var pages = Object.keys(getFileMap('views/**/*.html', 'views/'));
var jss = getFileMap('client/js/**/index.js', 'client/js/', '/index');
var result = {};
var entry;
pages.forEach(function(page) {
if (page in jss) {
entry = jss[page];
result[page] = entry;
}
});
return result;
}
function copyPlugins() {
fs.removeSync('dist/');
fs.mkdirsSync('dist/');
fs.copySync('client/assets', 'dist/assets');
fs.copySync('client/vendor-manifest.json', 'dist/vendor-manifest.json');
fs.copySync('client/vendor.dll.js', 'dist/vendor.dll.js');
}
module.exports = productionConfig;