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