forked from shinygang/Vue-cnodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
100 lines (98 loc) · 2.87 KB
/
webpack.config.js
File metadata and controls
100 lines (98 loc) · 2.87 KB
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
'use strict'
var path = require('path')
var webpack = require('webpack')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var isProduction = () => {
return process.env.NODE_ENV === 'production'
}
var projectRoot = path.resolve(__dirname, './src')
// 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'
})
]
let entry = ['./src/main']
let cdnPrefix = ''
let buildPath = '/dist/'
let 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: {
preLoaders: [{
test: /\.vue$/,
loader: 'eslint',
include: projectRoot,
exclude: /node_modules/
}, {
test: /\.js$/,
loader: 'eslint',
include: projectRoot,
exclude: /node_modules/
}],
loaders: [{
test: /\.vue$/,
loader: 'vue-loader'
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract(
'style-loader', 'css-loader?sourceMap!sass-loader!autoprefixer?{browsers:["last 2 version", "> 1%"]}')
}, {
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'
}]
},
resolve: {
// require时省略的扩展名,如:require('module') 不需要module.js
extension: ['', '.js'],
// 别名
alias: {
filter: path.join(__dirname, 'src/filters'),
vue: 'vue/dist/vue.js'
}
},
plugins: plugins,
devtool: '#source-map'
}