-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.plugin.js
69 lines (62 loc) · 1.85 KB
/
build.plugin.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
const { join } = require('path');
const fs = require('fs-extra');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const scenarioNames = fs.readdirSync(join('./src/scenarios')).filter(name => !name.startsWith('.'));
const { version } = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
module.exports = ({ onGetWebpackConfig }) => {
onGetWebpackConfig((config) => {
config.resolve.plugin('tsconfigpaths').use(TsconfigPathsPlugin, [
{
configFile: './tsconfig.json',
},
]);
config.merge({
node: {
fs: 'empty',
},
});
scenarioNames.forEach(name => {
const hasTsx = fs.existsSync(join(`./src/scenarios/${name}/index.tsx`));
config.merge({
entry: {
[name]: hasTsx ? require.resolve(`./src/scenarios/${name}/index.tsx`) : require.resolve(`./src/scenarios/${name}/index.ts`),
},
});
config
.plugin(name)
.use(HtmlWebpackPlugin, [
{
inject: false,
minify: false,
templateParameters: {
scenario: name,
version,
},
template: require.resolve('./public/index.ejs'),
filename: `${name}.html`,
},
]);
})
config
.plugin('preview')
.use(HtmlWebpackPlugin, [
{
inject: false,
templateParameters: {
},
template: require.resolve('./public/preview.html'),
filename: 'preview.html',
},
]);
config.plugins.delete('hot');
config.devServer.hot(false);
config.module // fixes https://github.com/graphql/graphql-js/issues/1272
.rule('mjs$')
.test(/\.mjs$/)
.include
.add(/node_modules/)
.end()
.type('javascript/auto');
});
};