-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathwebpack.config.js
97 lines (94 loc) · 2.8 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
'use strict';
var path = require('path');
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var vue = require("vue-loader");
var isProduction = function() {
return process.env.NODE_ENV === 'production';
};
//webpack插件
var plugins = [
//提公用js到common.js文件中
new webpack.optimize.CommonsChunkPlugin('common.js'),
//将样式统一发布到style.css中
new ExtractTextPlugin("style.css", {
allChunks: true,
disable: false
}),
// 使用 ProvidePlugin 加载使用率高的依赖库
new webpack.ProvidePlugin({
$: 'webpack-zepto'
})
];
var entry = ['./src/main'],
cdnPrefix = "",
buildPath = "/dist/",
publishPath = cdnPrefix + buildPath;
//生产环境js压缩和图片cdn
if (isProduction()) {
//plugins.push(new webpack.optimize.UglifyJsPlugin());
cdnPrefix = "";
publishPath = cdnPrefix;
}
//编译输出路径
module.exports = {
debug: true,
entry: entry,
output: {
path: __dirname + buildPath,
filename: 'build.js',
publicPath: publishPath,
chunkFilename:"[id].build.js?[chunkhash]"
},
module: {
loaders: [{
test: /\.vue$/,
loader: 'vue',
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract(
"style-loader", 'css-loader?sourceMap!sass-loader!cssnext-loader')
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract(
"style-loader", "css-loader?sourceMap!cssnext-loader")
}, {
test: /\.js$/,
exclude: /node_modules|vue\/dist/,
loader: 'babel'
},{
test: /\.(jpg|png|gif)$/,
loader: "file-loader?name=images/[hash].[ext]"
}, {
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "url-loader?limit=10000&minetype=application/font-woff"
}, {
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "file-loader"
}, {
test: /\.json$/,
loader: 'json'
}, {
test: /\.(html|tpl)$/,
loader: 'html-loader'
}]
},
vue: {
css: ExtractTextPlugin.extract("css"),
sass: ExtractTextPlugin.extract("css!sass-loader")
},
babel: {
presets: ['es2015', 'stage-0'],
plugins: ['transform-runtime']
},
resolve: {
// require时省略的扩展名,如:require('module') 不需要module.js
extension: ['', '.js'],
//别名
alias: {
filter: path.join(__dirname, 'src/filters')
}
},
plugins: plugins,
devtool: '#source-map'
};