-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.ts
47 lines (41 loc) · 1.22 KB
/
webpack.config.ts
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
import { readdirSync, unlinkSync, writeFileSync } from 'fs';
import { join } from 'path';
const cwd = process.cwd();
const docs = join(cwd, 'docs');
class NgAppDocsPlugin {
constructor(private isDev: boolean) { }
public apply(compiler: import('webpack').Compiler) {
if (this.isDev === false) {
compiler.hooks.emit.tap(this.constructor.name, () => {
const files = readdirSync(docs, { withFileTypes: true }).filter(x => x.isFile());
files.forEach(x => unlinkSync(join(docs, x.name)));
});
}
compiler.hooks.afterEmit.tap(this.constructor.name, () => {
writeFileSync(join(docs, 'CNAME'), 'ng-app.js.org');
});
}
}
export default (env: { staging?: boolean; production?: boolean; WEBPACK_SERVE?: boolean; }) => {
const config = require('@ledge/configs/webpack.merge')(env, {
context: docs,
output: {
globalObject: 'window',
path: docs,
},
plugins: [
new NgAppDocsPlugin(env.WEBPACK_SERVE ?? false),
],
});
if (env.staging || env.production) {
config.resolve = { alias: { index: join(cwd, 'build', 'ng-app.mjs') } };
config.module.rules.push({
test: /[.]m?js$/,
exclude: /node_modules(?![/]@ledge[/]jsx)/,
use: {
loader: '../webpack.plugin.ts',
},
});
}
return config;
};