Build extension
Rsbuild
Rspress builds documents based on Rsbuild.
Configure Rsbuild
Rsbuild provides a rich set of build configurations. You can customize these configurations through builderConfig. For example, change the output directory to doc_dist
:
import { defineConfig } from '@rspress/core';
export default defineConfig({
builderConfig: {
output: {
distPath: {
root: 'doc_dist',
},
},
},
});
Rspress also provides the builderConfig.plugins config to register Rsbuild plugins. You can leverage Rsbuild's extensive plugin ecosystem to enhance and extend your build capabilities.
For example, add Google analytics through rsbuild-plugin-google-analytics:
import { defineConfig } from '@rspress/core';
import { pluginGoogleAnalytics } from 'rsbuild-plugin-google-analytics';
export default defineConfig({
builderConfig: {
plugins: [
pluginGoogleAnalytics({
// replace this with your Google tag ID
id: 'G-xxxxxxxxxx',
}),
],
},
});
You can learn more about the configuration options through Rsbuild - Config documentation.
Configure Rspack
You can configure Rspack through the tools.rspack option provided by Rsbuild:
import { defineConfig } from '@rspress/core';
export default defineConfig({
builderConfig: {
tools: {
rspack(options) {
// modify the rspack configuration
},
},
},
});
MDX compilation
The compilation of MDX in Rspress is based on unified, and you can add related compilation plugins through markdown
configuration. for example
:
import { defineConfig } from '@rspress/core';
export default defineConfig({
markdown: {
// It's necessary to use JS version compiler
mdxRs: false,
remarkPlugins: [
[
require('remark-autolink-headings'),
{
behavior: 'wrap',
},
],
],
rehypePlugins: [require('rehype-slug')],
},
});
Only the JS version of the MDX compiler supports compilation plugins.