workflow: rename umd build to global

This commit is contained in:
Evan You 2018-09-19 12:46:55 -04:00
parent d1bc6ee8d6
commit 73106b8553
5 changed files with 28 additions and 28 deletions

View File

@ -1,3 +1,3 @@
# @vue/observer # @vue/observer
> This package is inlined into UMD & Browser ESM builds of user-facing renderers (e.g. `@vue/renderer-dom`), but also published as a package that can be used standalone. The standalone build should not be used alongside a pre-bundled build of a user-facing renderer, as they will have different internal storage for reactivity connections. A user-facing renderer should re-export all APIs from this package. > This package is inlined into Global & Browser ESM builds of user-facing renderers (e.g. `@vue/renderer-dom`), but also published as a package that can be used standalone. The standalone build should not be used alongside a pre-bundled build of a user-facing renderer, as they will have different internal storage for reactivity connections. A user-facing renderer should re-export all APIs from this package.

View File

@ -5,14 +5,14 @@
"main": "index.js", "main": "index.js",
"module": "dist/observer.esm.js", "module": "dist/observer.esm.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"unpkg": "dist/observer.umd.js", "unpkg": "dist/observer.global.js",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/vuejs/vue.git" "url": "git+https://github.com/vuejs/vue.git"
}, },
"buildOptions": { "buildOptions": {
"name": "VueObserver", "name": "VueObserver",
"formats": ["esm", "cjs", "umd", "esm-browser"] "formats": ["esm", "cjs", "global", "esm-browser"]
}, },
"keywords": [ "keywords": [
"vue" "vue"

View File

@ -5,10 +5,10 @@
"main": "index.js", "main": "index.js",
"module": "dist/renderer-dom.esm.js", "module": "dist/renderer-dom.esm.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"unpkg": "dist/renderer-dom.umd.js", "unpkg": "dist/renderer-dom.global.js",
"buildOptions": { "buildOptions": {
"name": "Vue", "name": "VueDOMRenderer",
"formats": ["esm", "cjs", "umd", "esm-browser"] "formats": ["esm", "cjs", "global", "esm-browser"]
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -29,16 +29,16 @@ let hasTSChecked = false
const configs = { const configs = {
esm: { esm: {
file: resolve(`dist/${name}.esm.js`), file: resolve(`dist/${name}.esm-bundler.js`),
format: `es` format: `es`
}, },
cjs: { cjs: {
file: resolve(`dist/${name}.cjs.js`), file: resolve(`dist/${name}.cjs.js`),
format: `cjs` format: `cjs`
}, },
umd: { global: {
file: resolve(`dist/${name}.umd.js`), file: resolve(`dist/${name}.global.js`),
format: `umd` format: `iife`
}, },
'esm-browser': { 'esm-browser': {
file: resolve(`dist/${name}.esm-browser.js`), file: resolve(`dist/${name}.esm-browser.js`),
@ -49,14 +49,16 @@ const configs = {
const defaultFormats = ['esm', 'cjs'] const defaultFormats = ['esm', 'cjs']
const inlineFromats = process.env.FORMATS && process.env.FORMATS.split(',') const inlineFromats = process.env.FORMATS && process.env.FORMATS.split(',')
const packageFormats = inlineFromats || packageOptions.formats || defaultFormats const packageFormats = inlineFromats || packageOptions.formats || defaultFormats
const packageConfigs = packageFormats.map(format => createConfig(configs[format])) const packageConfigs = packageFormats.map(format =>
createConfig(configs[format])
)
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
packageFormats.forEach(format => { packageFormats.forEach(format => {
if (format === 'cjs') { if (format === 'cjs') {
packageConfigs.push(createProductionConfig(format)) packageConfigs.push(createProductionConfig(format))
} }
if (format === 'umd' || format === 'esm-browser') { if (format === 'global' || format === 'esm-browser') {
packageConfigs.push(createMinifiedConfig(format)) packageConfigs.push(createMinifiedConfig(format))
} }
}) })
@ -66,11 +68,11 @@ module.exports = packageConfigs
function createConfig(output, plugins = []) { function createConfig(output, plugins = []) {
const isProductionBuild = /\.prod\.js$/.test(output.file) const isProductionBuild = /\.prod\.js$/.test(output.file)
const isUMDBuild = /\.umd(\.prod)?\.js$/.test(output.file) const isGlobalBuild = /\.global(\.prod)?\.js$/.test(output.file)
const isBunlderESMBuild = /\.esm\.js$/.test(output.file) const isBunlderESMBuild = /\.esm\.js$/.test(output.file)
const isBrowserESMBuild = /esm-browser(\.prod)?\.js$/.test(output.file) const isBrowserESMBuild = /esm-browser(\.prod)?\.js$/.test(output.file)
if (isUMDBuild) { if (isGlobalBuild) {
output.name = packageOptions.name output.name = packageOptions.name
} }
@ -91,11 +93,10 @@ function createConfig(output, plugins = []) {
return { return {
input: resolve(`src/index.ts`), input: resolve(`src/index.ts`),
// UMD 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: isUMDBuild || isBrowserESMBuild external:
? [] isGlobalBuild || isBrowserESMBuild ? [] : Object.keys(aliasOptions),
: Object.keys(aliasOptions),
plugins: [ plugins: [
tsPlugin, tsPlugin,
aliasPlugin, aliasPlugin,
@ -114,10 +115,10 @@ function createConfig(output, plugins = []) {
function createReplacePlugin(isProduction, isBunlderESMBuild) { function createReplacePlugin(isProduction, isBunlderESMBuild) {
return replace({ return replace({
__DEV__: isBunlderESMBuild __DEV__: isBunlderESMBuild
// preserve to be handled by bundlers ? // preserve to be handled by bundlers
? `process.env.NODE_ENV !== 'production'` `process.env.NODE_ENV !== 'production'`
// hard coded dev/prod builds : // hard coded dev/prod builds
: !isProduction, !isProduction,
// compatibility builds // compatibility builds
__COMPAT__: !!process.env.COMPAT __COMPAT__: !!process.env.COMPAT
}) })
@ -126,21 +127,20 @@ function createReplacePlugin(isProduction, isBunlderESMBuild) {
function createProductionConfig(format) { function createProductionConfig(format) {
return createConfig({ return createConfig({
file: resolve(`dist/${name}.${format}.prod.js`), file: resolve(`dist/${name}.${format}.prod.js`),
format: /^esm/.test(format) ? 'es' : format format: configs[format].format
}) })
} }
function createMinifiedConfig(format) { function createMinifiedConfig(format) {
const { terser } = require('rollup-plugin-terser') const { terser } = require('rollup-plugin-terser')
const isESM = /^esm/.test(format)
return createConfig( return createConfig(
{ {
file: resolve(`dist/${name}.${format}.prod.js`), file: resolve(`dist/${name}.${format}.prod.js`),
format: isESM ? 'es' : format format: configs[format].format
}, },
[ [
terser({ terser({
module: isESM module: /^esm/.test(format)
}) })
] ]
) )

View File

@ -2,7 +2,7 @@
Run Rollup in watch mode for development. Run Rollup in watch mode for development.
To specific the package to watch, simply pass its name and the desired build To specific the package to watch, simply pass its name and the desired build
formats to watch (defaults to "umd"): formats to watch (defaults to "global"):
``` ```
# name supports fuzzy match. will watch all packages with name containing "dom" # name supports fuzzy match. will watch all packages with name containing "dom"
@ -22,7 +22,7 @@ const formats = args.formats || args.f
execa( execa(
'rollup', 'rollup',
['-wc', '--environment', `TARGET:${target},FORMATS:${formats || 'umd'}`], ['-wc', '--environment', `TARGET:${target},FORMATS:${formats || 'global'}`],
{ {
stdio: 'inherit' stdio: 'inherit'
} }