]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
build: adjust esm formats
authorEvan You <yyx990803@gmail.com>
Wed, 11 Dec 2019 03:14:02 +0000 (22:14 -0500)
committerEvan You <yyx990803@gmail.com>
Wed, 11 Dec 2019 03:14:02 +0000 (22:14 -0500)
.github/contributing.md
packages/compiler-core/package.json
packages/compiler-dom/package.json
packages/reactivity/package.json
packages/runtime-core/package.json
packages/runtime-dom/package.json
packages/runtime-test/package.json
packages/vue/package.json
rollup.config.js
scripts/build.js
scripts/release.js

index 865caf16ff23f4450f108601e38dc9bad4a18a36..930e1a21f298b3a59bb4ab1ab5f5903b33c7430a 100644 (file)
@@ -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:
 
 - **`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-browser`**: for in-browser usage via native ES modules import (`<script type="module">`)
+- **`esm-bundler`**: for use with bundlers like `webpack`, `rollup` and `parcel`.
+- **`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()`.
 
 For example, to build `runtime-core` with the global build only:
index b03163f444dcf8a698aa8eb1e76e8ec9de615999..4af472bb1d21ce7fed8177e06a3909bd458c99be 100644 (file)
@@ -11,6 +11,7 @@
   "types": "dist/compiler-core.d.ts",
   "buildOptions": {
     "formats": [
+      "esm-bundler",
       "cjs"
     ]
   },
index 74a55610e5ba8655f79621f00870e3951dddbb10..30d69ae7e55c2dfbf898daa742d909c5a6f230d1 100644 (file)
   "buildOptions": {
     "name": "VueDOMCompiler",
     "formats": [
+      "esm-bundler",
       "cjs",
       "global",
-      "esm-browser"
+      "esm"
     ]
   },
   "repository": {
index 02eca7259e17e0364ad7976d0a260eb8bf97c67b..9a6eec0a1dcbd69ebdbc6f1f1ebe1b2bea7c4b79 100644 (file)
   "buildOptions": {
     "name": "VueObserver",
     "formats": [
-      "esm",
+      "esm-bundler",
       "cjs",
       "global",
-      "esm-browser"
+      "esm"
     ]
   },
   "keywords": [
index 6c6677ebe72a311ab9bbfd87de974c1efbab7fda..deccfd3e0e2418f2d22f1f9a59066eeee4aa2e00 100644 (file)
@@ -9,6 +9,12 @@
     "dist"
   ],
   "types": "dist/runtime-core.d.ts",
+  "buildOptions": {
+    "formats": [
+      "esm-bundler",
+      "cjs"
+    ]
+  },
   "sideEffects": false,
   "repository": {
     "type": "git",
index 7c04028904476204d98f55532f000bfe07053cdc..6efbad1ce2f3db5f7eba7b0cd03efc249546105d 100644 (file)
   "buildOptions": {
     "name": "VueDOMRuntime",
     "formats": [
-      "esm",
+      "esm-bundler",
       "cjs",
       "global",
-      "esm-browser"
+      "esm"
     ],
     "dts": [
       "jsx.d.ts"
index 7deb989401b7e7a6f2454ff9317e635b9df3eb63..0a35d5ae12df2f26b4c28a369964453765940342 100644 (file)
@@ -2,6 +2,7 @@
   "name": "@vue/runtime-test",
   "version": "3.0.0-alpha.0",
   "description": "@vue/runtime-test",
+  "private": true,
   "main": "index.js",
   "module": "dist/runtime-test.esm-bundler.js",
   "files": [
@@ -16,8 +17,6 @@
   "buildOptions": {
     "name": "VueTestRuntime",
     "formats": [
-      "esm",
-      "cjs",
       "global"
     ]
   },
index 4929abbaeca3cbde610dbd2b717f80158024222b..a06ab849723df31eba0bdf67db60a6cac95b9beb 100644 (file)
   "buildOptions": {
     "name": "Vue",
     "formats": [
-      "esm",
+      "esm-bundler",
       "cjs",
       "global",
-      "esm-browser"
+      "esm"
     ]
   },
   "repository": {
index 8487504bfa0bd6484870fa8fb82c313b6b09f46f..b629f61d3ead8622ed6b3ec75504f907cc8b4b26 100644 (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,
index cced27660c7cbfb50ddaa64b9a6a40f751e4a127..985452423428cb9116ad890d217b676abaab5455 100644 (file)
@@ -27,7 +27,8 @@ const targets = args._
 const formats = args.formats || args.f
 const devOnly = args.devOnly || args.d
 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 lean = args.lean || args.l
 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 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 (!formats) {
     await fs.remove(`${pkgDir}/dist`)
index 14ddb901b7cde379d1a3e2f98cfe14102ea7b377..a8b9b7c86f96a57c865c6cedf19db800ace40c5b 100644 (file)
@@ -79,7 +79,7 @@ async function main() {
 
   // build all packages with types
   if (!skipBuild) {
-    await run('yarn', ['build', '-t'])
+    await run('yarn', ['build', '--release'])
     // test generated dts files
     await run(bin('tsd'))
   }