build: adjust esm formats
This commit is contained in:
parent
8ed04ed503
commit
136ab753b3
4
.github/contributing.md
vendored
4
.github/contributing.md
vendored
@ -71,8 +71,8 @@ yarn build runtime --all
|
|||||||
By default, each package will be built in multiple distribution formats as specified in the `buildOptions.formats` field in its `package.json`. These can be overwritten via the `-f` flag. The following formats are supported:
|
By default, each package will be built in multiple distribution formats as specified in the `buildOptions.formats` field in its `package.json`. These can be overwritten via the `-f` flag. The following formats are supported:
|
||||||
|
|
||||||
- **`global`**: for direct use via `<script>` in the browser. The global variable exposed is specified via the `buildOptions.name` field in a package's `package.json`.
|
- **`global`**: for direct use via `<script>` in the browser. The global variable exposed is specified via the `buildOptions.name` field in a package's `package.json`.
|
||||||
- **`esm`**: for use with bundlers.
|
- **`esm-bundler`**: for use with bundlers like `webpack`, `rollup` and `parcel`.
|
||||||
- **`esm-browser`**: for in-browser usage via native ES modules import (`<script type="module">`)
|
- **`esm`**: for usage via native ES modules imports (in browser via `<script type="module">`, or via Node.js native ES modules support in the future)
|
||||||
- **`cjs`**: for use in Node.js via `require()`.
|
- **`cjs`**: for use in Node.js via `require()`.
|
||||||
|
|
||||||
For example, to build `runtime-core` with the global build only:
|
For example, to build `runtime-core` with the global build only:
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
"types": "dist/compiler-core.d.ts",
|
"types": "dist/compiler-core.d.ts",
|
||||||
"buildOptions": {
|
"buildOptions": {
|
||||||
"formats": [
|
"formats": [
|
||||||
|
"esm-bundler",
|
||||||
"cjs"
|
"cjs"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -14,9 +14,10 @@
|
|||||||
"buildOptions": {
|
"buildOptions": {
|
||||||
"name": "VueDOMCompiler",
|
"name": "VueDOMCompiler",
|
||||||
"formats": [
|
"formats": [
|
||||||
|
"esm-bundler",
|
||||||
"cjs",
|
"cjs",
|
||||||
"global",
|
"global",
|
||||||
"esm-browser"
|
"esm"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -18,10 +18,10 @@
|
|||||||
"buildOptions": {
|
"buildOptions": {
|
||||||
"name": "VueObserver",
|
"name": "VueObserver",
|
||||||
"formats": [
|
"formats": [
|
||||||
"esm",
|
"esm-bundler",
|
||||||
"cjs",
|
"cjs",
|
||||||
"global",
|
"global",
|
||||||
"esm-browser"
|
"esm"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"types": "dist/runtime-core.d.ts",
|
"types": "dist/runtime-core.d.ts",
|
||||||
|
"buildOptions": {
|
||||||
|
"formats": [
|
||||||
|
"esm-bundler",
|
||||||
|
"cjs"
|
||||||
|
]
|
||||||
|
},
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -14,10 +14,10 @@
|
|||||||
"buildOptions": {
|
"buildOptions": {
|
||||||
"name": "VueDOMRuntime",
|
"name": "VueDOMRuntime",
|
||||||
"formats": [
|
"formats": [
|
||||||
"esm",
|
"esm-bundler",
|
||||||
"cjs",
|
"cjs",
|
||||||
"global",
|
"global",
|
||||||
"esm-browser"
|
"esm"
|
||||||
],
|
],
|
||||||
"dts": [
|
"dts": [
|
||||||
"jsx.d.ts"
|
"jsx.d.ts"
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
"name": "@vue/runtime-test",
|
"name": "@vue/runtime-test",
|
||||||
"version": "3.0.0-alpha.0",
|
"version": "3.0.0-alpha.0",
|
||||||
"description": "@vue/runtime-test",
|
"description": "@vue/runtime-test",
|
||||||
|
"private": true,
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"module": "dist/runtime-test.esm-bundler.js",
|
"module": "dist/runtime-test.esm-bundler.js",
|
||||||
"files": [
|
"files": [
|
||||||
@ -16,8 +17,6 @@
|
|||||||
"buildOptions": {
|
"buildOptions": {
|
||||||
"name": "VueTestRuntime",
|
"name": "VueTestRuntime",
|
||||||
"formats": [
|
"formats": [
|
||||||
"esm",
|
|
||||||
"cjs",
|
|
||||||
"global"
|
"global"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
"buildOptions": {
|
"buildOptions": {
|
||||||
"name": "Vue",
|
"name": "Vue",
|
||||||
"formats": [
|
"formats": [
|
||||||
"esm",
|
"esm-bundler",
|
||||||
"cjs",
|
"cjs",
|
||||||
"global",
|
"global",
|
||||||
"esm-browser"
|
"esm"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -24,7 +24,7 @@ const knownExternals = fs.readdirSync(packagesDir).filter(p => {
|
|||||||
let hasTSChecked = false
|
let hasTSChecked = false
|
||||||
|
|
||||||
const configs = {
|
const configs = {
|
||||||
esm: {
|
'esm-bundler': {
|
||||||
file: resolve(`dist/${name}.esm-bundler.js`),
|
file: resolve(`dist/${name}.esm-bundler.js`),
|
||||||
format: `es`
|
format: `es`
|
||||||
},
|
},
|
||||||
@ -36,13 +36,13 @@ const configs = {
|
|||||||
file: resolve(`dist/${name}.global.js`),
|
file: resolve(`dist/${name}.global.js`),
|
||||||
format: `iife`
|
format: `iife`
|
||||||
},
|
},
|
||||||
'esm-browser': {
|
esm: {
|
||||||
file: resolve(`dist/${name}.esm-browser.js`),
|
file: resolve(`dist/${name}.esm.js`),
|
||||||
format: `es`
|
format: `es`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultFormats = ['esm', 'cjs']
|
const defaultFormats = ['esm-bundler', 'cjs']
|
||||||
const inlineFormats = process.env.FORMATS && process.env.FORMATS.split(',')
|
const inlineFormats = process.env.FORMATS && process.env.FORMATS.split(',')
|
||||||
const packageFormats = inlineFormats || packageOptions.formats || defaultFormats
|
const packageFormats = inlineFormats || packageOptions.formats || defaultFormats
|
||||||
const packageConfigs = process.env.PROD_ONLY
|
const packageConfigs = process.env.PROD_ONLY
|
||||||
@ -54,7 +54,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-browser') {
|
if (format === 'global' || format === 'esm') {
|
||||||
packageConfigs.push(createMinifiedConfig(format))
|
packageConfigs.push(createMinifiedConfig(format))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -69,7 +69,7 @@ function createConfig(output, plugins = []) {
|
|||||||
process.env.__DEV__ === 'false' || /\.prod\.js$/.test(output.file)
|
process.env.__DEV__ === 'false' || /\.prod\.js$/.test(output.file)
|
||||||
const isGlobalBuild = /\.global(\.prod)?\.js$/.test(output.file)
|
const isGlobalBuild = /\.global(\.prod)?\.js$/.test(output.file)
|
||||||
const isBundlerESMBuild = /\.esm-bundler\.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)
|
const isRuntimeCompileBuild = /vue\./.test(output.file)
|
||||||
|
|
||||||
if (isGlobalBuild) {
|
if (isGlobalBuild) {
|
||||||
@ -103,7 +103,7 @@ function createConfig(output, plugins = []) {
|
|||||||
// Global and Browser ESM builds inlines everything so that they can be
|
// Global and Browser ESM builds inlines everything so that they can be
|
||||||
// used alone.
|
// used alone.
|
||||||
external:
|
external:
|
||||||
isGlobalBuild || isBrowserESMBuild
|
isGlobalBuild || isRawESMBuild
|
||||||
? []
|
? []
|
||||||
: knownExternals.concat(Object.keys(pkg.dependencies || [])),
|
: knownExternals.concat(Object.keys(pkg.dependencies || [])),
|
||||||
plugins: [
|
plugins: [
|
||||||
@ -114,7 +114,7 @@ function createConfig(output, plugins = []) {
|
|||||||
createReplacePlugin(
|
createReplacePlugin(
|
||||||
isProductionBuild,
|
isProductionBuild,
|
||||||
isBundlerESMBuild,
|
isBundlerESMBuild,
|
||||||
(isGlobalBuild || isBrowserESMBuild) &&
|
(isGlobalBuild || isRawESMBuild) &&
|
||||||
!packageOptions.enableNonBrowserBranches,
|
!packageOptions.enableNonBrowserBranches,
|
||||||
isRuntimeCompileBuild
|
isRuntimeCompileBuild
|
||||||
),
|
),
|
||||||
@ -145,7 +145,7 @@ function createReplacePlugin(
|
|||||||
!isProduction,
|
!isProduction,
|
||||||
// this is only used during tests
|
// this is only used during tests
|
||||||
__TEST__: isBundlerESMBuild ? `(process.env.NODE_ENV === 'test')` : false,
|
__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,
|
__BROWSER__: isBrowserBuild,
|
||||||
// support compile in browser?
|
// support compile in browser?
|
||||||
__RUNTIME_COMPILE__: isRuntimeCompileBuild,
|
__RUNTIME_COMPILE__: isRuntimeCompileBuild,
|
||||||
|
@ -27,7 +27,8 @@ const targets = args._
|
|||||||
const formats = args.formats || args.f
|
const formats = args.formats || args.f
|
||||||
const devOnly = args.devOnly || args.d
|
const devOnly = args.devOnly || args.d
|
||||||
const prodOnly = !devOnly && (args.prodOnly || args.p)
|
const prodOnly = !devOnly && (args.prodOnly || args.p)
|
||||||
const buildTypes = args.t || args.types
|
const isRelease = args.release
|
||||||
|
const buildTypes = args.t || args.types || isRelease
|
||||||
const buildAllMatching = args.all || args.a
|
const buildAllMatching = args.all || args.a
|
||||||
const lean = args.lean || args.l
|
const lean = args.lean || args.l
|
||||||
const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
|
const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
|
||||||
@ -54,6 +55,11 @@ async function build(target) {
|
|||||||
const pkgDir = path.resolve(`packages/${target}`)
|
const pkgDir = path.resolve(`packages/${target}`)
|
||||||
const pkg = require(`${pkgDir}/package.json`)
|
const pkg = require(`${pkgDir}/package.json`)
|
||||||
|
|
||||||
|
// only build published packages for release
|
||||||
|
if (isRelease && pkg.private) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// if building a specific format, do not remove dist.
|
// if building a specific format, do not remove dist.
|
||||||
if (!formats) {
|
if (!formats) {
|
||||||
await fs.remove(`${pkgDir}/dist`)
|
await fs.remove(`${pkgDir}/dist`)
|
||||||
|
@ -79,7 +79,7 @@ async function main() {
|
|||||||
|
|
||||||
// build all packages with types
|
// build all packages with types
|
||||||
if (!skipBuild) {
|
if (!skipBuild) {
|
||||||
await run('yarn', ['build', '-t'])
|
await run('yarn', ['build', '--release'])
|
||||||
// test generated dts files
|
// test generated dts files
|
||||||
await run(bin('tsd'))
|
await run(bin('tsd'))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user