]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
build: trim vapor intenral helper exports form runtime-core in non-esm-bunlder builds
authorEvan You <evan@vuejs.org>
Sun, 8 Dec 2024 07:53:13 +0000 (15:53 +0800)
committerEvan You <evan@vuejs.org>
Sun, 8 Dec 2024 07:53:13 +0000 (15:53 +0800)
rollup.config.js
scripts/trim-vapor-exports.js [new file with mode: 0644]

index 5180d4637313eeb539adc379fbe8118d9f29836c..3ae06651452e7e96d4ff5951b750fc417839b062 100644 (file)
@@ -15,6 +15,7 @@ import alias from '@rollup/plugin-alias'
 import { entries } from './scripts/aliases.js'
 import { inlineEnums } from './scripts/inline-enums.js'
 import { minify as minifySwc } from '@swc/core'
+import { trimVaporExportsPlugin } from './scripts/trim-vapor-exports.js'
 
 /**
  * @template T
@@ -186,6 +187,7 @@ function createConfig(format, output, plugins = []) {
     // used alone.
     external: resolveExternal(),
     plugins: [
+      ...trimVaporExportsPlugin(format, pkg.name),
       json({
         namedExports: false,
       }),
diff --git a/scripts/trim-vapor-exports.js b/scripts/trim-vapor-exports.js
new file mode 100644 (file)
index 0000000..4ccdf8a
--- /dev/null
@@ -0,0 +1,33 @@
+// @ts-check
+
+/**
+ * runtime-core exports a number of internal helpers that are only used by
+ * runtime-vapor, which should be only preserved in vapor / esm-bundler builds.
+ * This plugin should be included as the first plugin for all other formats
+ * other than vapor / esm-bundler.
+ *
+ * @param {string} format
+ * @param {string} pkgName
+ * @returns {import('rollup').Plugin[]}
+ */
+export function trimVaporExportsPlugin(format, pkgName) {
+  if (
+    format === 'vapor' ||
+    format === 'esm-bundler' ||
+    pkgName === '@vue/runtime-vapor'
+  ) {
+    return []
+  } else {
+    return [
+      {
+        name: 'trim-vapor-exports',
+        transform(code, id) {
+          if (id.endsWith('runtime-core/src/index.ts')) {
+            const index = code.lastIndexOf('// VAPOR ---')
+            return code.slice(0, index)
+          }
+        },
+      },
+    ]
+  }
+}