Repository navigation
Expand file tree
/
Copy pathwebpack.common.mjs
More file actions
149 lines (145 loc) · 3.93 KB
/
Copy pathwebpack.common.mjs
File metadata and controls
149 lines (145 loc) · 3.93 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { createRequire } from "node:module";
import path from "node:path";
import { fileURLToPath } from "node:url";
// eslint-disable-next-line import/no-extraneous-dependencies
import { h as hastscript } from "hastscript";
import autolink from "remark-autolink-headings";
import remarkEmoji from "remark-emoji";
import frontmatter from "remark-frontmatter";
import gfm from "remark-gfm";
import webpack from "webpack";
import cleanup from "./src/remark-plugins/remark-cleanup-readme/index.mjs";
import aside from "./src/remark-plugins/remark-custom-asides/index.mjs";
import refractor from "./src/remark-plugins/remark-refractor/index.mjs";
import remarkRemoveDuplicateH1 from "./src/remark-plugins/remark-remove-duplicate-h1/index.mjs";
import remarkRemoveHeadingId from "./src/remark-plugins/remark-remove-heading-id/index.mjs";
import remarkResponsiveTable from "./src/remark-plugins/remark-responsive-table/remark-responsive-table.mjs";
import slug from "./src/remark-plugins/remark-slug/index.mjs";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const require = createRequire(import.meta.url);
const mdPlugins = [
gfm,
slug,
remarkResponsiveTable,
remarkEmoji,
cleanup,
[
aside,
{
mapping: {
"T>": "tip",
"W>": "warning",
"?>": "todo",
},
},
],
[
autolink,
{
behavior: "append",
content() {
return [hastscript("span.header-link")];
},
},
],
refractor,
remarkRemoveHeadingId,
];
export default ({ ssg = false }) => ({
context: path.resolve(__dirname, "./src"),
performance: false,
cache: {
type: "filesystem",
buildDependencies: {
config: [__filename],
},
cacheDirectory: path.resolve(__dirname, "node_modules/.cache/webpack"),
},
resolve: {
extensions: [".js", ".jsx"],
fallback: {
path: require.resolve("path-browserify"),
},
},
module: {
rules: [
{
test: /\.mdx$/,
use: [
"babel-loader",
{
loader: "@mdx-js/loader",
/** @type {import('@mdx-js/loader').Options} */
options: {
remarkPlugins: [
...mdPlugins,
[frontmatter],
remarkRemoveDuplicateH1,
],
providerImportSource: path.resolve("./src/mdx-components.mjs"),
},
},
],
},
{
test: [/\.(m|c)?jsx?$/],
exclude: /node_modules/,
use: ["babel-loader"],
},
{
test: /\.css$/,
use: ["postcss-loader"],
type: "css/auto",
},
{
test: /\.woff2?$/,
type: "asset/resource",
generator: {
filename: "font/[name].[hash][ext][query]",
emit: ssg !== true,
},
},
{
test: /\.(jpg|jpeg|png|ico)$/i,
type: "asset/resource",
generator: {
filename: "[name].[hash][ext][query]",
emit: ssg !== true,
},
},
{
test: /\.svg$/i,
type: "asset/resource",
exclude: [path.resolve(__dirname, "src/styles/icons")],
generator: {
filename: "[name].[hash][ext][query]",
emit: ssg !== true,
},
},
{
test: /\.svg$/i,
use: ["@svgr/webpack"],
include: [path.resolve(__dirname, "src/styles/icons")],
},
],
},
plugins: [
new webpack.DefinePlugin({
// https://github.com/algolia/algoliasearch-client-javascript/issues/764
"process.env.RESET_APP_DATA_TIMER": JSON.stringify(""), // fix for algoliasearch
"process.env.PHASE": JSON.stringify(process.env.PHASE),
}),
],
experiments: {
css: true,
},
output: {
path: path.resolve(__dirname, "./dist"),
publicPath: "/",
filename: "[name].bundle.js",
cssFilename: "[name].[contenthash].css",
cssChunkFilename: "[name].[contenthash].css",
hashFunction: "xxhash64",
},
});