-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
92 lines (90 loc) · 3.34 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
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var UglifyJSPlugin = require('uglifyjs-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin")
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
module.exports = {
entry: {
app: './app/main.js'
},
output: {
path: path.join(__dirname, 'public'),
publicPath: '',
filename: 'dist/js/[name].[hash].js',
chunkFilename: 'dist/js/[id].chunk.[chunkhash:8].js'
},
module: {
rules: [{
test: /\.js$/,
loaders: 'babel-loader',
include: [path.resolve(__dirname, 'app')]
}, {
test: /\.vue$/,
loader: "vue-loader",
options: {
loaders: {
css: ExtractTextPlugin.extract({
use: 'css-loader'
}),
sass: ExtractTextPlugin.extract({
use: ["css-loader", "sass-loader"]
})
}
}
}, {
test: /\.(css|scss)$/,
use: ExtractTextPlugin.extract({
fallback: 'vue-style-loader',
use: ["css-loader", "postcss-loader", "sass-loader"]
})
}]
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
//new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new CleanWebpackPlugin(['public/dist']),
new ExtractTextPlugin({
filename: 'dist/css/index.[contenthash:8].css'
}),
/*new webpack.optimize.UglifyJsPlugin({
mangle: { // 排除不想要压缩的对象名称
except: ['$', 'exports', 'require', 'module']
},
compress: {
// http://lisperator.net/uglifyjs/compress
warnings: false, // warn about potentially dangerous optimizations/code
conditionals: true, // optimize if-s and conditional expressions
unused: true, // drop unused variables/functions
comparisons: true, // optimize comparisons
sequences: true, // join consecutive statements with the "comma operato"
dead_code: true, // discard unreachable code 丢弃未使用的代码
evaluate: true, // evaluate constant expressions
join_vars: true, // join var declarations
if_return: true // optimize if-s followed by return/continue
},
output: {
// https://github.com/mishoo/UglifyJS2/blob/master/lib/output.js
comments: false
},
sourceMap: false //将错误信息的位置映射到模块。这会减慢编译的速度。仅在开发环境下使用。
}),*/
new HtmlWebpackPlugin({
chunks: ['app'],
filename: 'index.html',
template: './views/index.html'
})
],
resolve: {
extensions: ['.js', '.vue', '.scss', '.css', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': path.resolve('./app')
},
modules: ['node_modules']
}
}