-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
executable file
·132 lines (122 loc) · 3.66 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
// You can install more packages below to config more as you like:
// eslint
// babel-eslint
// eslint-config-standard
// eslint-loader
// eslint-plugin-html
// eslint-plugin-promise
// eslint-plugin-standard
// postcss-cssnext
var path = require('path')
var webpack = require('webpack')
var fs = require('fs-extra');
function getEntryFileContent (entryPath, vueFilePath) {
let relativePath = path.relative(path.join(entryPath, '../'), vueFilePath);
relativePath=relativePath.replace(/\\/ig,'/')
return 'var App = require(\'' + relativePath + '\')\n'
+ 'App.el = \'#root\'\n'
+ 'new Vue(App)\n'
}
var entry = {
entry: path.resolve('./src/entry.js')
};
function walk(dir) {
dir = dir || '.'
let directory = path.join(__dirname, './src', dir);
let entryDirectory = path.join(__dirname, './src/entry');
fs.readdirSync(directory)
.forEach(function(file) {
var fullpath = path.join(directory, file);
var stat = fs.statSync(fullpath);
var extname = path.extname(fullpath);
if (stat.isFile() && (extname === '.we' || extname === '.vue')) {
let entryFile = path.join(entryDirectory, dir, path.basename(file, extname) + '.js')
fs.outputFileSync(entryFile, getEntryFileContent(entryFile, fullpath))
let name = path.join(dir, path.basename(file, extname))
entry[name] = entryFile + '?entry=true';
} else if (stat.isDirectory() && file !== 'build' && file !== 'include') {
var subdir = path.join(dir, file);
walk(subdir);
}
});
}
walk();
var bannerPlugin = new webpack.BannerPlugin(
'// { "framework": "Vue" }\n',
{ raw: true }
)
function getBaseConfig () {
return {
entry: entry,
output: {
path: 'dist',
},
resolve: {
extensions: ['', '.js', '.vue'],
fallback: [path.join(__dirname, './node_modules')],
alias: {
'api': path.resolve(__dirname, './src/api/'),
'views': path.resolve(__dirname, './src/views/'),
'utils': path.resolve(__dirname, './src/utils/')
}
},
module: {
// // You can use ESLint now!
// // Please:
// // 1. npm install {
// // babel-eslint
// // eslint
// // eslint-config-standard
// // eslint-loader
// // eslint-plugin-html
// // eslint-plugin-promise
// // } --save-dev
// // 2. set .eslintrc
// // take { "extends": "standard" } for example
// // so you need: npm install eslint-plugin-standard --save-dev
// // 3. set the config below
// preLoaders: [
// {
// test: /\.vue$/,
// loader: 'eslint',
// exclude: /node_modules/
// },
// {
// test: /\.js$/,
// loader: 'eslint',
// exclude: /node_modules/
// }
// ],
loaders: [
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
}, {
test: /\.vue(\?[^?]+)?$/,
loaders: []
}
]
},
vue: {
// // You can use PostCSS now!
// // Take cssnext for example:
// // 1. npm install postcss-cssnext --save-dev
// // 2. write `var cssnext = require('postcss-cssnext')` at the top
// // 3. set the config below
// postcss: [cssnext({
// features: {
// autoprefixer: false
// }
// })]
},
plugins: [bannerPlugin]
}
}
var webConfig = getBaseConfig()
webConfig.output.filename = 'web/[name].js'
webConfig.module.loaders[1].loaders.push('vue')
var weexConfig = getBaseConfig()
weexConfig.output.filename = 'weex/[name].js'
weexConfig.module.loaders[1].loaders.push('weex')
module.exports = [webConfig, weexConfig]