-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
126 lines (122 loc) · 2.77 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
const PACKAGE = require('./package.json')
const path = require('path')
const webpack = require('webpack')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const resolve = dir => path.join(__dirname, dir)
const banner = PACKAGE.name + ' | ' +
'(c) ' + new Date().getFullYear() + ' ' + PACKAGE.author + ' | ' +
PACKAGE.license + ' | ' +
PACKAGE.homepage
const configDevevelopment = {
entry: './demo/src/main.js',
output: {
filename: 'demo.js'
},
resolve: {
extensions: ['.js', '.vue'],
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
},
module: {
rules: [
{
test: /\.(js|vue)$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('demo/src')],
options: {
formatter: require('eslint-friendly-formatter')
}
},
{
test: /\.vue$/,
loader: 'vue-loader',
include: [resolve('demo/src')],
options: {
loaders: {
css: 'vue-style-loader!css-loader'
}
}
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('demo/src')]
}
]
},
devtool: 'cheap-module-eval-source-map',
devServer: {
contentBase: [resolve('demo')],
hot: true,
watchContentBase: true
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new FriendlyErrorsPlugin(),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
template: './demo/index.html'
})
]
}
const configProduction = {
entry: './src/index.js',
output: {
filename: 'vue-gaspard.umd.js',
path: resolve('dist'),
library: {
root: 'VueGaspard',
amd: 'vue-gaspard',
commonjs: 'common-vue-gaspard'
},
libraryTarget: 'umd'
},
externals: {
gaspard: {
root: 'Gaspard',
amd: 'gaspard',
commonjs: 'common-gaspard',
commonjs2: 'common-gaspard'
}
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('src')],
options: {
formatter: require('eslint-friendly-formatter')
}
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src')]
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.BannerPlugin(banner),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: true
}
})
]
}
module.exports = (env) => {
return env && env.production ? configProduction : configDevevelopment
}