@vuepress/bundler-rspack 0.0.0-stage → 2.0.0-rc.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +11 -2
- package/dist/index.d.ts +109 -0
- package/dist/index.js +827 -0
- package/dist/rolldown-runtime-C6B9acKu.cjs +51 -0
- package/dist/vuepress-markdown-loader.cjs +19 -0
- package/dist/vuepress-ssr-loader.cjs +18 -0
- package/package.json +66 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018-present, VuePress Community
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vuepress/bundler-rspack
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@vuepress/bundler-rspack)
|
|
4
|
+
[](https://github.com/vuepress/core/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
## Documentation
|
|
7
|
+
|
|
8
|
+
https://vuepress.vuejs.org
|
|
9
|
+
|
|
10
|
+
## License
|
|
11
|
+
|
|
12
|
+
[MIT](https://github.com/vuepress/core/blob/main/LICENSE)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { merge } from "rspack-merge";
|
|
2
|
+
import { Configuration as RspackConfiguration, LoaderContext } from "@rspack/core";
|
|
3
|
+
import { RspackChain } from "rspack-chain";
|
|
4
|
+
import { VueLoaderOptions } from "vue-loader";
|
|
5
|
+
import { Configuration, RspackDevServer } from "@rspack/dev-server";
|
|
6
|
+
import { Bundler, BundlerOptions } from "@vuepress/core";
|
|
7
|
+
/**
|
|
8
|
+
* Options for bundler-rspack
|
|
9
|
+
*/
|
|
10
|
+
interface RspackBundlerOptions extends BundlerOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Edit the internal Rspack config.
|
|
13
|
+
*
|
|
14
|
+
* @param config - Rspack config
|
|
15
|
+
* @param isServer - Whether it is server bundle
|
|
16
|
+
* @param isBuild - Whether in build mode
|
|
17
|
+
* @returns if returns a configuration object, it will be used as the new rspack config, otherwise the original config object will be used
|
|
18
|
+
*/
|
|
19
|
+
configureRspack?: (config: RspackConfiguration, isServer: boolean, isBuild: boolean) => RspackConfiguration | void;
|
|
20
|
+
/**
|
|
21
|
+
* use rspack-chain to set rspack config
|
|
22
|
+
*/
|
|
23
|
+
chainRspack?: (config: RspackChain, isServer: boolean, isBuild: boolean) => void;
|
|
24
|
+
/**
|
|
25
|
+
* `setupMiddlewares` config of rspack-dev-server
|
|
26
|
+
*/
|
|
27
|
+
devServerSetupMiddlewares?: Configuration['setupMiddlewares'];
|
|
28
|
+
/**
|
|
29
|
+
* vue-loader options
|
|
30
|
+
*/
|
|
31
|
+
vue?: VueLoaderOptions;
|
|
32
|
+
/**
|
|
33
|
+
* postcss-loader options
|
|
34
|
+
*/
|
|
35
|
+
postcss?: PostcssLoaderOptions;
|
|
36
|
+
/**
|
|
37
|
+
* stylus-loader options
|
|
38
|
+
*/
|
|
39
|
+
stylus?: StylusLoaderOptions;
|
|
40
|
+
/**
|
|
41
|
+
* sass-loader options for scss files
|
|
42
|
+
*/
|
|
43
|
+
scss?: SassLoaderOptions;
|
|
44
|
+
/**
|
|
45
|
+
* sass-loader options for sass files
|
|
46
|
+
*/
|
|
47
|
+
sass?: SassLoaderOptions;
|
|
48
|
+
/**
|
|
49
|
+
* less-loader options
|
|
50
|
+
*/
|
|
51
|
+
less?: LessLoaderOptions;
|
|
52
|
+
/**
|
|
53
|
+
* only target evergreen browsers or not
|
|
54
|
+
*/
|
|
55
|
+
evergreen?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Common options for style preprocessor rspack loaders
|
|
59
|
+
*/
|
|
60
|
+
interface StylePreprocessorLoaderOptions {
|
|
61
|
+
additionalData?: string | ((content: string, loaderContext: LoaderContext<Record<string, unknown>>) => string);
|
|
62
|
+
sourceMap?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Common type for style pre-processor options
|
|
66
|
+
*/
|
|
67
|
+
type StylePreprocessorOptions<T extends Record<string, unknown> = Record<string, unknown>> = T | ((loaderContext: LoaderContext<T>) => TextDecodeOptions);
|
|
68
|
+
/**
|
|
69
|
+
* Options for postcss-loader
|
|
70
|
+
*
|
|
71
|
+
* @see https://github.com/webpack-contrib/postcss-loader#options
|
|
72
|
+
*/
|
|
73
|
+
interface PostcssLoaderOptions extends Pick<StylePreprocessorLoaderOptions, 'sourceMap'> {
|
|
74
|
+
execute?: boolean;
|
|
75
|
+
implementation?: string | ((...args: unknown[]) => unknown);
|
|
76
|
+
postcssOptions?: StylePreprocessorOptions;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Options for stylus-loader
|
|
80
|
+
*
|
|
81
|
+
* @see https://github.com/webpack-contrib/stylus-loader#options
|
|
82
|
+
*/
|
|
83
|
+
interface StylusLoaderOptions extends StylePreprocessorLoaderOptions {
|
|
84
|
+
implementation?: string | ((...args: unknown[]) => unknown);
|
|
85
|
+
stylusOptions?: StylePreprocessorOptions;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Options for sass-loader
|
|
89
|
+
*
|
|
90
|
+
* @see https://github.com/webpack-contrib/sass-loader#options
|
|
91
|
+
*/
|
|
92
|
+
interface SassLoaderOptions extends StylePreprocessorLoaderOptions {
|
|
93
|
+
api?: 'legacy' | 'modern-compiler' | 'modern';
|
|
94
|
+
implementation?: Record<string, unknown> | string;
|
|
95
|
+
sassOptions?: StylePreprocessorOptions;
|
|
96
|
+
warnRuleAsWarning?: boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Options for less-loader
|
|
100
|
+
*
|
|
101
|
+
* @see https://github.com/webpack-contrib/less-loader#options
|
|
102
|
+
*/
|
|
103
|
+
interface LessLoaderOptions extends StylePreprocessorLoaderOptions {
|
|
104
|
+
implementation?: Record<string, unknown> | string;
|
|
105
|
+
lessLogAsWarnOrErr?: boolean;
|
|
106
|
+
lessOptions?: StylePreprocessorOptions;
|
|
107
|
+
}
|
|
108
|
+
export declare const rspackBundler: (options?: RspackBundlerOptions) => Bundler;
|
|
109
|
+
export { type LessLoaderOptions, type PostcssLoaderOptions, type RspackBundlerOptions, type RspackConfiguration, type RspackDevServer, type SassLoaderOptions, type StylePreprocessorLoaderOptions, type StylePreprocessorOptions, type StylusLoaderOptions, type VueLoaderOptions, rspackBundler as default, merge as rspackMergeConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,827 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { merge, merge as merge$1 } from "rspack-merge";
|
|
3
|
+
import { CopyRspackPlugin, CssExtractRspackPlugin, DefinePlugin, HotModuleReplacementPlugin, HtmlRspackPlugin, LightningCssMinimizerRspackPlugin, rspack } from "@rspack/core";
|
|
4
|
+
import { createPageChunkFilesMap, createVueServerApp, getSsrTemplate, renderPageToString, resolveLinkedPageChunkFiles } from "@vuepress/bundlerutils";
|
|
5
|
+
import { colors, debug, fs, logger, ora, path, renderHead, withSpinner } from "@vuepress/utils";
|
|
6
|
+
import { RspackChain } from "rspack-chain";
|
|
7
|
+
import autoprefixer from "autoprefixer";
|
|
8
|
+
import { VueLoaderPlugin } from "vue-loader";
|
|
9
|
+
import { RspackDevServer } from "@rspack/dev-server";
|
|
10
|
+
import { sep } from "node:path";
|
|
11
|
+
// src/resolveRspackConfig.ts
|
|
12
|
+
const resolveRspackConfig = ({ config, options, isServer, isBuild }) => {
|
|
13
|
+
options.chainRspack?.(config, isServer, isBuild);
|
|
14
|
+
let rspackConfig = config.toConfig();
|
|
15
|
+
const configureRspackResult = options.configureRspack?.(rspackConfig, isServer, isBuild);
|
|
16
|
+
if (configureRspackResult) rspackConfig = configureRspackResult;
|
|
17
|
+
return rspackConfig;
|
|
18
|
+
};
|
|
19
|
+
// src/config/handleDevtool.ts
|
|
20
|
+
/**
|
|
21
|
+
* Set rspack devtool
|
|
22
|
+
*/
|
|
23
|
+
const handleDevtool = ({ app, config, isBuild }) => {
|
|
24
|
+
if (app.env.isDebug) config.devtool("source-map");
|
|
25
|
+
else if (!isBuild) config.devtool("eval-cheap-module-source-map");
|
|
26
|
+
};
|
|
27
|
+
// src/config/handleEntry.ts
|
|
28
|
+
/**
|
|
29
|
+
* Set rspack entry
|
|
30
|
+
*/
|
|
31
|
+
const handleEntry = ({ app, config }) => {
|
|
32
|
+
config.entry("app").add(app.dir.client(fs.readJsonSync(app.dir.client("package.json")).exports["./app"]));
|
|
33
|
+
};
|
|
34
|
+
// src/config/handleMode.ts
|
|
35
|
+
/**
|
|
36
|
+
* Set rspack mode
|
|
37
|
+
*/
|
|
38
|
+
const handleMode = ({ app, config, isBuild }) => {
|
|
39
|
+
config.mode(!isBuild || app.env.isDebug ? "development" : "production");
|
|
40
|
+
};
|
|
41
|
+
// src/config/handleModuleAssets.ts
|
|
42
|
+
/**
|
|
43
|
+
* Set rspack config to handle assets files
|
|
44
|
+
*/
|
|
45
|
+
const handleModuleAssets = ({ config }) => {
|
|
46
|
+
config.module.rule("images").test(/\.(png|jpe?g|gif|webp)(\?.*)?$/i).type("asset").generator({ filename: "assets/img/[name].[contenthash:8][ext]" });
|
|
47
|
+
config.module.rule("svg").test(/\.(svg)(\?.*)?$/i).type("asset/resource").generator({ filename: "assets/img/[name].[contenthash:8][ext]" });
|
|
48
|
+
config.module.rule("media").test(/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i).type("asset/resource").generator({ filename: "assets/media/[name].[contenthash:8][ext]" });
|
|
49
|
+
config.module.rule("fonts").test(/\.(woff2?|eot|ttf|otf)(\?.*)?$/i).type("asset/resource").generator({ filename: "assets/fonts/[name].[contenthash:8][ext]" });
|
|
50
|
+
};
|
|
51
|
+
// src/config/resolveSwcLoaderOptions.ts
|
|
52
|
+
const resolveSwcLoaderOptions = ({ env, jsc = {}, ...rest } = {}, isTypescript = false) => {
|
|
53
|
+
const { parser = {}, transform = {}, ...jscRest } = jsc;
|
|
54
|
+
return {
|
|
55
|
+
env: {
|
|
56
|
+
/**
|
|
57
|
+
* keep consistent with vite
|
|
58
|
+
*
|
|
59
|
+
* @see https://vite.dev/config/build-options.html#build-target
|
|
60
|
+
*/
|
|
61
|
+
targets: {
|
|
62
|
+
chrome: "111",
|
|
63
|
+
edge: "111",
|
|
64
|
+
firefox: "114",
|
|
65
|
+
safari: "16.4"
|
|
66
|
+
},
|
|
67
|
+
...env
|
|
68
|
+
},
|
|
69
|
+
jsc: {
|
|
70
|
+
parser: isTypescript ? {
|
|
71
|
+
syntax: "typescript",
|
|
72
|
+
tsx: true,
|
|
73
|
+
...parser
|
|
74
|
+
} : {
|
|
75
|
+
syntax: "ecmascript",
|
|
76
|
+
jsx: true,
|
|
77
|
+
...parser
|
|
78
|
+
},
|
|
79
|
+
transform: {
|
|
80
|
+
...transform,
|
|
81
|
+
react: {
|
|
82
|
+
runtime: "classic",
|
|
83
|
+
pragma: "jsx",
|
|
84
|
+
pragmaFrag: "Fragment",
|
|
85
|
+
development: false,
|
|
86
|
+
...transform.react
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
...jscRest
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* overrides
|
|
93
|
+
*/
|
|
94
|
+
...rest
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
// src/config/handleModuleJs.ts
|
|
98
|
+
/**
|
|
99
|
+
* Set rspack module to handle js files
|
|
100
|
+
*/
|
|
101
|
+
const handleModuleJs = ({ options, config, isBuild, isServer }) => {
|
|
102
|
+
if (options.evergreen !== false || !isBuild || isServer) return;
|
|
103
|
+
config.module.rule("js").test(/\.jsx?$/).exclude.add((filePath) => {
|
|
104
|
+
if (/\.vue\.jsx?$/.test(filePath)) return false;
|
|
105
|
+
if (/(@vuepress[/\\][^/\\]*|vuepress-[^/\\]*)[/\\](?!node_modules).*\.js$/.test(filePath)) return false;
|
|
106
|
+
return filePath.includes("node_modules");
|
|
107
|
+
}).end().use("swc-loader").loader("builtin:swc-loader").options(resolveSwcLoaderOptions()).end();
|
|
108
|
+
};
|
|
109
|
+
// src/config/handleModulePug.ts
|
|
110
|
+
/**
|
|
111
|
+
* Set rspack module to handle pug files
|
|
112
|
+
*/
|
|
113
|
+
const handleModulePug = ({ config }) => {
|
|
114
|
+
config.module.rule("pug").test(/\.pug$/).use("pug-plain-loader").loader("pug-plain-loader");
|
|
115
|
+
};
|
|
116
|
+
// src/config/handleModuleStyles.ts
|
|
117
|
+
const require$2 = createRequire(import.meta.url);
|
|
118
|
+
/**
|
|
119
|
+
* Set rspack module to handle style files
|
|
120
|
+
*/
|
|
121
|
+
const handleModuleStyles = ({ options, config, isBuild, isServer }) => {
|
|
122
|
+
const handleStyle = ({ lang, test, loaderName, loaderOptions }) => {
|
|
123
|
+
const rule = config.module.rule(lang).test(test).type("javascript/auto");
|
|
124
|
+
if (!isServer) {
|
|
125
|
+
if (isBuild) rule.use("css-extract-loader").loader(CssExtractRspackPlugin.loader);
|
|
126
|
+
else rule.use("style-loader").loader(require$2.resolve("style-loader"));
|
|
127
|
+
}
|
|
128
|
+
rule.use("css-loader").loader(require$2.resolve("css-loader")).options({
|
|
129
|
+
modules: {
|
|
130
|
+
auto: true,
|
|
131
|
+
exportLocalsConvention: "as-is",
|
|
132
|
+
exportOnlyLocals: isServer,
|
|
133
|
+
localIdentName: `[local]_[contenthash:base64:8]`,
|
|
134
|
+
namedExport: false
|
|
135
|
+
},
|
|
136
|
+
importLoaders: loaderName ? 2 : 1
|
|
137
|
+
});
|
|
138
|
+
rule.use("postcss-loader").loader(require$2.resolve("postcss-loader")).options({
|
|
139
|
+
postcssOptions: { plugins: [autoprefixer] },
|
|
140
|
+
...options.postcss
|
|
141
|
+
});
|
|
142
|
+
if (loaderName) rule.use(loaderName).loader(loaderName).options(loaderOptions ?? {});
|
|
143
|
+
};
|
|
144
|
+
handleStyle({
|
|
145
|
+
lang: "css",
|
|
146
|
+
test: /\.css$/
|
|
147
|
+
});
|
|
148
|
+
handleStyle({
|
|
149
|
+
lang: "postcss",
|
|
150
|
+
test: /\.p(ost)?css$/
|
|
151
|
+
});
|
|
152
|
+
handleStyle({
|
|
153
|
+
lang: "scss",
|
|
154
|
+
test: /\.scss$/,
|
|
155
|
+
loaderName: "sass-loader",
|
|
156
|
+
loaderOptions: options.scss
|
|
157
|
+
});
|
|
158
|
+
handleStyle({
|
|
159
|
+
lang: "sass",
|
|
160
|
+
test: /\.sass$/,
|
|
161
|
+
loaderName: "sass-loader",
|
|
162
|
+
loaderOptions: options.sass
|
|
163
|
+
});
|
|
164
|
+
handleStyle({
|
|
165
|
+
lang: "less",
|
|
166
|
+
test: /\.less$/,
|
|
167
|
+
loaderName: "less-loader",
|
|
168
|
+
loaderOptions: options.less
|
|
169
|
+
});
|
|
170
|
+
handleStyle({
|
|
171
|
+
lang: "stylus",
|
|
172
|
+
test: /\.styl(us)?$/,
|
|
173
|
+
loaderName: "stylus-loader",
|
|
174
|
+
loaderOptions: {
|
|
175
|
+
stylusOptions: {
|
|
176
|
+
includeCSS: true,
|
|
177
|
+
compress: false
|
|
178
|
+
},
|
|
179
|
+
...options.stylus
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
// src/config/handleModuleTs.ts
|
|
184
|
+
/**
|
|
185
|
+
* Set rspack module to handle ts files
|
|
186
|
+
*/
|
|
187
|
+
const handleModuleTs = ({ config }) => {
|
|
188
|
+
config.module.rule("ts").test(/\.tsx?/).use("swc-loader").loader("builtin:swc-loader").options(resolveSwcLoaderOptions({}, true)).end();
|
|
189
|
+
};
|
|
190
|
+
// src/config/handleModuleVue.ts
|
|
191
|
+
const require$1 = createRequire(import.meta.url);
|
|
192
|
+
/**
|
|
193
|
+
* Set rspack module to handle vue files
|
|
194
|
+
*/
|
|
195
|
+
const handleModuleVue = ({ app, options, config, isBuild, isServer }) => {
|
|
196
|
+
const handleVue = ({ lang, test }) => {
|
|
197
|
+
const rule = config.module.rule(lang).test(test);
|
|
198
|
+
if (isBuild) rule.use("vuepress-ssr-loader").loader(require$1.resolve("#vuepress-ssr-loader")).end();
|
|
199
|
+
rule.use("vue-loader").loader(require$1.resolve("vue-loader")).options({
|
|
200
|
+
...options.vue,
|
|
201
|
+
isServerBuild: isServer
|
|
202
|
+
}).end();
|
|
203
|
+
if (lang === "md") rule.use("vuepress-markdown-loader").loader(require$1.resolve("#vuepress-markdown-loader")).options({ app }).end();
|
|
204
|
+
};
|
|
205
|
+
handleVue({
|
|
206
|
+
lang: "md",
|
|
207
|
+
test: /\.md$/
|
|
208
|
+
});
|
|
209
|
+
handleVue({
|
|
210
|
+
lang: "vue",
|
|
211
|
+
test: /\.vue$/
|
|
212
|
+
});
|
|
213
|
+
config.plugin("vue-loader").use(VueLoaderPlugin);
|
|
214
|
+
};
|
|
215
|
+
// src/config/handleModule.ts
|
|
216
|
+
/**
|
|
217
|
+
* Set rspack module
|
|
218
|
+
*/
|
|
219
|
+
const handleModule = ({ app, options, config, isBuild, isServer }) => {
|
|
220
|
+
config.module.noParse(/^(?:vue|vue-router|(?:@vue\/[^/]+))$/);
|
|
221
|
+
handleModuleVue({
|
|
222
|
+
app,
|
|
223
|
+
options,
|
|
224
|
+
config,
|
|
225
|
+
isBuild,
|
|
226
|
+
isServer
|
|
227
|
+
});
|
|
228
|
+
handleModulePug({ config });
|
|
229
|
+
handleModuleAssets({ config });
|
|
230
|
+
handleModuleJs({
|
|
231
|
+
options,
|
|
232
|
+
config,
|
|
233
|
+
isBuild,
|
|
234
|
+
isServer
|
|
235
|
+
});
|
|
236
|
+
handleModuleTs({ config });
|
|
237
|
+
handleModuleStyles({
|
|
238
|
+
options,
|
|
239
|
+
config,
|
|
240
|
+
isBuild,
|
|
241
|
+
isServer
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
// src/config/handleNode.ts
|
|
245
|
+
/**
|
|
246
|
+
* Set rspack node config
|
|
247
|
+
*/
|
|
248
|
+
const handleNode = ({ config }) => {
|
|
249
|
+
config.node.set("__filename", false).set("__dirname", false).set("global", false);
|
|
250
|
+
};
|
|
251
|
+
// src/config/handleOtherOptions.ts
|
|
252
|
+
const require = createRequire(import.meta.url);
|
|
253
|
+
/**
|
|
254
|
+
* Set rspack other options
|
|
255
|
+
*
|
|
256
|
+
* @see https://rspack.rs/config/other-options
|
|
257
|
+
*/
|
|
258
|
+
const handleOtherOptions = ({ app, config, isBuild, isServer }) => {
|
|
259
|
+
config.infrastructureLogging({ level: app.env.isDebug ? "info" : "error" });
|
|
260
|
+
config.cache({
|
|
261
|
+
type: "persistent",
|
|
262
|
+
storage: {
|
|
263
|
+
type: "filesystem",
|
|
264
|
+
directory: app.dir.cache()
|
|
265
|
+
},
|
|
266
|
+
version: JSON.stringify({
|
|
267
|
+
isBuild,
|
|
268
|
+
isServer,
|
|
269
|
+
"version": app.version,
|
|
270
|
+
"esbuild-loader": require("esbuild-loader/package.json").version,
|
|
271
|
+
"vue-loader": require("vue-loader/package.json").version,
|
|
272
|
+
"@rspack/core": require("@rspack/core/package.json").version
|
|
273
|
+
})
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
// src/config/handlePluginDefine.ts
|
|
277
|
+
/**
|
|
278
|
+
* Set rspack DefinePlugin
|
|
279
|
+
*/
|
|
280
|
+
const handlePluginDefine = async ({ app, config, isBuild, isServer }) => {
|
|
281
|
+
config.plugin("define").use(DefinePlugin, [{
|
|
282
|
+
__VUEPRESS_VERSION__: JSON.stringify(app.version),
|
|
283
|
+
__VUEPRESS_BASE__: JSON.stringify(app.options.base),
|
|
284
|
+
__VUEPRESS_DEV__: JSON.stringify(!isBuild),
|
|
285
|
+
__VUEPRESS_SSR__: JSON.stringify(isServer),
|
|
286
|
+
__VUE_OPTIONS_API__: JSON.stringify(true),
|
|
287
|
+
__VUE_PROD_DEVTOOLS__: JSON.stringify(app.env.isDebug),
|
|
288
|
+
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(app.env.isDebug)
|
|
289
|
+
}]);
|
|
290
|
+
const defineResult = await app.pluginApi.hooks.define.process(app, isServer);
|
|
291
|
+
config.plugin("define").tap(([options]) => {
|
|
292
|
+
defineResult.forEach((defineObject) => {
|
|
293
|
+
Object.entries(defineObject).forEach(([key, value]) => {
|
|
294
|
+
options[key] = JSON.stringify(value);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
return [options];
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
// src/config/handleResolve.ts
|
|
301
|
+
/**
|
|
302
|
+
* Set rspack resolve
|
|
303
|
+
*/
|
|
304
|
+
const handleResolve = async ({ app, config, isServer }) => {
|
|
305
|
+
const alias = {
|
|
306
|
+
"@source": app.dir.source(),
|
|
307
|
+
"@temp": app.dir.temp(),
|
|
308
|
+
"@internal": app.dir.temp("internal")
|
|
309
|
+
};
|
|
310
|
+
(await app.pluginApi.hooks.alias.process(app, isServer)).forEach((aliasObject) => {
|
|
311
|
+
Object.assign(alias, aliasObject);
|
|
312
|
+
});
|
|
313
|
+
config.resolve.alias.merge(Object.fromEntries(Object.entries(alias).sort(([a], [b]) => b.length - a.length)));
|
|
314
|
+
config.resolve.extensions.merge([
|
|
315
|
+
".js",
|
|
316
|
+
".jsx",
|
|
317
|
+
".ts",
|
|
318
|
+
".tsx",
|
|
319
|
+
".vue",
|
|
320
|
+
".json"
|
|
321
|
+
]);
|
|
322
|
+
config.resolve.extensionAlias.merge({
|
|
323
|
+
".js": [".js", ".ts"],
|
|
324
|
+
".mjs": [".mjs", ".mts"]
|
|
325
|
+
});
|
|
326
|
+
};
|
|
327
|
+
// src/config/createBaseConfig.ts
|
|
328
|
+
const createBaseConfig = async ({ app, options, isBuild, isServer }) => {
|
|
329
|
+
const config = new RspackChain();
|
|
330
|
+
/**
|
|
331
|
+
* entry
|
|
332
|
+
*/
|
|
333
|
+
handleEntry({
|
|
334
|
+
app,
|
|
335
|
+
config
|
|
336
|
+
});
|
|
337
|
+
/**
|
|
338
|
+
* mode
|
|
339
|
+
*/
|
|
340
|
+
handleMode({
|
|
341
|
+
app,
|
|
342
|
+
config,
|
|
343
|
+
isBuild
|
|
344
|
+
});
|
|
345
|
+
/**
|
|
346
|
+
* node
|
|
347
|
+
*/
|
|
348
|
+
handleNode({ config });
|
|
349
|
+
/**
|
|
350
|
+
* devtool
|
|
351
|
+
*/
|
|
352
|
+
handleDevtool({
|
|
353
|
+
app,
|
|
354
|
+
config,
|
|
355
|
+
isBuild
|
|
356
|
+
});
|
|
357
|
+
/**
|
|
358
|
+
* resolve
|
|
359
|
+
*/
|
|
360
|
+
await handleResolve({
|
|
361
|
+
app,
|
|
362
|
+
config,
|
|
363
|
+
isServer
|
|
364
|
+
});
|
|
365
|
+
/**
|
|
366
|
+
* module
|
|
367
|
+
*/
|
|
368
|
+
handleModule({
|
|
369
|
+
app,
|
|
370
|
+
options,
|
|
371
|
+
config,
|
|
372
|
+
isBuild,
|
|
373
|
+
isServer
|
|
374
|
+
});
|
|
375
|
+
/**
|
|
376
|
+
* plugins
|
|
377
|
+
*/
|
|
378
|
+
await handlePluginDefine({
|
|
379
|
+
app,
|
|
380
|
+
config,
|
|
381
|
+
isBuild,
|
|
382
|
+
isServer
|
|
383
|
+
});
|
|
384
|
+
/**
|
|
385
|
+
* other options
|
|
386
|
+
*/
|
|
387
|
+
handleOtherOptions({
|
|
388
|
+
app,
|
|
389
|
+
config,
|
|
390
|
+
isBuild,
|
|
391
|
+
isServer
|
|
392
|
+
});
|
|
393
|
+
return config;
|
|
394
|
+
};
|
|
395
|
+
// src/config/createClientBaseConfig.ts
|
|
396
|
+
const createClientBaseConfig = async ({ app, options, isBuild }) => {
|
|
397
|
+
const config = await createBaseConfig({
|
|
398
|
+
app,
|
|
399
|
+
options,
|
|
400
|
+
isServer: false,
|
|
401
|
+
isBuild
|
|
402
|
+
});
|
|
403
|
+
config.output.path(app.dir.dest()).filename(isBuild ? "assets/js/[name].[chunkhash:8].js" : "assets/js/[name].js").publicPath(app.options.base);
|
|
404
|
+
return config;
|
|
405
|
+
};
|
|
406
|
+
// src/build/createClientPlugin.ts
|
|
407
|
+
const isJS = (file) => /\.js(\?[^.]+)?$/.test(file);
|
|
408
|
+
const isCSS = (file) => /\.css(\?[^.]+)?$/.test(file);
|
|
409
|
+
/**
|
|
410
|
+
* Vuepress client plugin
|
|
411
|
+
*
|
|
412
|
+
* Collecting rspack bundled files info for SSR
|
|
413
|
+
*/
|
|
414
|
+
const createClientPlugin = (outputFile) => {
|
|
415
|
+
return { apply(compiler) {
|
|
416
|
+
compiler.hooks.emit.tapPromise("vuepress-client-plugin", async (compilation) => {
|
|
417
|
+
const { modules = [], entrypoints = {}, chunks = [] } = compilation.getStats().toJson({
|
|
418
|
+
all: false,
|
|
419
|
+
modules: true,
|
|
420
|
+
entrypoints: true,
|
|
421
|
+
chunks: true,
|
|
422
|
+
chunkModules: true
|
|
423
|
+
});
|
|
424
|
+
const allFiles = chunks.flatMap((c) => c.files ?? []);
|
|
425
|
+
const initialFiles = Object.keys(entrypoints).flatMap((entry) => entrypoints[entry].assets?.map(({ name }) => name) ?? []).filter((file) => isJS(file) || isCSS(file));
|
|
426
|
+
const asyncFiles = allFiles.filter((file) => (isJS(file) || isCSS(file)) && !initialFiles.includes(file));
|
|
427
|
+
const assetModules = modules.filter((m) => Boolean(m.assets?.length));
|
|
428
|
+
const manifestModules = {};
|
|
429
|
+
const fileToIndex = (file) => allFiles.indexOf(file.toString());
|
|
430
|
+
modules.forEach((m) => {
|
|
431
|
+
if (m.chunks?.length !== 1) return;
|
|
432
|
+
const cid = m.chunks[0];
|
|
433
|
+
const chunk = chunks.find((c) => c.id === cid);
|
|
434
|
+
if (!chunk?.files) return;
|
|
435
|
+
const request = m.identifier?.replace(/\|\w+$/, "");
|
|
436
|
+
const files = chunk.files.map(fileToIndex);
|
|
437
|
+
assetModules.forEach((item) => {
|
|
438
|
+
if (item.chunks?.some((id) => id === cid)) files.push(...item.assets.map(fileToIndex));
|
|
439
|
+
});
|
|
440
|
+
if (request) manifestModules[request] = files;
|
|
441
|
+
});
|
|
442
|
+
const clientManifest = {
|
|
443
|
+
all: allFiles,
|
|
444
|
+
initial: initialFiles,
|
|
445
|
+
async: asyncFiles,
|
|
446
|
+
modules: manifestModules,
|
|
447
|
+
chunks: Object.fromEntries(Array.from(compilation.namedChunkGroups, ([name, chunkGroup]) => [name, chunkGroup.getFiles()]))
|
|
448
|
+
};
|
|
449
|
+
const clientManifestJson = JSON.stringify(clientManifest, null, 2);
|
|
450
|
+
await fs.outputFile(outputFile, clientManifestJson);
|
|
451
|
+
});
|
|
452
|
+
} };
|
|
453
|
+
};
|
|
454
|
+
// src/build/createClientConfig.ts
|
|
455
|
+
/**
|
|
456
|
+
* Filename of the client manifest file that generated by client plugin
|
|
457
|
+
*/
|
|
458
|
+
const CLIENT_MANIFEST_FILENAME = ".server/client-manifest.json";
|
|
459
|
+
const createClientConfig = async (app, options) => {
|
|
460
|
+
const config = await createClientBaseConfig({
|
|
461
|
+
app,
|
|
462
|
+
options,
|
|
463
|
+
isBuild: true
|
|
464
|
+
});
|
|
465
|
+
config.plugin("vuepress-client").use(createClientPlugin(app.dir.temp(CLIENT_MANIFEST_FILENAME)));
|
|
466
|
+
if (fs.pathExistsSync(app.dir.public())) config.plugin("copy").use(CopyRspackPlugin, [{ patterns: [{
|
|
467
|
+
from: app.dir.public(),
|
|
468
|
+
to: app.dir.dest()
|
|
469
|
+
}] }]);
|
|
470
|
+
config.plugin("css-extract").use(CssExtractRspackPlugin, [{ filename: "assets/css/styles.[chunkhash:8].css" }]);
|
|
471
|
+
config.optimization.splitChunks({ cacheGroups: {
|
|
472
|
+
styles: {
|
|
473
|
+
idHint: "styles",
|
|
474
|
+
test: (m) => m.type.includes("css/mini-extract"),
|
|
475
|
+
chunks: "all",
|
|
476
|
+
enforce: true,
|
|
477
|
+
reuseExistingChunk: true
|
|
478
|
+
},
|
|
479
|
+
vendor: {
|
|
480
|
+
idHint: "vendor",
|
|
481
|
+
test: /node_modules/,
|
|
482
|
+
chunks: "all",
|
|
483
|
+
priority: -10,
|
|
484
|
+
reuseExistingChunk: true
|
|
485
|
+
}
|
|
486
|
+
} });
|
|
487
|
+
config.optimization.runtimeChunk(true);
|
|
488
|
+
config.optimization.minimize(true);
|
|
489
|
+
config.optimization.set("minimizer", ["...", new LightningCssMinimizerRspackPlugin()]);
|
|
490
|
+
if (!app.env.isDebug) config.performance.hints(false);
|
|
491
|
+
return config;
|
|
492
|
+
};
|
|
493
|
+
// src/build/createServerConfig.ts
|
|
494
|
+
const createServerConfig = async (app, options) => {
|
|
495
|
+
const config = await createBaseConfig({
|
|
496
|
+
app,
|
|
497
|
+
options,
|
|
498
|
+
isBuild: true,
|
|
499
|
+
isServer: true
|
|
500
|
+
});
|
|
501
|
+
config.output.path(app.dir.temp(".server")).filename("app.cjs").publicPath(app.options.base).library({ type: "commonjs2" });
|
|
502
|
+
config.target("node");
|
|
503
|
+
config.externals([/^vue($|\/)/]);
|
|
504
|
+
config.devtool("source-map");
|
|
505
|
+
config.optimization.minimize(false);
|
|
506
|
+
return config;
|
|
507
|
+
};
|
|
508
|
+
// src/build/renderPagePrefetchLinks.ts
|
|
509
|
+
/**
|
|
510
|
+
* Render prefetch links of current page
|
|
511
|
+
*/
|
|
512
|
+
const renderPagePrefetchLinks = ({ app, asyncFilesMeta, page, pageClientFilesMeta, pageChunkFilesMap }) => {
|
|
513
|
+
const { shouldPrefetch } = app.options;
|
|
514
|
+
if (shouldPrefetch === false) return "";
|
|
515
|
+
let prefetchFilesMeta;
|
|
516
|
+
if (shouldPrefetch === "as-needed") {
|
|
517
|
+
const linkedPageChunkFiles = resolveLinkedPageChunkFiles({
|
|
518
|
+
base: app.options.base,
|
|
519
|
+
page,
|
|
520
|
+
pageChunkFilesMap
|
|
521
|
+
});
|
|
522
|
+
prefetchFilesMeta = asyncFilesMeta.filter(({ file }) => linkedPageChunkFiles.has(file) && !pageClientFilesMeta.some((f) => f.file === file));
|
|
523
|
+
} else prefetchFilesMeta = asyncFilesMeta.filter(({ file }) => !pageClientFilesMeta.some((f) => f.file === file));
|
|
524
|
+
return prefetchFilesMeta.map(({ file, type }) => {
|
|
525
|
+
if (shouldPrefetch !== true && shouldPrefetch !== "as-needed" && !shouldPrefetch(file, type)) return "";
|
|
526
|
+
return `<link rel="prefetch" href="${app.options.base}${file}" as="${type}">`;
|
|
527
|
+
}).join("");
|
|
528
|
+
};
|
|
529
|
+
// src/build/renderPagePreloadLinks.ts
|
|
530
|
+
/**
|
|
531
|
+
* Render preload links of current page
|
|
532
|
+
*/
|
|
533
|
+
const renderPagePreloadLinks = ({ app, initialFilesMeta, pageClientFilesMeta }) => {
|
|
534
|
+
const { shouldPreload } = app.options;
|
|
535
|
+
if (shouldPreload === false) return "";
|
|
536
|
+
return [...initialFilesMeta, ...pageClientFilesMeta].map(({ file, extension, type }) => {
|
|
537
|
+
if (shouldPreload === true && type !== "script" && type !== "style") return "";
|
|
538
|
+
if (shouldPreload !== true && !shouldPreload(file, type)) return "";
|
|
539
|
+
return `<link rel="preload" href="${app.options.base}${file}"${type !== "" ? ` as="${type}"` : ""}${type === "font" ? ` type="font/${extension}" crossorigin` : ""}>`;
|
|
540
|
+
}).join("");
|
|
541
|
+
};
|
|
542
|
+
// src/build/renderPageScripts.ts
|
|
543
|
+
/**
|
|
544
|
+
* Render scripts of current page
|
|
545
|
+
*/
|
|
546
|
+
const renderPageScripts = ({ app, initialFilesMeta, pageClientFilesMeta }) => [...pageClientFilesMeta, ...initialFilesMeta].filter(({ type }) => type === "script").map(({ file }) => `<script src="${app.options.base}${file}" defer><\/script>`).join("");
|
|
547
|
+
// src/build/renderPageStyles.ts
|
|
548
|
+
/**
|
|
549
|
+
* Render styles of current page
|
|
550
|
+
*/
|
|
551
|
+
const renderPageStyles = ({ app, initialFilesMeta, pageClientFilesMeta }) => [...initialFilesMeta, ...pageClientFilesMeta].filter(({ type }) => type === "style").map(({ file }) => `<link rel="stylesheet" href="${app.options.base}${file}">`).join("");
|
|
552
|
+
// src/build/resolvePageClientFilesMeta.ts
|
|
553
|
+
/**
|
|
554
|
+
* Get all client files according to module requests of a page
|
|
555
|
+
*/
|
|
556
|
+
const resolvePageClientFilesMeta = ({ moduleRequests, moduleFilesMetaMap }) => {
|
|
557
|
+
const files = /* @__PURE__ */ new Set();
|
|
558
|
+
moduleRequests.forEach((request) => {
|
|
559
|
+
moduleFilesMetaMap[request]?.forEach((file) => files.add(file));
|
|
560
|
+
});
|
|
561
|
+
return Array.from(files);
|
|
562
|
+
};
|
|
563
|
+
// src/build/renderPage.ts
|
|
564
|
+
/**
|
|
565
|
+
* Render page to html file, return the html file path
|
|
566
|
+
*/
|
|
567
|
+
const renderPage = async ({ app, page, vueApp, vueRouter, ssrTemplate, initialFilesMeta, asyncFilesMeta, moduleFilesMetaMap, pageChunkFilesMap }) => {
|
|
568
|
+
const { ssrContext, ssrString } = await renderPageToString({
|
|
569
|
+
page,
|
|
570
|
+
vueApp,
|
|
571
|
+
vueRouter,
|
|
572
|
+
ssrContextInit: { _registeredComponents: /* @__PURE__ */ new Set() }
|
|
573
|
+
});
|
|
574
|
+
const pageClientFilesMeta = resolvePageClientFilesMeta({
|
|
575
|
+
moduleRequests: Array.from(ssrContext._registeredComponents),
|
|
576
|
+
moduleFilesMetaMap
|
|
577
|
+
});
|
|
578
|
+
const html = await app.options.templateBuildRenderer(ssrTemplate, {
|
|
579
|
+
content: ssrString,
|
|
580
|
+
head: ssrContext.head.map(renderHead).join(""),
|
|
581
|
+
lang: ssrContext.lang,
|
|
582
|
+
prefetch: renderPagePrefetchLinks({
|
|
583
|
+
app,
|
|
584
|
+
asyncFilesMeta,
|
|
585
|
+
page,
|
|
586
|
+
pageClientFilesMeta,
|
|
587
|
+
pageChunkFilesMap
|
|
588
|
+
}),
|
|
589
|
+
preload: renderPagePreloadLinks({
|
|
590
|
+
app,
|
|
591
|
+
initialFilesMeta,
|
|
592
|
+
pageClientFilesMeta
|
|
593
|
+
}),
|
|
594
|
+
scripts: renderPageScripts({
|
|
595
|
+
app,
|
|
596
|
+
initialFilesMeta,
|
|
597
|
+
pageClientFilesMeta
|
|
598
|
+
}),
|
|
599
|
+
styles: renderPageStyles({
|
|
600
|
+
app,
|
|
601
|
+
initialFilesMeta,
|
|
602
|
+
pageClientFilesMeta
|
|
603
|
+
}),
|
|
604
|
+
version: app.version
|
|
605
|
+
});
|
|
606
|
+
await fs.outputFile(page.htmlFilePath, html);
|
|
607
|
+
};
|
|
608
|
+
// src/build/resolveFileMetaType.ts
|
|
609
|
+
/**
|
|
610
|
+
* Resolve client file type by extension
|
|
611
|
+
*/
|
|
612
|
+
const resolveFileMetaType = (extension) => {
|
|
613
|
+
if (extension === "js") return "script";
|
|
614
|
+
if (extension === "css") return "style";
|
|
615
|
+
if (/jpe?g|png|svg|gif|webp|ico/i.test(extension)) return "image";
|
|
616
|
+
if (/woff2?|ttf|otf|eot/i.test(extension)) return "font";
|
|
617
|
+
return "";
|
|
618
|
+
};
|
|
619
|
+
// src/build/resolveFileMeta.ts
|
|
620
|
+
/**
|
|
621
|
+
* Resolve client file meta from to file name
|
|
622
|
+
*/
|
|
623
|
+
const resolveFileMeta = (file) => {
|
|
624
|
+
const extension = path.extname(file).slice(1);
|
|
625
|
+
return {
|
|
626
|
+
file,
|
|
627
|
+
extension,
|
|
628
|
+
type: resolveFileMetaType(extension)
|
|
629
|
+
};
|
|
630
|
+
};
|
|
631
|
+
// src/build/resolveClientManifestMeta.ts
|
|
632
|
+
/**
|
|
633
|
+
* Resolve files meta from clientManifest
|
|
634
|
+
*/
|
|
635
|
+
const resolveClientManifestMeta = ({ all, initial, async, modules }) => {
|
|
636
|
+
const allFilesMeta = all.map(resolveFileMeta);
|
|
637
|
+
return {
|
|
638
|
+
allFilesMeta,
|
|
639
|
+
initialFilesMeta: initial.map(resolveFileMeta),
|
|
640
|
+
asyncFilesMeta: async.map(resolveFileMeta),
|
|
641
|
+
moduleFilesMetaMap: Object.fromEntries(Object.entries(modules).map(([moduleRequest, assetFilesIndex]) => [moduleRequest, assetFilesIndex.map((fileIndex) => allFilesMeta[fileIndex]).filter(({ file, type }) => async.includes(file) || type !== "style" && type !== "script")]))
|
|
642
|
+
};
|
|
643
|
+
};
|
|
644
|
+
// src/build/build.ts
|
|
645
|
+
const log = debug("vuepress:bundler-rspack/build");
|
|
646
|
+
const build = async (options, app) => {
|
|
647
|
+
await app.pluginApi.hooks.extendsBundlerOptions.process(options, app);
|
|
648
|
+
log("compiling start");
|
|
649
|
+
await withSpinner("Compiling with rspack")(async () => {
|
|
650
|
+
const clientConfig = resolveRspackConfig({
|
|
651
|
+
config: await createClientConfig(app, options),
|
|
652
|
+
options,
|
|
653
|
+
isServer: false,
|
|
654
|
+
isBuild: true
|
|
655
|
+
});
|
|
656
|
+
const serverConfig = resolveRspackConfig({
|
|
657
|
+
config: await createServerConfig(app, options),
|
|
658
|
+
options,
|
|
659
|
+
isServer: true,
|
|
660
|
+
isBuild: true
|
|
661
|
+
});
|
|
662
|
+
await new Promise((resolve, reject) => {
|
|
663
|
+
rspack([clientConfig, serverConfig], (err, stats) => {
|
|
664
|
+
if (err) reject(err);
|
|
665
|
+
else {
|
|
666
|
+
if (stats) {
|
|
667
|
+
const { warnings, errors } = stats.toJson("errors-warnings");
|
|
668
|
+
errors?.forEach((item) => {
|
|
669
|
+
logger.error(item);
|
|
670
|
+
});
|
|
671
|
+
warnings?.forEach((warning) => {
|
|
672
|
+
logger.warn(warning);
|
|
673
|
+
});
|
|
674
|
+
if (stats.hasErrors()) reject(/* @__PURE__ */ new Error("Failed to compile with errors"));
|
|
675
|
+
}
|
|
676
|
+
resolve();
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
});
|
|
681
|
+
log("compiling finish");
|
|
682
|
+
await withSpinner(`Rendering ${app.pages.length} pages`)(async (spinner) => {
|
|
683
|
+
const clientManifestPath = app.dir.temp(CLIENT_MANIFEST_FILENAME);
|
|
684
|
+
const clientManifest = await fs.readJson(clientManifestPath);
|
|
685
|
+
const { initialFilesMeta, asyncFilesMeta, moduleFilesMetaMap } = resolveClientManifestMeta(clientManifest);
|
|
686
|
+
const pageChunkFilesMap = createPageChunkFilesMap({
|
|
687
|
+
pages: app.pages,
|
|
688
|
+
resolvePageChunkFiles: (page) => clientManifest.chunks[page.chunkName] ?? []
|
|
689
|
+
});
|
|
690
|
+
const { vueApp, vueRouter } = await createVueServerApp(app.dir.temp(".server/app.cjs"));
|
|
691
|
+
const ssrTemplate = await getSsrTemplate(app);
|
|
692
|
+
for (const page of app.pages) {
|
|
693
|
+
if (spinner) spinner.text = `Rendering pages ${colors.magenta(page.path)}`;
|
|
694
|
+
await renderPage({
|
|
695
|
+
app,
|
|
696
|
+
page,
|
|
697
|
+
vueApp,
|
|
698
|
+
vueRouter,
|
|
699
|
+
ssrTemplate,
|
|
700
|
+
initialFilesMeta,
|
|
701
|
+
asyncFilesMeta,
|
|
702
|
+
moduleFilesMetaMap,
|
|
703
|
+
pageChunkFilesMap
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
if (!app.env.isDebug) await fs.remove(app.dir.temp(".server"));
|
|
708
|
+
};
|
|
709
|
+
// src/dev/createDevConfig.ts
|
|
710
|
+
const createDevConfig = async (app, options) => {
|
|
711
|
+
const config = await createClientBaseConfig({
|
|
712
|
+
app,
|
|
713
|
+
options,
|
|
714
|
+
isBuild: false
|
|
715
|
+
});
|
|
716
|
+
config.plugin("html").use(HtmlRspackPlugin, [{ template: app.options.templateDev }]);
|
|
717
|
+
config.plugin("hmr").use(HotModuleReplacementPlugin);
|
|
718
|
+
return config;
|
|
719
|
+
};
|
|
720
|
+
// src/dev/trailingSlashMiddleware.ts
|
|
721
|
+
const FAKE_HOST = "http://.";
|
|
722
|
+
/**
|
|
723
|
+
* A middleware to add trailing slash to the url
|
|
724
|
+
*
|
|
725
|
+
* It will redirect '/foo' to '/foo/' with 302
|
|
726
|
+
*/
|
|
727
|
+
const trailingSlashMiddleware = (req, res, next) => {
|
|
728
|
+
if (!req.method || !req.url || !["GET", "HEAD"].includes(req.method)) {
|
|
729
|
+
next();
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
const { pathname } = new URL(req.url, FAKE_HOST);
|
|
733
|
+
if (pathname.split("/").pop()?.includes(".") || pathname.endsWith("/")) {
|
|
734
|
+
next();
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
const query = req.url.slice(pathname.length);
|
|
738
|
+
res.statusCode = 302;
|
|
739
|
+
res.setHeader("Location", `${pathname}/${query}`);
|
|
740
|
+
res.end();
|
|
741
|
+
};
|
|
742
|
+
// src/dev/createDevServerConfig.ts
|
|
743
|
+
const createDevServerConfig = (app, options) => ({
|
|
744
|
+
allowedHosts: "all",
|
|
745
|
+
compress: true,
|
|
746
|
+
devMiddleware: {
|
|
747
|
+
publicPath: app.options.base,
|
|
748
|
+
writeToDisk: false,
|
|
749
|
+
stats: app.env.isDebug ? "normal" : "errors-warnings"
|
|
750
|
+
},
|
|
751
|
+
headers: { "access-control-allow-origin": "*" },
|
|
752
|
+
historyApiFallback: {
|
|
753
|
+
disableDotRule: true,
|
|
754
|
+
rewrites: [{
|
|
755
|
+
from: /./,
|
|
756
|
+
to: path.join(app.options.base, "index.html")
|
|
757
|
+
}]
|
|
758
|
+
},
|
|
759
|
+
host: app.options.host,
|
|
760
|
+
hot: true,
|
|
761
|
+
setupMiddlewares: (middlewares, devServer) => {
|
|
762
|
+
devServer.app?.use(trailingSlashMiddleware);
|
|
763
|
+
return options.devServerSetupMiddlewares?.(middlewares, devServer) ?? middlewares;
|
|
764
|
+
},
|
|
765
|
+
open: app.options.open,
|
|
766
|
+
port: app.options.port,
|
|
767
|
+
static: {
|
|
768
|
+
directory: app.dir.public().replace("/", sep),
|
|
769
|
+
publicPath: app.options.base,
|
|
770
|
+
watch: {
|
|
771
|
+
ignoreInitial: true,
|
|
772
|
+
ignored: ["node_modules"]
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
});
|
|
776
|
+
// src/dev/dev.ts
|
|
777
|
+
/**
|
|
778
|
+
* Create the dev method of rspack bundler
|
|
779
|
+
*/
|
|
780
|
+
const dev = async (options, app) => {
|
|
781
|
+
await app.pluginApi.hooks.extendsBundlerOptions.process(options, app);
|
|
782
|
+
const rspackConfig = resolveRspackConfig({
|
|
783
|
+
config: await createDevConfig(app, options),
|
|
784
|
+
options,
|
|
785
|
+
isServer: false,
|
|
786
|
+
isBuild: false
|
|
787
|
+
});
|
|
788
|
+
const compiler = rspack(rspackConfig);
|
|
789
|
+
const serverConfig = createDevServerConfig(app, options);
|
|
790
|
+
const server = new RspackDevServer(serverConfig, compiler);
|
|
791
|
+
const [, close] = await Promise.all([server.start(), new Promise((resolve, reject) => {
|
|
792
|
+
const spinner = ora();
|
|
793
|
+
let hasStarted = false;
|
|
794
|
+
let hasFinished = false;
|
|
795
|
+
compiler.hooks.beforeCompile.tap("vuepress-dev", () => {
|
|
796
|
+
if (hasStarted) return;
|
|
797
|
+
hasStarted = true;
|
|
798
|
+
spinner.start("Compiling with rspack...");
|
|
799
|
+
});
|
|
800
|
+
compiler.hooks.done.tap("vuepress-dev", ({ endTime, startTime }) => {
|
|
801
|
+
if (hasFinished) return;
|
|
802
|
+
hasFinished = true;
|
|
803
|
+
spinner.succeed(endTime && startTime ? `Compilation finished in ${endTime - startTime}ms` : "Compilation finished");
|
|
804
|
+
const url = `http://${serverConfig.host === "0.0.0.0" ? "localhost" : serverConfig.host}:${serverConfig.port}${app.options.base}`;
|
|
805
|
+
logger.success(`VuePress rspack dev server is listening at ${colors.cyan(url)}`);
|
|
806
|
+
resolve(async () => server.stop());
|
|
807
|
+
});
|
|
808
|
+
compiler.hooks.failed.tap("vuepress-dev", (err) => {
|
|
809
|
+
if (hasFinished) return;
|
|
810
|
+
hasFinished = true;
|
|
811
|
+
spinner.fail("Compilation failed");
|
|
812
|
+
reject(err);
|
|
813
|
+
});
|
|
814
|
+
})]);
|
|
815
|
+
return close;
|
|
816
|
+
};
|
|
817
|
+
// src/rspackBundler.ts
|
|
818
|
+
const rspackBundler = (options = {}) => ({
|
|
819
|
+
name: "@vuepress/bundler-rspack",
|
|
820
|
+
type: "rspack",
|
|
821
|
+
dev: async (app) => dev(options, app),
|
|
822
|
+
build: async (app) => build(options, app),
|
|
823
|
+
mergeConfig: merge$1
|
|
824
|
+
});
|
|
825
|
+
// src/index.ts
|
|
826
|
+
var src_default = rspackBundler;
|
|
827
|
+
export { src_default as default, rspackBundler, merge as rspackMergeConfig };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __esmMin = (fn, res, err) => () => {
|
|
7
|
+
if (err) throw err[0];
|
|
8
|
+
try {
|
|
9
|
+
return fn && (res = fn(fn = 0)), res;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
throw err = [e], e;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var __exportAll = (all, flags) => {
|
|
15
|
+
let target = Object.setPrototypeOf({}, null);
|
|
16
|
+
for (var name in all) __defProp(target, name, {
|
|
17
|
+
get: all[name],
|
|
18
|
+
enumerable: true
|
|
19
|
+
});
|
|
20
|
+
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
21
|
+
return flags & 2 ? target : Object.preventExtensions(target);
|
|
22
|
+
};
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
25
|
+
key = keys[i];
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
27
|
+
get: ((k) => from[k]).bind(null, key),
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
|
+
Object.defineProperty(exports, "__esmMin", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function() {
|
|
37
|
+
return __esmMin;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "__exportAll", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function() {
|
|
43
|
+
return __exportAll;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports, "__toCommonJS", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function() {
|
|
49
|
+
return __toCommonJS;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C6B9acKu.cjs");
|
|
2
|
+
// src/loaders/vuepressMarkdownLoader.ts
|
|
3
|
+
var vuepressMarkdownLoader_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ vuepressMarkdownLoader: () => vuepressMarkdownLoader });
|
|
4
|
+
var vuepressMarkdownLoader;
|
|
5
|
+
// src/loaders/vuepressMarkdownLoader.cts
|
|
6
|
+
const loader = (require_rolldown_runtime.__esmMin((() => {
|
|
7
|
+
vuepressMarkdownLoader = async function vuepressMarkdownLoader(source) {
|
|
8
|
+
const [{ createPage, renderPageToVue }, { path }] = await Promise.all([import("@vuepress/core"), import("@vuepress/utils")]);
|
|
9
|
+
const { app } = this.getOptions();
|
|
10
|
+
const filePath = path.normalize(this.resourcePath);
|
|
11
|
+
const page = app.pagesMap[filePath];
|
|
12
|
+
if (page?.content === source) return renderPageToVue(app, page);
|
|
13
|
+
return renderPageToVue(app, await createPage(app, {
|
|
14
|
+
content: source,
|
|
15
|
+
filePath
|
|
16
|
+
}));
|
|
17
|
+
};
|
|
18
|
+
}))(), require_rolldown_runtime.__toCommonJS(vuepressMarkdownLoader_exports));
|
|
19
|
+
module.exports = loader.vuepressMarkdownLoader;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C6B9acKu.cjs");
|
|
2
|
+
// src/loaders/vuepressSsrLoader.ts
|
|
3
|
+
var vuepressSsrLoader_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ vuepressSsrLoader: () => vuepressSsrLoader });
|
|
4
|
+
var vuepressSsrLoader;
|
|
5
|
+
// src/loaders/vuepressSsrLoader.cts
|
|
6
|
+
const loader = (require_rolldown_runtime.__esmMin((() => {
|
|
7
|
+
vuepressSsrLoader = function vuepressSsrLoader(source) {
|
|
8
|
+
return source.replace(/import { ssrRender } from (.*)\n/, `import { ssrRender as _ssrRender } from $1
|
|
9
|
+
import { ssrContextKey } from 'vue'
|
|
10
|
+
const ssrRender = (...args) => {
|
|
11
|
+
const ssrContext = args[2].appContext.provides[ssrContextKey]
|
|
12
|
+
ssrContext._registeredComponents.add(${JSON.stringify(this.request)})
|
|
13
|
+
return _ssrRender(...args)
|
|
14
|
+
}
|
|
15
|
+
`);
|
|
16
|
+
};
|
|
17
|
+
}))(), require_rolldown_runtime.__toCommonJS(vuepressSsrLoader_exports));
|
|
18
|
+
module.exports = loader.vuepressSsrLoader;
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/bundler-rspack",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.0.0-rc.32",
|
|
4
|
+
"description": "Bundler rspack package of VuePress",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bundler",
|
|
7
|
+
"rspack",
|
|
8
|
+
"vuepress",
|
|
9
|
+
"vuepress-bundler"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/vuepress",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/vuepress/core/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "meteorlxy",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/vuepress/core.git"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"imports": {
|
|
29
|
+
"#vuepress-markdown-loader": "./dist/vuepress-markdown-loader.cjs",
|
|
30
|
+
"#vuepress-ssr-loader": "./dist/vuepress-ssr-loader.cjs"
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
".": "./dist/index.js",
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@rspack/core": "^2.3.2",
|
|
41
|
+
"@rspack/dev-server": "^2.2.2",
|
|
42
|
+
"@vuepress/bundlerutils": "2.0.0-rc.32",
|
|
43
|
+
"@vuepress/client": "2.0.0-rc.32",
|
|
44
|
+
"@vuepress/core": "2.0.0-rc.32",
|
|
45
|
+
"@vuepress/shared": "2.0.0-rc.32",
|
|
46
|
+
"@vuepress/utils": "2.0.0-rc.32",
|
|
47
|
+
"autoprefixer": "^10.6.2",
|
|
48
|
+
"css-loader": "^7.1.5",
|
|
49
|
+
"esbuild-loader": "~4.5.0",
|
|
50
|
+
"postcss": "^8.5.32",
|
|
51
|
+
"postcss-loader": "^8.2.1",
|
|
52
|
+
"rspack-chain": "^2.3.2",
|
|
53
|
+
"rspack-merge": "^1.0.1",
|
|
54
|
+
"style-loader": "^4.0.0",
|
|
55
|
+
"vue": "^3.5.45",
|
|
56
|
+
"vue-loader": "^17.4.2",
|
|
57
|
+
"vue-router": "^5.4.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"connect-next": "^5.0.0"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": "^22.18.0 || ^24 || >=26"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsdown",
|
|
67
|
+
"clean": "rimraf dist"
|
|
68
|
+
}
|
|
6
69
|
}
|