-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathrslib.config.mjs
More file actions
115 lines (110 loc) · 2.95 KB
/
Copy pathrslib.config.mjs
File metadata and controls
115 lines (110 loc) · 2.95 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
import { promises as fs } from "node:fs"
import { createRequire } from "node:module"
import { join } from "node:path"
import { defineConfig } from "@rslib/core"
const require = createRequire(import.meta.url)
const isProduction = process.env.NODE_ENV === "production"
async function removeRuntimeOnlyFiles(distPath) {
try {
const files = await fs.readdir(distPath, { withFileTypes: true })
for (const file of files) {
if (file.isFile() && file.name.endsWith(".js")) {
const filePath = join(distPath, file.name)
const content = await fs.readFile(filePath, "utf-8")
// Remove files that are empty or only contain the inlined webpack runtime
// (generated as JS stubs for CSS-only entries)
const exports = content.match(/export\{[^}]+\}/g)
const isRuntimeOnly =
content.trim() === "" ||
(exports?.length === 1 &&
/^export\{\w+ as __webpack_require__\}$/.test(exports[0]))
if (isRuntimeOnly) {
await fs.unlink(filePath)
const mapPath = `${filePath}.map`
await fs.unlink(mapPath).catch(() => {})
console.log(`Removed runtime-only file: ${filePath}`)
}
}
}
} catch (error) {
console.error(`Error removing runtime-only files: ${error.message}`)
}
}
const commonConfig = {
bundle: true,
format: "esm",
syntax: "es6",
output: {
autoExternal: false,
distPath: {
root: "django_prose_editor/static/django_prose_editor/",
css: "",
js: "",
font: "",
},
filename: {
js: "[name].js",
css: "[name].css",
},
sourceMap: true,
minify: isProduction,
target: "web",
},
}
export default defineConfig({
lib: [
{
...commonConfig,
source: {
entry: {
editor: "./src/editor.js",
overrides: "./src/overrides.css",
"material-icons": "./src/material-icons.css",
},
},
},
// Editor presets
{
...commonConfig,
source: {
entry: {
default: "./src/default.js",
configurable: "./src/configurable.js",
},
},
output: {
...commonConfig.output,
externals: {
"django-prose-editor/editor": "module django-prose-editor/editor",
},
chunkLoading: "import",
},
},
],
tools: {
postcss: (opts) => {
opts.postcssOptions.plugins = [require("autoprefixer")()]
},
rspack: {
optimization: {
runtimeChunk: false,
},
output: {
devtoolModuleFilenameTemplate: (info) =>
info.resourcePath.replace(`${process.cwd()}/`, ""),
},
plugins: [
{
apply: (compiler) => {
compiler.hooks.afterDone.tap(
"RemoveRuntimeOnlyFilesPlugin",
async () => {
await removeRuntimeOnlyFiles(commonConfig.output.distPath.root)
},
)
},
},
],
},
},
})