-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
47 lines (45 loc) · 1.11 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const hello = 'hello';
const example = process.env.NAME || hello;
const tip = '使用 `NAME=[example-name] npm run example` 指定用例';
/**
* @type {import('webpack/declarations/WebpackOptions').WebpackOptions}
*/
module.exports = {
entry: `./src/examples/${example}/index.ts`,
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
publicPath: '/',
filename: 'bundle.[contenthash].js',
path: path.resolve(__dirname, 'build', example),
},
plugins: [
new HtmlWebpackPlugin(),
{
apply(compiler) {
compiler.hooks.done.tapAsync('MyCustomPlugin', function (_compiler, callback) {
if (!process.env.NAME) setTimeout(() => console.log(`\n${tip}`));
callback();
});
},
},
],
devServer: {
contentBase: path.join('./build', example),
open: true,
historyApiFallback: true,
},
devtool: 'source-map',
};