forked from Hanks10100/weex-vue-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
127 lines (123 loc) · 3.42 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
const path = require('path')
const webpack = require('webpack')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
// const { VueLoaderPlugin } = require('vue-loader')
const weexLoaderOptions = {
loaders: {
scss: ['sass-loader'],
sass: [{
loader: 'sass-loader',
options: { indentedSyntax: true }
}],
less: ['less-loader'],
stylus: ['stylus-loader'],
styl: ['stylus-loader']
}
}
const vueLoaderOptions = {
optimizeSSR: false,
postcss: [
// to convert weex exclusive styles.
require('postcss-plugin-weex')(),
require('autoprefixer')({
browsers: ['> 0.1%', 'ios >= 8', 'not ie < 12']
}),
require('postcss-plugin-px2rem')({
// base on 750px standard.
rootValue: 75,
// to leave 1px alone.
minPixelValue: 1.01
})
],
compilerModules: [
{
postTransformNode: el => {
// to convert vnode for weex components.
require('weex-vue-precompiler')()(el)
}
}
]
}
function createConfig (option = {}) {
const { isWeex, minify } = option
const suffix = `.${isWeex ? 'weex' : 'web'}${minify ? '.min': '' }.js`
const webpackConfig = {
entry: option.entry,
output: {
path: path.resolve(__dirname, option.outputPath || 'dist'),
filename: (option.outputName || 'bundle') + suffix
},
module: {
rules: [{
test: /\.js$/,
use: ['babel-loader'],
exclude: /node_modules/
}, {
test: /\.vue(\?[^?]+)?$/,
use: [{
loader: isWeex ? 'weex-loader' : 'vue-loader',
options: isWeex ? weexLoaderOptions : vueLoaderOptions
}]
}]
},
node: {
// prevent webpack from injecting useless polyfill
__filename: false,
__dirname: false,
child_process: false,
Buffer: false,
global: false,
console: false,
setImmediate: false,
process: false,
timers: false,
dgram: false,
fs: false,
path: false,
net: false,
crypto: false,
http: false,
https: false,
url: false,
dns: false,
tls: false,
vm: false
},
plugins: []
}
if (minify) {
webpackConfig.plugins.push(new UglifyJSPlugin())
}
if (isWeex) {
webpackConfig.plugins.push(new webpack.BannerPlugin({
banner: '// { "framework": "Vue" }\n"use weex:vue";\n',
raw: true
}))
} else {
// webpackConfig.plugins.unshift(new VueLoaderPlugin())
}
return webpackConfig
}
function generateWebpackConfigs (options) {
const buildOptions = []
for (const name in options) {
const option = typeof options[name] === 'string'
? ({ entry: options[name] })
: options[name]
option.outputName = name
buildOptions.push(Object.assign({}, option, { isWeex: true, minify: false }))
buildOptions.push(Object.assign({}, option, { isWeex: false, minify: false }))
buildOptions.push(Object.assign({}, option, { isWeex: true, minify: true }))
buildOptions.push(Object.assign({}, option, { isWeex: false, minify: true }))
}
return buildOptions.map(opt => createConfig(opt))
}
module.exports = generateWebpackConfigs({
landing: path.resolve('src/pages/landing', 'Landing.js'),
about: path.resolve('src/pages/about', 'About.js'),
examples: path.resolve('src/pages/examples', 'Examples.js'),
news: path.resolve('src/pages/news', 'News.js'),
guide: path.resolve('src/pages/guide', 'Guide.js'),
webview: path.resolve('src/pages/webview', 'Webview.js'),
// update: path.resolve('misc', 'update.js')
})