-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwebpack.config.js
126 lines (111 loc) · 4.09 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
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry:{
main: ['./src/main.js'],
// vendor: ['vue','vue-router','vue-resource']
},
output: {
publicPath: process.env.NODE_ENV === 'production' ? "http://imjeen.github.io/i/release/" : "/build/",
path: __dirname + (process.env.NODE_ENV === 'production' ? "/release/" : "/build/"),
filename: "[name].js",
chunkFilename: "[chunkhash].js"
},
module: {
loaders: [
/* #image */
{
test: /\.png$/,
loaders: [
'file?hash=sha512&digest=hex&name=images/[name].[ext]?[hash]',
'image-webpack?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}}'
]
},
{
test: /\.svg$/,
loader: 'svg-sprite?' + JSON.stringify({
name: '[name]_[hash]',
prefixize: true,
// spriteModule: './static/images/'
})
},
/* #font */
// { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },
// { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" },
/* #vue */
{ test: /\.vue$/, loader: "vue-loader" },
/* #js */
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
cacheDirectory: true,
plugins: ['transform-runtime'],
presets: ['es2015']
}
},
]
},
plugins: [
new ExtractTextPlugin("[name].css",{ allChunks: true }),
new webpack.optimize.CommonsChunkPlugin('common.js'),
],
resolve: {
extensions: ['', '.js'],
alias:{
'vue': __dirname + "/bower_components/vue/dist/vue.js",
'vue-router': __dirname + "/bower_components/vue-router/dist/vue-router.js",
'vue-resource': __dirname + "/bower_components/vue-resource/dist/vue-resource.js",
}
}
};
if(process.env.NODE_ENV === 'production'){
module.exports.plugins
&& module.exports.plugins.push(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.OccurenceOrderPlugin(),
new HtmlWebpackPlugin({
filename: '../index.html',
template: './src/index.template.html',
inject: false,
minify: {
removeComments: true,
collapseWhitespace: true,
minifyJS: true,
minifyCSS: true,
},
})
);
// for style
module.exports.module.loaders
&& module.exports.module.loaders.push(
{ test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader","css-loader") },
{ test: /\.scss$/, loader: ExtractTextPlugin.extract("style-loader","css-loader!sass-loader") }
);
}else{
module.exports.devtool = 'source-map';
module.exports.plugins
&& module.exports.plugins.push(
new HtmlWebpackPlugin({
filename: '../index.html',
template: './src/index.template.html',
inject: false
})
);
module.exports.module.loaders
&& module.exports.module.loaders.push(
{ test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader","css-loader?sourceMap") },
{ test: /\.scss$/, loader: ExtractTextPlugin.extract("style-loader","css-loader?sourceMap!sass-loader?sourceMap") }
);
}