-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
54 lines (46 loc) · 1.18 KB
/
index.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
48
49
50
51
52
53
54
import Config from 'webpack-chain';
interface Options {
pug?: Record<string, any>;
pugLoader?: Record<string, any>;
}
/**
* Infuse Pug loaders into `webpack-chain` instance.
*
* @param {Config} config `webpack-chain` instance
* @param {Record<string, any>} pugOptions Options for `pug-plain-loader`
* @param {Record<string, any>} pugLoaderOptions Options for `pug-loader`
*/
function infusePug(
config: Config,
pugOptions: Record<string, any>,
pugLoaderOptions: Record<string, any>
) {
const pugRule = config.module.rule('pug').test(/\.pug$/);
pugRule.oneOf('pug-vue').resourceQuery(/^\?vue/)
.use('pug-vue')
.loader('pug-plain-loader')
.options(pugOptions);
pugRule.oneOf('pug')
.use('pug')
.loader('pug-loader')
.options(pugLoaderOptions);
}
/**
* Pug plugin for Gridsome.
*
* @exports
* @param {any} api Gridsome API
* @param {Options} options Plugin options
*/
function PugPlugin(api: any, options: Options) {
const { pug, pugLoader } = options;
api.chainWebpack((config: Config) => infusePug(config, pug, pugLoader));
}
/**
* Default options
*/
PugPlugin.defaultOptions = (): Options => ({
pug: undefined,
pugLoader: undefined
});
export = PugPlugin;