-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwebpack.config.js
171 lines (159 loc) · 4.46 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const path = require('path'); // 导入路径包
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const env = process.env.NODE_ENV;
const isProduction = env === 'production';
const marked = require("marked");
const hljs = require('highlight.js');
const vueCssLoaders = function (options) {
options = options || {}
const cssLoader = {
loader: 'css-loader',
options: {
minimize: isProduction,
sourceMap: options.sourceMap
}
}
// generate loader string to be used with extract text plugin
function generateLoaders(loader, loaderOptions) {
const loaders = [cssLoader]
if (loader) {
loaders.push({
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, {
sourceMap: options.sourceMap
})
})
}
// Extract CSS when that option is specified
// (which is the case during production build)
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
fallback: 'vue-style-loader'
})
} else {
return ['vue-style-loader'].concat(loaders)
}
}
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
return {
css: generateLoaders(),
postcss: generateLoaders(),
less: generateLoaders('less'),
sass: generateLoaders('sass', { indentedSyntax: true }),
scss: generateLoaders('sass'),
stylus: generateLoaders('stylus'),
styl: generateLoaders('stylus')
}
}
let config = {
devtool: isProduction ? 'none' : 'eval',
entry: {
demo: './pages/demo/index',
docs: './pages/docs/index',
home: './pages/home/index',
'home-viser': './pages/home/home-viser',
theme: './pages/theme/index',
demoHome: './pages/demoHome/index',
},
output: {
path: path.resolve(__dirname, 'build'),
filename: "[name].js",
publicPath: "http://localhost:3000/build/",
chunkFilename: '[name].js'
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json", ".scss", "vue"],
alias: {
'vue$': 'vue/dist/vue.esm.js',
},
},
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [isProduction ? 'css-loader?minimize' : 'css-loader']
})
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [isProduction ? 'css-loader?minimize' : 'css-loader', 'sass-loader']
})
},
{ test: /\.tsx?$/, loader: "ts-loader" },
{ test: /\.tpl$/, loader: "handlebars-loader?helperDirs[]=" + __dirname + "/helpers" },
{
test: /\.md$/,
use: [
{
loader: "html-loader"
},
{
loader: "markdown-loader",
options: {
pedantic: true,
highlight: (code, lang) => {
if (lang) {
hljs.highlightAuto(code, [lang]).value;
}
return hljs.highlightAuto(code).value;
}
}
}
]
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: vueCssLoaders({
sourceMap: isProduction,
extract: isProduction,
}),
transformToRequire: {
video: 'src',
source: 'src',
img: 'src',
image: 'xlink:href'
}
}
},
]
},
plugins: isProduction ? [
new webpack.optimize.UglifyJsPlugin({
// 简单避免混淆造成的Angular变量名丢失
mangle: false,
// 最紧凑的输出
beautify: false,
// 删除所有的注释
comments: false,
compress: {
// 在UglifyJs删除没有用到的代码时不输出警告
warnings: false,
// 删除所有的 `console` 语句
// 还可以兼容ie浏览器
drop_console: true,
// 内嵌定义了但是只用到一次的变量
collapse_vars: true,
// 提取出出现多次但是没有定义成变量去引用的静态值
reduce_vars: true,
}
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env),
}),
new ExtractTextPlugin("[name].css"),
] : [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env),
}),
new ExtractTextPlugin("[name].css"),
],
};
module.exports = config;