forked from uxcore/uxcore-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.dev.js
57 lines (52 loc) · 1.56 KB
/
webpack.dev.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
var fs = require('fs');
var webpack = require('webpack');
// 扫描uxcore组件目录下的所有module
function getUxcoreModuleAlias() {
var alias = {};
// 判断是否存在uxcore目录
if (!fs.existsSync('./uxcore')) return alias;
var modules = fs.readdirSync('./uxcore');
modules.forEach(function (name) {
alias[name] = [process.cwd(), 'uxcore', name, 'src'].join('/');
});
return alias;
}
module.exports = {
cache: false,
entry: {
demo: './demo/index'
},
output: {
path: './dist',
filename: "[name].js",
sourceMapFilename: "[name].js.map"
},
devtool: '#source-map', // 这个配置要和output.sourceMapFilename一起使用
module: {
loaders: [
{
test: /\.js(x)*$/,
// uxcore以外的modules都不需要经过babel解析
exclude: function (path) {
var isNpmModule = !!path.match(/node_modules/);
var isUxcore = !!path.match(/node_modules\/uxcore/);
return isNpmModule & !isUxcore;
},
loader: 'babel-loader?stage=1'
}
]
},
resolve: {
alias: getUxcoreModuleAlias()
},
externals: {
react: 'var React' // 相当于把全局的React作为模块的返回 module.exports = React;
},
plugins: [
new webpack.DefinePlugin({
__LOCAL__: true, // 本地环境
__DEV__: true, // 日常环境
__PRO__: false // 生产环境
})
]
};