-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.umd.config.js
76 lines (68 loc) · 2 KB
/
webpack.umd.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
'use strict';
const path = require('path');
const glob = require('glob'); //自动查找固定目录的js文件
const CleanWebpackPlugin = require('clean-webpack-plugin'); //清理文件夹
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const node_lib = process.env.NODE_LIB === 'production';
const outputPath = 'dist';
const entryPath = 'src';
const clearPaths = ['dist/lib/**.js', 'dist/lib/**.js.map'];
const pathMatch = node_lib ? '**/index.js' : '**/**.js';
//require('babel-polyfill');
let webpackConfig = {
entry: {
//vendor: 'babel-polyfill'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, outputPath),
//library: 'qview',
libraryTarget: 'umd'
},
context: path.resolve(__dirname),
resolve: {
},
devtool: 'source-map',
plugins: [
// new UglifyJsPlugin({
// sourceMap: true
// })
],
module: {
rules: [
{
test: /\.m?js$/,
include: path.join(__dirname, entryPath),
exclude: /(node_modules|dist|docs|examples|tutorials)/,
use: {
loader: 'babel-loader'
}
}
]
},
}
let pathRoot = path.resolve(__dirname, './')
let paths = path.resolve(pathRoot, entryPath);
let options = {
cwd: paths, // 在src目录里找
sync: true, // 这里不能异步,只能同步
};
let entries = new glob.Glob(pathMatch, options).found;
entries.forEach((page) => {
let filename = page.substring(0, page.lastIndexOf('.'));
if (filename.indexOf('index') > -1) {
filename = filename.substring(0, filename.lastIndexOf('/'));
filename = node_lib ? `lib/${filename}` : `${filename}/${filename}`;
}
webpackConfig.entry[filename] = path.resolve(paths, page);
webpackConfig.plugins.push(new CleanWebpackPlugin(
clearPaths,
{
root: __dirname, //根目录
exclude: ['dist/vendor.js', 'dist/vendor.js.map'], //排除
verbose: true, //开启在控制台输出信息
dry: false //启用删除文件
}
));
});
module.exports = webpackConfig;