]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
build: remove comments when minifying + inline all enums rolldown
authorEvan You <evan@vuejs.org>
Thu, 14 Nov 2024 15:32:46 +0000 (23:32 +0800)
committerEvan You <evan@vuejs.org>
Thu, 14 Nov 2024 15:32:46 +0000 (23:32 +0800)
rollup.config.js
scripts/create-rolldown-config.js
scripts/inline-enums.js

index 1d6f0da4c6aee6d2d1735235266747b80a6c48e9..da7de554b64d4e780c086359b3ffcb1081ed3c46 100644 (file)
@@ -46,6 +46,12 @@ const pkg = require(resolve(`package.json`))
 const packageOptions = pkg.buildOptions || {}
 const name = packageOptions.filename || path.basename(packageDir)
 
+const banner = `/**
+* ${pkg.name} v${masterVersion}
+* (c) 2018-present Yuxi (Evan) You and Vue contributors
+* @license MIT
+**/`
+
 const [enumPlugin, enumDefines] = inlineEnums()
 
 /** @type {Record<PackageFormat, OutputOptions>} */
@@ -136,11 +142,7 @@ function createConfig(format, output, plugins = []) {
     (isGlobalBuild || isBrowserESMBuild || isBundlerESMBuild) &&
     !packageOptions.enableNonBrowserBranches
 
-  output.banner = `/**
-* ${pkg.name} v${masterVersion}
-* (c) 2018-present Yuxi (Evan) You and Vue contributors
-* @license MIT
-**/`
+  output.banner = banner
 
   output.exports = isCompatPackage ? 'auto' : 'named'
   if (isCJSBuild) {
@@ -372,24 +374,21 @@ function createMinifiedConfig(/** @type {PackageFormat} */ format) {
       {
         name: 'swc-minify',
 
-        async renderChunk(
-          contents,
-          _,
-          { format, sourcemap, sourcemapExcludeSources },
-        ) {
-          const { code, map } = await minifySwc(contents, {
+        async renderChunk(contents, _, { format }) {
+          const { code } = await minifySwc(contents, {
             module: format === 'es',
+            format: {
+              comments: false,
+            },
             compress: {
               ecma: 2016,
               pure_getters: true,
             },
             safari10: true,
             mangle: true,
-            sourceMap: !!sourcemap,
-            inlineSourcesContent: !sourcemapExcludeSources,
           })
 
-          return { code, map: map || null }
+          return { code: banner + code, map: null }
         },
       },
     ],
index cdc2320a35789bcc5e9aeba09157280d68656035..7e8f04a23e00296b57c66648f71e13530dc49ca1 100644 (file)
@@ -50,6 +50,12 @@ export function createConfigsForPackage({
   const packageOptions = pkg.buildOptions || {}
   const name = packageOptions.filename || path.basename(packageDir)
 
+  const banner = `/**!
+  * ${pkg.name} v${masterVersion}
+  * (c) 2018-present Yuxi (Evan) You and Vue contributors
+  * @license MIT
+  **/`
+
   /** @type {Record<PackageFormat, import('rolldown').OutputOptions>} */
   const outputConfigs = {
     'esm-bundler': {
@@ -134,12 +140,7 @@ export function createConfigsForPackage({
       (isGlobalBuild || isBrowserESMBuild || isBundlerESMBuild) &&
       !packageOptions.enableNonBrowserBranches
 
-    output.banner = `/**
-  * ${pkg.name} v${masterVersion}
-  * (c) 2018-present Yuxi (Evan) You and Vue contributors
-  * @license MIT
-  **/`
-
+    output.banner = banner
     output.exports = isCompatPackage ? 'auto' : 'named'
     if (isCJSBuild) {
       output.esModule = true
@@ -354,28 +355,21 @@ export function createConfigsForPackage({
       [
         {
           name: 'swc-minify',
-          async renderChunk(
-            contents,
-            _,
-            {
-              format,
-              sourcemap,
-              // @ts-expect-error not supported yet
-              sourcemapExcludeSources,
-            },
-          ) {
-            const { code, map } = await minifySwc(contents, {
+          async renderChunk(contents, _, { format }) {
+            const { code } = await minifySwc(contents, {
               module: format === 'es',
+              format: {
+                comments: false,
+              },
               compress: {
                 ecma: 2016,
                 pure_getters: true,
               },
               safari10: true,
               mangle: true,
-              sourceMap: !!sourcemap,
-              inlineSourcesContent: !sourcemapExcludeSources,
             })
-            return { code, map: map || null }
+            // swc removes banner
+            return { code: banner + code, map: null }
           },
         },
       ],
index 88b2dca8c61be62e8410aeb0d93ef0049a45f647..e849384b3dfad82fa18203f0902f8aac8d524c4a 100644 (file)
@@ -49,7 +49,7 @@ export function scanEnums() {
   const defines = Object.create(null)
 
   // 1. grep for files with exported enum
-  const { stdout } = spawnSync('git', ['grep', `export enum`])
+  const { stdout } = spawnSync('git', ['grep', `enum `])
   const files = [
     ...new Set(
       stdout
@@ -74,12 +74,19 @@ export function scanEnums() {
     /** @type {Set<string>} */
     const enumIds = new Set()
     for (const node of res.program.body) {
+      let decl
+      if (node.type === 'TSEnumDeclaration') {
+        decl = node
+      }
       if (
         node.type === 'ExportNamedDeclaration' &&
         node.declaration &&
         node.declaration.type === 'TSEnumDeclaration'
       ) {
-        const decl = node.declaration
+        decl = node.declaration
+      }
+
+      if (decl) {
         const id = decl.id.name
         if (enumIds.has(id)) {
           throw new Error(