build: adjust esm formats

This commit is contained in:
Evan You
2019-12-10 22:14:02 -05:00
parent 8ed04ed503
commit 136ab753b3
11 changed files with 35 additions and 22 deletions

View File

@@ -24,7 +24,7 @@ const knownExternals = fs.readdirSync(packagesDir).filter(p => {
let hasTSChecked = false
const configs = {
esm: {
'esm-bundler': {
file: resolve(`dist/${name}.esm-bundler.js`),
format: `es`
},
@@ -36,13 +36,13 @@ const configs = {
file: resolve(`dist/${name}.global.js`),
format: `iife`
},
'esm-browser': {
file: resolve(`dist/${name}.esm-browser.js`),
esm: {
file: resolve(`dist/${name}.esm.js`),
format: `es`
}
}
const defaultFormats = ['esm', 'cjs']
const defaultFormats = ['esm-bundler', 'cjs']
const inlineFormats = process.env.FORMATS && process.env.FORMATS.split(',')
const packageFormats = inlineFormats || packageOptions.formats || defaultFormats
const packageConfigs = process.env.PROD_ONLY
@@ -54,7 +54,7 @@ if (process.env.NODE_ENV === 'production') {
if (format === 'cjs' && packageOptions.prod !== false) {
packageConfigs.push(createProductionConfig(format))
}
if (format === 'global' || format === 'esm-browser') {
if (format === 'global' || format === 'esm') {
packageConfigs.push(createMinifiedConfig(format))
}
})
@@ -69,7 +69,7 @@ function createConfig(output, plugins = []) {
process.env.__DEV__ === 'false' || /\.prod\.js$/.test(output.file)
const isGlobalBuild = /\.global(\.prod)?\.js$/.test(output.file)
const isBundlerESMBuild = /\.esm-bundler\.js$/.test(output.file)
const isBrowserESMBuild = /esm-browser(\.prod)?\.js$/.test(output.file)
const isRawESMBuild = /esm(\.prod)?\.js$/.test(output.file)
const isRuntimeCompileBuild = /vue\./.test(output.file)
if (isGlobalBuild) {
@@ -103,7 +103,7 @@ function createConfig(output, plugins = []) {
// Global and Browser ESM builds inlines everything so that they can be
// used alone.
external:
isGlobalBuild || isBrowserESMBuild
isGlobalBuild || isRawESMBuild
? []
: knownExternals.concat(Object.keys(pkg.dependencies || [])),
plugins: [
@@ -114,7 +114,7 @@ function createConfig(output, plugins = []) {
createReplacePlugin(
isProductionBuild,
isBundlerESMBuild,
(isGlobalBuild || isBrowserESMBuild) &&
(isGlobalBuild || isRawESMBuild) &&
!packageOptions.enableNonBrowserBranches,
isRuntimeCompileBuild
),
@@ -145,7 +145,7 @@ function createReplacePlugin(
!isProduction,
// this is only used during tests
__TEST__: isBundlerESMBuild ? `(process.env.NODE_ENV === 'test')` : false,
// If the build is expected to run directly in the browser (global / esm-browser builds)
// If the build is expected to run directly in the browser (global / esm builds)
__BROWSER__: isBrowserBuild,
// support compile in browser?
__RUNTIME_COMPILE__: isRuntimeCompileBuild,