build: add runtime-global build for vue
This commit is contained in:
parent
f529dbde23
commit
4126a9dd51
@ -18,6 +18,7 @@
|
|||||||
"esm-bundler-runtime",
|
"esm-bundler-runtime",
|
||||||
"cjs",
|
"cjs",
|
||||||
"global",
|
"global",
|
||||||
|
"global-runtime",
|
||||||
"esm"
|
"esm"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -23,11 +23,6 @@ const outputConfigs = {
|
|||||||
file: resolve(`dist/${name}.esm-bundler.js`),
|
file: resolve(`dist/${name}.esm-bundler.js`),
|
||||||
format: `es`
|
format: `es`
|
||||||
},
|
},
|
||||||
// main "vue" package only
|
|
||||||
'esm-bundler-runtime': {
|
|
||||||
file: resolve(`dist/${name}.runtime.esm-bundler.js`),
|
|
||||||
format: `es`
|
|
||||||
},
|
|
||||||
cjs: {
|
cjs: {
|
||||||
file: resolve(`dist/${name}.cjs.js`),
|
file: resolve(`dist/${name}.cjs.js`),
|
||||||
format: `cjs`
|
format: `cjs`
|
||||||
@ -39,6 +34,15 @@ const outputConfigs = {
|
|||||||
esm: {
|
esm: {
|
||||||
file: resolve(`dist/${name}.esm.js`),
|
file: resolve(`dist/${name}.esm.js`),
|
||||||
format: `es`
|
format: `es`
|
||||||
|
},
|
||||||
|
// main "vue" package only
|
||||||
|
'esm-bundler-runtime': {
|
||||||
|
file: resolve(`dist/${name}.runtime.esm-bundler.js`),
|
||||||
|
format: `es`
|
||||||
|
},
|
||||||
|
'global-runtime': {
|
||||||
|
file: resolve(`dist/${name}.runtime.global.js`),
|
||||||
|
format: 'iife'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +58,7 @@ if (process.env.NODE_ENV === 'production') {
|
|||||||
if (format === 'cjs' && packageOptions.prod !== false) {
|
if (format === 'cjs' && packageOptions.prod !== false) {
|
||||||
packageConfigs.push(createProductionConfig(format))
|
packageConfigs.push(createProductionConfig(format))
|
||||||
}
|
}
|
||||||
if (format === 'global' || format === 'esm') {
|
if (/global/.test(format) || format === 'esm') {
|
||||||
packageConfigs.push(createMinifiedConfig(format))
|
packageConfigs.push(createMinifiedConfig(format))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -73,7 +77,7 @@ function createConfig(format, output, plugins = []) {
|
|||||||
|
|
||||||
const isProductionBuild =
|
const isProductionBuild =
|
||||||
process.env.__DEV__ === 'false' || /\.prod\.js$/.test(output.file)
|
process.env.__DEV__ === 'false' || /\.prod\.js$/.test(output.file)
|
||||||
const isGlobalBuild = format === 'global'
|
const isGlobalBuild = /global/.test(format)
|
||||||
const isRawESMBuild = format === 'esm'
|
const isRawESMBuild = format === 'esm'
|
||||||
const isNodeBuild = format === 'cjs'
|
const isNodeBuild = format === 'cjs'
|
||||||
const isBundlerESMBuild = /esm-bundler/.test(format)
|
const isBundlerESMBuild = /esm-bundler/.test(format)
|
||||||
@ -102,8 +106,7 @@ function createConfig(format, output, plugins = []) {
|
|||||||
// during a single build.
|
// during a single build.
|
||||||
hasTSChecked = true
|
hasTSChecked = true
|
||||||
|
|
||||||
const entryFile =
|
const entryFile = /runtime$/.test(format) ? `src/runtime.ts` : `src/index.ts`
|
||||||
format === 'esm-bundler-runtime' ? `src/runtime.ts` : `src/index.ts`
|
|
||||||
|
|
||||||
const external =
|
const external =
|
||||||
isGlobalBuild || isRawESMBuild
|
isGlobalBuild || isRawESMBuild
|
||||||
@ -210,7 +213,7 @@ function createMinifiedConfig(format) {
|
|||||||
return createConfig(
|
return createConfig(
|
||||||
format,
|
format,
|
||||||
{
|
{
|
||||||
file: resolve(`dist/${name}.${format}.prod.js`),
|
file: outputConfigs[format].file.replace(/\.js$/, '.prod.js'),
|
||||||
format: outputConfigs[format].format
|
format: outputConfigs[format].format
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
|
@ -148,18 +148,23 @@ function checkAllSizes(targets) {
|
|||||||
|
|
||||||
function checkSize(target) {
|
function checkSize(target) {
|
||||||
const pkgDir = path.resolve(`packages/${target}`)
|
const pkgDir = path.resolve(`packages/${target}`)
|
||||||
const esmProdBuild = `${pkgDir}/dist/${target}.global.prod.js`
|
checkFileSize(`${pkgDir}/dist/${target}.global.prod.js`)
|
||||||
if (fs.existsSync(esmProdBuild)) {
|
checkFileSize(`${pkgDir}/dist/${target}.runtime.global.prod.js`)
|
||||||
const file = fs.readFileSync(esmProdBuild)
|
}
|
||||||
const minSize = (file.length / 1024).toFixed(2) + 'kb'
|
|
||||||
const gzipped = gzipSync(file)
|
function checkFileSize(filePath) {
|
||||||
const gzippedSize = (gzipped.length / 1024).toFixed(2) + 'kb'
|
if (!fs.existsSync(filePath)) {
|
||||||
const compressed = compress(file)
|
return
|
||||||
const compressedSize = (compressed.length / 1024).toFixed(2) + 'kb'
|
}
|
||||||
console.log(
|
const file = fs.readFileSync(filePath)
|
||||||
`${chalk.gray(
|
const minSize = (file.length / 1024).toFixed(2) + 'kb'
|
||||||
chalk.bold(target)
|
const gzipped = gzipSync(file)
|
||||||
)} min:${minSize} / gzip:${gzippedSize} / brotli:${compressedSize}`
|
const gzippedSize = (gzipped.length / 1024).toFixed(2) + 'kb'
|
||||||
)
|
const compressed = compress(file)
|
||||||
}
|
const compressedSize = (compressed.length / 1024).toFixed(2) + 'kb'
|
||||||
|
console.log(
|
||||||
|
`${chalk.gray(
|
||||||
|
chalk.bold(path.basename(filePath))
|
||||||
|
)} min:${minSize} / gzip:${gzippedSize} / brotli:${compressedSize}`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user