forked from wechatsync/Wechatsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
146 lines (136 loc) · 3.38 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const path = require('path')
const webpack = require('webpack')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const IgnoreEmitPlugin = require('ignore-emit-webpack-plugin')
const ZipPlugin = require('zip-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const nodeExternals = require('webpack-node-externals')
const Dotenv = require('dotenv-webpack')
const production = process.env.WECHAT_ENV == 'production'
console.log('production', production)
// if (!process.env.WECHAT_ENV) production = true
const vueAlias = `vue/dist/vue${production ? '.min' : ''}.js`
const devPlugins = [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"development"',
},
}),
]
const prodPlugins = devPlugins.concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
}),
new ZipPlugin({
path: '../',
filename: 'WechatSync.zip',
}),
new UglifyJsPlugin(),
])
const productionPlugins = !production ? devPlugins : prodPlugins
const runningTests = process.env.WECHAT_ENV === 'testing'
const externals = runningTests ? [nodeExternals()] : []
function replaceSuffixes(file) {
return file.replace('scss', 'css')
}
console.log(production, productionPlugins)
const filesToPack = [
'background.js',
'popup.js',
'content.js',
'segmenftfault.js',
'editor.js',
'inject.js',
'styles.scss',
'page.js',
'api.js',
'viewer.js',
'autoformat.js',
'template.js',
]
const entry = filesToPack.reduce(
(o, file) =>
Object.assign(o, {
[replaceSuffixes(file)]: `./src/${file}`,
}),
{}
)
var devTools = {
devtool: 'source-map', //inline-
}
if (production) {
delete devTools.devtool
}
module.exports = {
entry,
output: {
path: path.resolve(__dirname, './build'),
filename: '[name]',
},
resolve: {
alias: {
vue: vueAlias,
'extension-streams': 'extension-streams/dist/index.js',
'aes-oop': 'aes-oop/dist/AES.js',
},
modules: [path.join(__dirname, 'node_modules')],
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'stage-3'],
},
exclude: /node_modules/,
},
],
rules: [
// { test: /(\.css$)/, loaders: ExtractTextPlugin.extract(['css-loader']) },
// { test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' },
{
test: /\.(sass|scss|css)$/,
loader: ExtractTextPlugin.extract(['css-loader', 'sass-loader']),
},
{
test: /\.(html|png|woff|woff2|eot|ttf|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
js: 'babel-loader',
scss: 'vue-style-loader!css-loader!sass-loader',
css: 'vue-style-loader!css-loader',
},
},
},
],
},
plugins: [
new ExtractTextPlugin({
filename: '[name].css',
allChunks: true,
}),
new IgnoreEmitPlugin(/\.omit$/),
new CopyWebpackPlugin([`./src/copied`]),
new Dotenv({
path: !production ? './.env.development' : './.env.production',
safe: true,
}),
].concat(productionPlugins),
stats: {
colors: true,
},
externals,
...devTools,
}