From 5cf752378794cbe0ca4605749f5133ccee00ee25 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 17 Dec 2019 18:24:01 -0500 Subject: [PATCH] build: export runtime-only build for bundlers by default in main vue package --- packages/vue/package.json | 3 ++- packages/vue/src/devCheck.ts | 6 ++++++ packages/vue/src/index.ts | 9 ++------- packages/vue/src/runtime.ts | 6 ++++++ rollup.config.js | 29 +++++++++++++++++++---------- 5 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 packages/vue/src/devCheck.ts create mode 100644 packages/vue/src/runtime.ts diff --git a/packages/vue/package.json b/packages/vue/package.json index f17ccfd6..0b66f0a0 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -3,7 +3,7 @@ "version": "3.0.0-alpha.0", "description": "vue", "main": "index.js", - "module": "dist/vue.esm-bundler.js", + "module": "dist/vue.runtime.esm-bundler.js", "files": [ "index.js", "dist" @@ -14,6 +14,7 @@ "name": "Vue", "formats": [ "esm-bundler", + "esm-bundler-runtime", "cjs", "global", "esm" diff --git a/packages/vue/src/devCheck.ts b/packages/vue/src/devCheck.ts new file mode 100644 index 00000000..10bd99ff --- /dev/null +++ b/packages/vue/src/devCheck.ts @@ -0,0 +1,6 @@ +if (__BROWSER__ && __DEV__) { + console[console.info ? 'info' : 'log']( + `You are running a development build of Vue.\n` + + `Make sure to use the production build (*.prod.js) when deploying for production.` + ) +} diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts index e40ec89e..f79b7696 100644 --- a/packages/vue/src/index.ts +++ b/packages/vue/src/index.ts @@ -1,4 +1,4 @@ -// This package is the "full-build" that includes both the runtime +// This entry is the "full-build" that includes both the runtime // and the compiler, and supports on-the-fly compilation of the template option. import { compile, CompilerOptions, CompilerError } from '@vue/compiler-dom' import { registerRuntimeCompiler, RenderFunction, warn } from '@vue/runtime-dom' @@ -61,9 +61,4 @@ registerRuntimeCompiler(compileToFunction) export { compileToFunction as compile } export * from '@vue/runtime-dom' -if (__BROWSER__ && __DEV__) { - console[console.info ? 'info' : 'log']( - `You are running a development build of Vue.\n` + - `Make sure to use the production build (*.prod.js) when deploying for production.` - ) -} +import './devCheck' diff --git a/packages/vue/src/runtime.ts b/packages/vue/src/runtime.ts new file mode 100644 index 00000000..b6bbe504 --- /dev/null +++ b/packages/vue/src/runtime.ts @@ -0,0 +1,6 @@ +// This entry exports the runtime only, and is built as +// `dist/vue.esm-bundler.js` which is used by default for bundlers. + +export * from '@vue/runtime-dom' + +import './devCheck' diff --git a/rollup.config.js b/rollup.config.js index b2a66d14..75ec6ad5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -23,11 +23,16 @@ const knownExternals = fs.readdirSync(packagesDir).filter(p => { // ensure TS checks only once for each build let hasTSChecked = false -const configs = { +const outputConfigs = { 'esm-bundler': { file: resolve(`dist/${name}.esm-bundler.js`), format: `es` }, + // main "vue" package only + 'esm-bundler-runtime': { + file: resolve(`dist/${name}.runtime.esm-bundler.js`), + format: `es` + }, cjs: { file: resolve(`dist/${name}.cjs.js`), format: `cjs` @@ -47,7 +52,7 @@ const inlineFormats = process.env.FORMATS && process.env.FORMATS.split(',') const packageFormats = inlineFormats || packageOptions.formats || defaultFormats const packageConfigs = process.env.PROD_ONLY ? [] - : packageFormats.map(format => createConfig(configs[format])) + : packageFormats.map(format => createConfig(format, outputConfigs[format])) if (process.env.NODE_ENV === 'production') { packageFormats.forEach(format => { @@ -62,14 +67,14 @@ if (process.env.NODE_ENV === 'production') { export default packageConfigs -function createConfig(output, plugins = []) { +function createConfig(format, output, plugins = []) { output.externalLiveBindings = false const isProductionBuild = 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 isRawESMBuild = /esm(\.prod)?\.js$/.test(output.file) + const isGlobalBuild = format === 'global' + const isRawESMBuild = format === 'esm' + const isBundlerESMBuild = /esm-bundler/.test(format) const isRuntimeCompileBuild = /vue\./.test(output.file) if (isGlobalBuild) { @@ -98,8 +103,11 @@ function createConfig(output, plugins = []) { // during a single build. hasTSChecked = true + const entryFile = + format === 'esm-bundler-runtime' ? `src/runtime.ts` : `src/index.ts` + return { - input: resolve(`src/index.ts`), + input: resolve(entryFile), // Global and Browser ESM builds inlines everything so that they can be // used alone. external: @@ -167,18 +175,19 @@ function createReplacePlugin( } function createProductionConfig(format) { - return createConfig({ + return createConfig(format, { file: resolve(`dist/${name}.${format}.prod.js`), - format: configs[format].format + format: outputConfigs[format].format }) } function createMinifiedConfig(format) { const { terser } = require('rollup-plugin-terser') return createConfig( + format, { file: resolve(`dist/${name}.${format}.prod.js`), - format: configs[format].format + format: outputConfigs[format].format }, [ terser({