forked from 2fps/recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
77 lines (70 loc) · 2.07 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const package = require('./package.json');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
let config = {
// 入口
entry: {
Recorder: path.resolve(__dirname, 'src/index.ts'),
},
devtool: 'source-map',
devServer: {
contentBase: './src'
},
output: {
// 输出文件名
//filename: '[name].js',
filename: (chunkData) => {
// 文件名小写
return `${firstLower(chunkData.chunk.name)}.js`;
},
// 输出路径
path: path.resolve(__dirname, 'dist'),
libraryExport: 'default',
library: '[name]',
globalObject: 'this',
libraryTarget: 'umd'
},
module: {
unknownContextCritical : false,
rules:[{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}]
},
resolve: {
extensions: ['.js', '.ts', '.json'],
},
plugins: [
// 文件注释插件
new webpack.BannerPlugin(`
${ package.name } - ${ package.description }
@version v${ package.version }
@homepage ${ package.homepage }
@author ${ package.author } <[email protected]> (https://www.zhuyuntao.cn)
@license ${ package.license }
`),
new CleanWebpackPlugin()
],
};
module.exports = (env, argv) => {
if (argv.mode === 'development') {
// 移动端下增加 vconsole 调试
config.entry.vconsole = path.resolve(__dirname, 'example/vconsole.ts');
// 开发模式下增加 example
config.entry.example = path.resolve(__dirname, 'example/example.ts');
// 开发模式下才要用到html
config.plugins.push(
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'example/example.html'),
filename: 'index.html'
}
));
}
return config;
}
function firstLower(str) {
return str.substring(0, 1).toLowerCase() + str.substring(1)
}