/
create-webpack-config.js
94 lines (92 loc) · 2.45 KB
/
create-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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const path = require(`path`)
const escapeStringRegexp = require(`escape-string-regexp`)
const defaultOptions = require(`../utils/default-options`)
module.exports = (
{ stage, loaders, actions, plugins, cache, ...other },
pluginOptions
) => {
const options = defaultOptions(pluginOptions)
const testPattern = new RegExp(
options.extensions.map(ext => `${escapeStringRegexp(ext)}$`).join(`|`)
)
actions.setWebpackConfig({
module: {
rules: [
{
test: /\.js$/,
include: cache.directory,
use: [loaders.js()],
},
{
test: /\.js$/,
include: path.dirname(require.resolve(`gatsby-plugin-mdx`)),
use: [loaders.js()],
},
{
test: /mdx-components\.js$/,
include: path.dirname(require.resolve(`gatsby-plugin-mdx`)),
use: [
loaders.js(),
{
loader: path.join(
`gatsby-plugin-mdx`,
`loaders`,
`mdx-components`
),
options: {
plugins: options.mdxPlugins,
},
},
],
},
{
test: /mdx-scopes\.js$/,
include: path.dirname(require.resolve(`gatsby-plugin-mdx`)),
use: [
loaders.js(),
{
loader: path.join(`gatsby-plugin-mdx`, `loaders`, `mdx-scopes`),
options: {
cache: cache,
},
},
],
},
{
test: /mdx-wrappers\.js$/,
include: path.dirname(require.resolve(`gatsby-plugin-mdx`)),
use: [
loaders.js(),
{
loader: path.join(`gatsby-plugin-mdx`, `loaders`, `mdx-wrappers`),
options: {
store: other.store,
},
},
],
},
{
test: testPattern,
use: [
loaders.js(),
{
loader: path.join(`gatsby-plugin-mdx`, `loaders`, `mdx-loader`),
options: {
cache: cache,
actions: actions,
isolateMDXComponent: stage === `develop`,
...other,
pluginOptions: options,
},
},
],
},
],
},
plugins: [
plugins.define({
__DEVELOPMENT__: stage === `develop` || stage === `develop-html`,
}),
],
})
}