-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.js
155 lines (137 loc) · 3.92 KB
/
webpack.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
145
/**
* @file webpack.config.js
* @author leeight
*/
const {execSync} = require('child_process');
const path = require('path');
const glob = require('glob');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const kBaseDir = path.resolve(__dirname, '..', '..');
const kGitVersion = execSync('git rev-parse --short HEAD').toString().trim();
function entries() {
const files = glob.sync('./src/x/demos/xui-*.js');
const config = {
app: './src/x/demos/app.js'
};
files.forEach(f => {
const key = path.basename(f, '.js');
config[key] = f;
});
return config;
}
function alias(name) {
return path.dirname(require.resolve(name));
}
module.exports = {
entry: entries(),
output: {
filename: '[name].js',
path: __dirname + '/output',
libraryTarget: 'amd'
},
externals: {
'san': {
amd: 'san'
},
'san-types': {
amd: 'san-types'
},
echarts: {
amd: 'echarts'
}
},
devServer: {
allowedHosts: [
'.efe.tech',
'.baidu.com',
'.baidu-int.com'
],
host: '0.0.0.0'
},
resolve: {
mainFiles: ['index', 'main'],
alias: {
'san-xui': path.join(__dirname, 'src')
}
},
plugins: [
new webpack.DefinePlugin({
GIT_VERSION: JSON.stringify(kGitVersion)
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'commons',
// (the commons chunk name)
filename: 'commons.js',
// (the filename of the commons chunk)
minChunks: 3
// (Modules must be shared between 3 entries)
// chunks: ['pageA', 'pageB'],
// (Only use these entries)
}),
new HtmlWebpackPlugin({
chunks: ['commons', 'app'],
minify: {
minifyJS: true,
minifyCSS: true,
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
},
hash: true,
inject: 'head',
template: './src/x/demos/index.html'
}),
new CopyWebpackPlugin([
{from: './src/x/demos/xui-*.js', to: 'assets/demos/[name].txt'},
{from: './src/x/components/*.js', to: 'assets/components/[name].txt'},
{from: './src/x/forms/*.js', to: 'assets/forms/[name].txt'}
])
],
module: {
rules: [
{
test: /\.(png|gif|jpe?g|svg)$/,
use: [
{
loader: 'file-loader',
options: {
name(file) {
return 'assets/images/[hash].[ext]';
}
}
}
]
},
{
test: /\.less$/,
use: [
{loader: 'style-loader'},
{loader: 'css-loader'},
{
loader: 'less-loader',
options: {
relativeUrls: true,
paths: [
kBaseDir
]
}
}
]
},
{
test: /\.js$/,
exclude: /(node_modules|dist)/,
use: {
loader: 'babel-loader',
options: {
presets: ['env', 'stage-0']
}
}
}
]
}
};