@rspress/plugin-playground 0.0.0-nightly-20230919160314 → 0.1.0

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.
@@ -6,6 +6,7 @@ interface PlaygroundOptions {
6
6
  include: Array<string | [string, string]>;
7
7
  defaultDirection: 'horizontal' | 'vertical';
8
8
  editorPosition: 'left' | 'right';
9
+ babelUrl: string;
9
10
  monacoLoader: Parameters<typeof loader.config>[0];
10
11
  monacoOptions: EditorProps['options'];
11
12
  }
@@ -3006,15 +3006,29 @@ var remarkPlugin = ({ getRouteMeta, defaultDirection, editorPosition }) => {
3006
3006
  };
3007
3007
  };
3008
3008
 
3009
+ // src/web/constant.ts
3010
+ var DEFAULT_BABEL_URL = "https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.22.20/babel.min.js";
3011
+ var DEFAULT_MONACO_URL = "https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs";
3012
+
3013
+ // src/web/utils.ts
3014
+ function normalizeUrl(u) {
3015
+ return u.replace(/\/\//g, "/");
3016
+ }
3017
+
3009
3018
  // src/cli/index.ts
3010
3019
  var routeMeta;
3011
3020
  function pluginPlayground(options) {
3012
- const { render = "", include, defaultDirection = "horizontal", editorPosition = "left", monacoLoader = {}, monacoOptions = {} } = options || {};
3021
+ const { render = "", include, defaultDirection = "horizontal", editorPosition = "left", babelUrl = "", monacoLoader = {}, monacoOptions = {} } = options || {};
3013
3022
  const playgroundVirtualModule = new import_rspack_plugin_virtual_module.RspackVirtualModulePlugin({});
3014
3023
  const getRouteMeta = () => routeMeta;
3015
3024
  if (render && !/Playground\.(jsx?|tsx?)$/.test(render)) {
3016
3025
  throw new Error("[Playground]: render should ends with Playground.(jsx?|tsx?)");
3017
3026
  }
3027
+ const preloads = [];
3028
+ preloads.push(babelUrl || DEFAULT_BABEL_URL);
3029
+ const monacoPrefix = monacoLoader.paths?.vs || DEFAULT_MONACO_URL;
3030
+ preloads.push(normalizeUrl(`${monacoPrefix}/loader.js`));
3031
+ preloads.push(normalizeUrl(`${monacoPrefix}/editor/editor.main.js`));
3018
3032
  return {
3019
3033
  name: "@rspress/plugin-playground",
3020
3034
  async routeGenerated(routes) {
@@ -3112,10 +3126,22 @@ function pluginPlayground(options) {
3112
3126
  builderConfig: {
3113
3127
  source: {
3114
3128
  define: {
3129
+ __PLAYGROUND_BABEL_URL__: JSON.stringify(babelUrl),
3115
3130
  __PLAYGROUND_MONACO_LOADER__: JSON.stringify(monacoLoader),
3116
3131
  __PLAYGROUND_MONACO_OPTIONS__: JSON.stringify(monacoOptions)
3117
3132
  }
3118
3133
  },
3134
+ html: {
3135
+ tags: preloads.map((url) => ({
3136
+ tag: "link",
3137
+ head: true,
3138
+ attrs: {
3139
+ rel: "preload",
3140
+ href: url,
3141
+ as: "script"
3142
+ }
3143
+ }))
3144
+ },
3119
3145
  tools: {
3120
3146
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error
3121
3147
  // @ts-ignore