From 92fcb9db0599ae633ae5ff829353612113749996 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 14 Jan 2022 16:21:50 +0800 Subject: [PATCH] workflow: use esbuild for dev scripts --- .github/contributing.md | 9 +- package.json | 8 +- packages/template-explorer/src/index.ts | 4 +- pnpm-lock.yaml | 203 +++++++++++++++++++++++- scripts/dev.js | 137 +++++++++++----- 5 files changed, 314 insertions(+), 47 deletions(-) diff --git a/.github/contributing.md b/.github/contributing.md index 5c50f8a9670..2b0995a1ef1 100644 --- a/.github/contributing.md +++ b/.github/contributing.md @@ -123,16 +123,19 @@ The `dev` script bundles a target package (default: `vue`) in a specified format ```bash $ nr dev -> rollup v1.19.4 -> bundles packages/vue/src/index.ts → packages/vue/dist/vue.global.js... +> watching: packages/vue/dist/vue.global.js ``` -- The `dev` script also supports fuzzy match for the target package, but will only match the first package matched. +- **Important:** output of the `dev` script is for development and debugging only. While it has the same runtime behavior, the generated code should never be published to npm. + +- The `dev` script does not support fuzzy match - you must specify the full package name, e.g. `nr dev runtime-core`. - The `dev` script supports specifying build format via the `-f` flag just like the `build` script. - The `dev` script also supports the `-s` flag for generating source maps, but it will make rebuilds slower. +- The `dev` script supports the `-i` flag for inlining all deps. This is useful when debugging `esm-bundler` builds which externalizes deps by default. + ### `nr dev-compiler` The `dev-compiler` script builds, watches and serves the [Template Explorer](https://github.com/vuejs/vue-next/tree/master/packages/template-explorer) at `http://localhost:5000`. This is extremely useful when working on the compiler. diff --git a/package.json b/package.json index 5bfd59dc1a8..30762ca3f52 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "release": "node scripts/release.js", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "dev-compiler": "run-p \"dev template-explorer\" serve", - "dev-sfc": "run-p \"dev compiler-sfc -- -f esm-browser\" \"dev runtime-core -- -f esm-bundler\" \"dev runtime-dom -- -f esm-bundler\" serve-sfc-playground", + "dev-sfc": "run-p \"dev compiler-sfc -- -f esm-browser\" \"dev vue -- -if esm-bundler-runtime \" serve-sfc-playground", "serve-sfc-playground": "vite packages/sfc-playground --host", "serve": "serve", "open": "open http://localhost:5000/packages/template-explorer/local.html", @@ -48,6 +48,7 @@ }, "devDependencies": { "@babel/types": "^7.12.0", + "@esbuild-plugins/node-modules-polyfill": "^0.1.4", "@microsoft/api-extractor": "^7.15.1", "@rollup/plugin-commonjs": "^18.0.0", "@rollup/plugin-json": "^4.0.0", @@ -66,6 +67,7 @@ "conventional-changelog-cli": "^2.0.31", "csstype": "^3.0.3", "enquirer": "^2.3.2", + "esbuild": "^0.14.11", "eslint": "^7.7.0", "execa": "^4.0.2", "fs-extra": "^9.0.1", @@ -86,11 +88,11 @@ "semver": "^7.3.2", "serve": "^12.0.0", "todomvc-app-css": "^2.3.0", - "tslib": "^2.3.1", "ts-jest": "^27.0.5", + "tslib": "^2.3.1", "typescript": "^4.2.2", - "vue": "workspace:*", "vite": "^2.7.1", + "vue": "workspace:*", "yorkie": "^2.0.0" } } diff --git a/packages/template-explorer/src/index.ts b/packages/template-explorer/src/index.ts index 7b7e2ae273a..d676c717373 100644 --- a/packages/template-explorer/src/index.ts +++ b/packages/template-explorer/src/index.ts @@ -62,7 +62,7 @@ window.init = () => { if (persistedState) { // functions are not persistable, so delete it in case we sometimes need // to debug with custom nodeTransforms - delete persistedState.options.nodeTransforms + delete persistedState.options?.nodeTransforms ssrMode.value = persistedState.ssr Object.assign(compilerOptions, persistedState.options) } @@ -142,7 +142,7 @@ window.init = () => { } const editor = monaco.editor.create(document.getElementById('source')!, { - value: persistedState?.src || `
Hello World!
`, + value: persistedState?.src || `
Hello World
`, language: 'html', ...sharedEditorOptions, wordWrap: 'bounded' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5a068cfbc6d..4237878a534 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,7 @@ importers: .: specifiers: '@babel/types': ^7.12.0 + '@esbuild-plugins/node-modules-polyfill': ^0.1.4 '@microsoft/api-extractor': ^7.15.1 '@rollup/plugin-commonjs': ^18.0.0 '@rollup/plugin-json': ^4.0.0 @@ -23,6 +24,7 @@ importers: conventional-changelog-cli: ^2.0.31 csstype: ^3.0.3 enquirer: ^2.3.2 + esbuild: ^0.14.11 eslint: ^7.7.0 execa: ^4.0.2 fs-extra: ^9.0.1 @@ -51,6 +53,7 @@ importers: yorkie: ^2.0.0 devDependencies: '@babel/types': 7.16.0 + '@esbuild-plugins/node-modules-polyfill': 0.1.4_esbuild@0.14.11 '@microsoft/api-extractor': 7.19.2 '@rollup/plugin-commonjs': 18.1.0_rollup@2.38.5 '@rollup/plugin-json': 4.1.0_rollup@2.38.5 @@ -69,6 +72,7 @@ importers: conventional-changelog-cli: 2.1.1 csstype: 3.0.10 enquirer: 2.3.6 + esbuild: 0.14.11 eslint: 7.32.0 execa: 4.1.0 fs-extra: 9.1.0 @@ -89,7 +93,7 @@ importers: semver: 7.3.5 serve: 12.0.1 todomvc-app-css: 2.4.1 - ts-jest: 27.1.1_dc33159234d58f1c7ac35b6119da0e94 + ts-jest: 27.1.1_305b6a4a69ca4f1a88855b62d81fc1b0 tslib: 2.3.1 typescript: 4.5.3 vite: 2.7.1 @@ -629,6 +633,16 @@ packages: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true + /@esbuild-plugins/node-modules-polyfill/0.1.4_esbuild@0.14.11: + resolution: {integrity: sha512-uZbcXi0zbmKC/050p3gJnne5Qdzw8vkXIv+c2BW0Lsc1ji1SkrxbKPUy5Efr0blbTu1SL8w4eyfpnSdPg3G0Qg==} + peerDependencies: + esbuild: '*' + dependencies: + esbuild: 0.14.11 + escape-string-regexp: 4.0.0 + rollup-plugin-node-polyfills: 0.2.1 + dev: true + /@eslint/eslintrc/0.4.3: resolution: {integrity: sha512-J6KFFz5QCYUJq3pf0mjEcCJVERbzv71PUIDczuh9JkwGEzced6CO5ADLHB1rbf/+oPBtoPfMYNOpGDzCANlbXw==} engines: {node: ^10.12.0 || >=12.0.0} @@ -2584,6 +2598,14 @@ packages: dev: true optional: true + /esbuild-android-arm64/0.14.11: + resolution: {integrity: sha512-6iHjgvMnC/SzDH8TefL+/3lgCjYWwAd1LixYfmz/TBPbDQlxcuSkX0yiQgcJB9k+ibZ54yjVXziIwGdlc+6WNw==} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + /esbuild-darwin-64/0.13.15: resolution: {integrity: sha512-ihOQRGs2yyp7t5bArCwnvn2Atr6X4axqPpEdCFPVp7iUj4cVSdisgvEKdNR7yH3JDjW6aQDw40iQFoTqejqxvQ==} cpu: [x64] @@ -2592,6 +2614,14 @@ packages: dev: true optional: true + /esbuild-darwin-64/0.14.11: + resolution: {integrity: sha512-olq84ikh6TiBcrs3FnM4eR5VPPlcJcdW8BnUz/lNoEWYifYQ+Po5DuYV1oz1CTFMw4k6bQIZl8T3yxL+ZT2uvQ==} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /esbuild-darwin-arm64/0.13.15: resolution: {integrity: sha512-i1FZssTVxUqNlJ6cBTj5YQj4imWy3m49RZRnHhLpefFIh0To05ow9DTrXROTE1urGTQCloFUXTX8QfGJy1P8dQ==} cpu: [arm64] @@ -2600,6 +2630,14 @@ packages: dev: true optional: true + /esbuild-darwin-arm64/0.14.11: + resolution: {integrity: sha512-Jj0ieWLREPBYr/TZJrb2GFH8PVzDqiQWavo1pOFFShrcmHWDBDrlDxPzEZ67NF/Un3t6sNNmeI1TUS/fe1xARg==} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /esbuild-freebsd-64/0.13.15: resolution: {integrity: sha512-G3dLBXUI6lC6Z09/x+WtXBXbOYQZ0E8TDBqvn7aMaOCzryJs8LyVXKY4CPnHFXZAbSwkCbqiPuSQ1+HhrNk7EA==} cpu: [x64] @@ -2608,6 +2646,14 @@ packages: dev: true optional: true + /esbuild-freebsd-64/0.14.11: + resolution: {integrity: sha512-C5sT3/XIztxxz/zwDjPRHyzj/NJFOnakAanXuyfLDwhwupKPd76/PPHHyJx6Po6NI6PomgVp/zi6GRB8PfrOTA==} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /esbuild-freebsd-arm64/0.13.15: resolution: {integrity: sha512-KJx0fzEDf1uhNOZQStV4ujg30WlnwqUASaGSFPhznLM/bbheu9HhqZ6mJJZM32lkyfGJikw0jg7v3S0oAvtvQQ==} cpu: [arm64] @@ -2616,6 +2662,14 @@ packages: dev: true optional: true + /esbuild-freebsd-arm64/0.14.11: + resolution: {integrity: sha512-y3Llu4wbs0bk4cwjsdAtVOesXb6JkdfZDLKMt+v1U3tOEPBdSu6w8796VTksJgPfqvpX22JmPLClls0h5p+L9w==} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-32/0.13.15: resolution: {integrity: sha512-ZvTBPk0YWCLMCXiFmD5EUtB30zIPvC5Itxz0mdTu/xZBbbHJftQgLWY49wEPSn2T/TxahYCRDWun5smRa0Tu+g==} cpu: [ia32] @@ -2624,6 +2678,14 @@ packages: dev: true optional: true + /esbuild-linux-32/0.14.11: + resolution: {integrity: sha512-Cg3nVsxArjyLke9EuwictFF3Sva+UlDTwHIuIyx8qpxRYAOUTmxr2LzYrhHyTcGOleLGXUXYsnUVwKqnKAgkcg==} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-64/0.13.15: resolution: {integrity: sha512-eCKzkNSLywNeQTRBxJRQ0jxRCl2YWdMB3+PkWFo2BBQYC5mISLIVIjThNtn6HUNqua1pnvgP5xX0nHbZbPj5oA==} cpu: [x64] @@ -2632,6 +2694,14 @@ packages: dev: true optional: true + /esbuild-linux-64/0.14.11: + resolution: {integrity: sha512-oeR6dIrrojr8DKVrxtH3xl4eencmjsgI6kPkDCRIIFwv4p+K7ySviM85K66BN01oLjzthpUMvBVfWSJkBLeRbg==} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-arm/0.13.15: resolution: {integrity: sha512-wUHttDi/ol0tD8ZgUMDH8Ef7IbDX+/UsWJOXaAyTdkT7Yy9ZBqPg8bgB/Dn3CZ9SBpNieozrPRHm0BGww7W/jA==} cpu: [arm] @@ -2640,6 +2710,14 @@ packages: dev: true optional: true + /esbuild-linux-arm/0.14.11: + resolution: {integrity: sha512-vcwskfD9g0tojux/ZaTJptJQU3a7YgTYsptK1y6LQ/rJmw7U5QJvboNawqM98Ca3ToYEucfCRGbl66OTNtp6KQ==} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-arm64/0.13.15: resolution: {integrity: sha512-bYpuUlN6qYU9slzr/ltyLTR9YTBS7qUDymO8SV7kjeNext61OdmqFAzuVZom+OLW1HPHseBfJ/JfdSlx8oTUoA==} cpu: [arm64] @@ -2648,6 +2726,14 @@ packages: dev: true optional: true + /esbuild-linux-arm64/0.14.11: + resolution: {integrity: sha512-+e6ZCgTFQYZlmg2OqLkg1jHLYtkNDksxWDBWNtI4XG4WxuOCUErLqfEt9qWjvzK3XBcCzHImrajkUjO+rRkbMg==} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-mips64le/0.13.15: resolution: {integrity: sha512-KlVjIG828uFPyJkO/8gKwy9RbXhCEUeFsCGOJBepUlpa7G8/SeZgncUEz/tOOUJTcWMTmFMtdd3GElGyAtbSWg==} cpu: [mips64el] @@ -2656,6 +2742,14 @@ packages: dev: true optional: true + /esbuild-linux-mips64le/0.14.11: + resolution: {integrity: sha512-Rrs99L+p54vepmXIb87xTG6ukrQv+CzrM8eoeR+r/OFL2Rg8RlyEtCeshXJ2+Q66MXZOgPJaokXJZb9snq28bw==} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-ppc64le/0.13.15: resolution: {integrity: sha512-h6gYF+OsaqEuBjeesTBtUPw0bmiDu7eAeuc2OEH9S6mV9/jPhPdhOWzdeshb0BskRZxPhxPOjqZ+/OqLcxQwEQ==} cpu: [ppc64] @@ -2664,6 +2758,22 @@ packages: dev: true optional: true + /esbuild-linux-ppc64le/0.14.11: + resolution: {integrity: sha512-JyzziGAI0D30Vyzt0HDihp4s1IUtJ3ssV2zx9O/c+U/dhUHVP2TmlYjzCfCr2Q6mwXTeloDcLS4qkyvJtYptdQ==} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-s390x/0.14.11: + resolution: {integrity: sha512-DoThrkzunZ1nfRGoDN6REwmo8ZZWHd2ztniPVIR5RMw/Il9wiWEYBahb8jnMzQaSOxBsGp0PbyJeVLTUatnlcw==} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-netbsd-64/0.13.15: resolution: {integrity: sha512-3+yE9emwoevLMyvu+iR3rsa+Xwhie7ZEHMGDQ6dkqP/ndFzRHkobHUKTe+NCApSqG5ce2z4rFu+NX/UHnxlh3w==} cpu: [x64] @@ -2672,6 +2782,14 @@ packages: dev: true optional: true + /esbuild-netbsd-64/0.14.11: + resolution: {integrity: sha512-12luoRQz+6eihKYh1zjrw0CBa2aw3twIiHV/FAfjh2NEBDgJQOY4WCEUEN+Rgon7xmLh4XUxCQjnwrvf8zhACw==} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + /esbuild-openbsd-64/0.13.15: resolution: {integrity: sha512-wTfvtwYJYAFL1fSs8yHIdf5GEE4NkbtbXtjLWjM3Cw8mmQKqsg8kTiqJ9NJQe5NX/5Qlo7Xd9r1yKMMkHllp5g==} cpu: [x64] @@ -2680,6 +2798,14 @@ packages: dev: true optional: true + /esbuild-openbsd-64/0.14.11: + resolution: {integrity: sha512-l18TZDjmvwW6cDeR4fmizNoxndyDHamGOOAenwI4SOJbzlJmwfr0jUgjbaXCUuYVOA964siw+Ix+A+bhALWg8Q==} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + /esbuild-sunos-64/0.13.15: resolution: {integrity: sha512-lbivT9Bx3t1iWWrSnGyBP9ODriEvWDRiweAs69vI+miJoeKwHWOComSRukttbuzjZ8r1q0mQJ8Z7yUsDJ3hKdw==} cpu: [x64] @@ -2688,6 +2814,14 @@ packages: dev: true optional: true + /esbuild-sunos-64/0.14.11: + resolution: {integrity: sha512-bmYzDtwASBB8c+0/HVOAiE9diR7+8zLm/i3kEojUH2z0aIs6x/S4KiTuT5/0VKJ4zk69kXel1cNWlHBMkmavQg==} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + /esbuild-windows-32/0.13.15: resolution: {integrity: sha512-fDMEf2g3SsJ599MBr50cY5ve5lP1wyVwTe6aLJsM01KtxyKkB4UT+fc5MXQFn3RLrAIAZOG+tHC+yXObpSn7Nw==} cpu: [ia32] @@ -2696,6 +2830,14 @@ packages: dev: true optional: true + /esbuild-windows-32/0.14.11: + resolution: {integrity: sha512-J1Ys5hMid8QgdY00OBvIolXgCQn1ARhYtxPnG6ESWNTty3ashtc4+As5nTrsErnv8ZGUcWZe4WzTP/DmEVX1UQ==} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild-windows-64/0.13.15: resolution: {integrity: sha512-9aMsPRGDWCd3bGjUIKG/ZOJPKsiztlxl/Q3C1XDswO6eNX/Jtwu4M+jb6YDH9hRSUflQWX0XKAfWzgy5Wk54JQ==} cpu: [x64] @@ -2704,6 +2846,14 @@ packages: dev: true optional: true + /esbuild-windows-64/0.14.11: + resolution: {integrity: sha512-h9FmMskMuGeN/9G9+LlHPAoiQk9jlKDUn9yA0MpiGzwLa82E7r1b1u+h2a+InprbSnSLxDq/7p5YGtYVO85Mlg==} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild-windows-arm64/0.13.15: resolution: {integrity: sha512-zzvyCVVpbwQQATaf3IG8mu1IwGEiDxKkYUdA4FpoCHi1KtPa13jeScYDjlW0Qh+ebWzpKfR2ZwvqAQkSWNcKjA==} cpu: [arm64] @@ -2712,6 +2862,14 @@ packages: dev: true optional: true + /esbuild-windows-arm64/0.14.11: + resolution: {integrity: sha512-dZp7Krv13KpwKklt9/1vBFBMqxEQIO6ri7Azf8C+ob4zOegpJmha2XY9VVWP/OyQ0OWk6cEeIzMJwInRZrzBUQ==} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild/0.13.15: resolution: {integrity: sha512-raCxt02HBKv8RJxE8vkTSCXGIyKHdEdGfUmiYb8wnabnaEmHzyW7DCHb5tEN0xU8ryqg5xw54mcwnYkC4x3AIw==} hasBin: true @@ -2736,6 +2894,31 @@ packages: esbuild-windows-arm64: 0.13.15 dev: true + /esbuild/0.14.11: + resolution: {integrity: sha512-xZvPtVj6yecnDeFb3KjjCM6i7B5TCAQZT77kkW/CpXTMnd6VLnRPKrUB1XHI1pSq6a4Zcy3BGueQ8VljqjDGCg==} + hasBin: true + requiresBuild: true + optionalDependencies: + esbuild-android-arm64: 0.14.11 + esbuild-darwin-64: 0.14.11 + esbuild-darwin-arm64: 0.14.11 + esbuild-freebsd-64: 0.14.11 + esbuild-freebsd-arm64: 0.14.11 + esbuild-linux-32: 0.14.11 + esbuild-linux-64: 0.14.11 + esbuild-linux-arm: 0.14.11 + esbuild-linux-arm64: 0.14.11 + esbuild-linux-mips64le: 0.14.11 + esbuild-linux-ppc64le: 0.14.11 + esbuild-linux-s390x: 0.14.11 + esbuild-netbsd-64: 0.14.11 + esbuild-openbsd-64: 0.14.11 + esbuild-sunos-64: 0.14.11 + esbuild-windows-32: 0.14.11 + esbuild-windows-64: 0.14.11 + esbuild-windows-arm64: 0.14.11 + dev: true + /escalade/3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} engines: {node: '>=6'} @@ -5859,6 +6042,15 @@ packages: inherits: 2.0.4 dev: true + /rollup-plugin-inject/3.0.2: + resolution: {integrity: sha512-ptg9PQwzs3orn4jkgXJ74bfs5vYz1NCZlSQMBUA0wKcGp5i5pA1AO3fOUEte8enhGUC+iapTCzEWw2jEFFUO/w==} + deprecated: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject. + dependencies: + estree-walker: 0.6.1 + magic-string: 0.25.7 + rollup-pluginutils: 2.8.2 + dev: true + /rollup-plugin-node-builtins/2.1.2: resolution: {integrity: sha1-JKH+1KQyV7a2Q3HYq8bOGrFFl+k=} dependencies: @@ -5879,6 +6071,12 @@ packages: rollup-pluginutils: 2.8.2 dev: true + /rollup-plugin-node-polyfills/0.2.1: + resolution: {integrity: sha512-4kCrKPTJ6sK4/gLL/U5QzVT8cxJcofO0OU74tnB19F40cmuAKSzH5/siithxlofFEjwvw1YAhPmbvGNA6jEroA==} + dependencies: + rollup-plugin-inject: 3.0.2 + dev: true + /rollup-plugin-polyfill-node/0.6.2_rollup@2.38.5: resolution: {integrity: sha512-gMCVuR0zsKq0jdBn8pSXN1Ejsc458k2QsFFvQdbHoM0Pot5hEnck+pBP/FDwFS6uAi77pD3rDTytsaUStsOMlA==} dependencies: @@ -6528,7 +6726,7 @@ packages: engines: {node: '>=8'} dev: true - /ts-jest/27.1.1_dc33159234d58f1c7ac35b6119da0e94: + /ts-jest/27.1.1_305b6a4a69ca4f1a88855b62d81fc1b0: resolution: {integrity: sha512-Ds0VkB+cB+8g2JUmP/GKWndeZcCKrbe6jzolGrVWdqVUFByY/2KDHqxJ7yBSon7hDB1TA4PXxjfZ+JjzJisvgA==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} hasBin: true @@ -6551,6 +6749,7 @@ packages: dependencies: '@types/jest': 27.0.3 bs-logger: 0.2.6 + esbuild: 0.14.11 fast-json-stable-stringify: 2.1.0 jest: 27.4.4 jest-util: 27.4.2 diff --git a/scripts/dev.js b/scripts/dev.js index 49418dbf4c1..621cbe63f05 100644 --- a/scripts/dev.js +++ b/scripts/dev.js @@ -1,44 +1,107 @@ -/* -Run Rollup in watch mode for development. +// Using esbuild for faster dev builds. +// We are still using Rollup for production builds because it generates +// smaller files w/ better tree-shaking. -To specific the package to watch, simply pass its name and the desired build -formats to watch (defaults to "global"): +// @ts-check +const { build } = require('esbuild') +const nodePolyfills = require('@esbuild-plugins/node-modules-polyfill') +const { resolve, relative } = require('path') +const args = require('minimist')(process.argv.slice(2)) -``` -# name supports fuzzy match. will watch all packages with name containing "dom" -nr dev dom +const target = args._[0] || 'vue' +const format = args.f || 'global' +const inlineDeps = args.i || args.inline +const pkg = require(resolve(__dirname, `../packages/${target}/package.json`)) -# specify the format to output -nr dev core --formats cjs +// resolve output +const outputFormat = format.startsWith('global') + ? 'iife' + : format === 'cjs' + ? 'cjs' + : 'esm' -# Can also drop all __DEV__ blocks with: -__DEV__=false nr dev -``` -*/ +const postfix = format.endsWith('-runtime') + ? `runtime.${format.replace(/-runtime$/, '')}` + : format -const execa = require('execa') -const { fuzzyMatchTarget } = require('./utils') -const args = require('minimist')(process.argv.slice(2)) -const target = args._.length ? fuzzyMatchTarget(args._)[0] : 'vue' -const formats = args.formats || args.f -const sourceMap = args.sourcemap || args.s -const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7) - -execa( - 'rollup', - [ - '-wc', - '--environment', - [ - `COMMIT:${commit}`, - `TARGET:${target}`, - `FORMATS:${formats || 'global'}`, - sourceMap ? `SOURCE_MAP:true` : `` +const outfile = resolve( + __dirname, + `../packages/${target}/dist/${target}.${postfix}.js` +) +const relativeOutfile = relative(process.cwd(), outfile) + +// resolve extenrals +// TODO this logic is largely duplicated from rollup.config.js +let external = [] +if (!inlineDeps) { + // cjs & esm-bundler: external all deps + if (format === 'cjs' || format.includes('esm-bundler')) { + external = [ + ...external, + ...Object.keys(pkg.dependencies || {}), + ...Object.keys(pkg.peerDependencies || {}), + // for @vue/compiler-sfc / server-renderer + 'path', + 'url', + 'stream' ] - .filter(Boolean) - .join(',') - ], - { - stdio: 'inherit' } -) + + if (target === 'compiler-sfc') { + const consolidateDeps = require.resolve('@vue/consolidate/package.json', { + paths: [resolve(__dirname, `../packages/${target}/`)] + }) + external = [ + ...external, + ...Object.keys(require(consolidateDeps).devDependencies), + 'fs', + 'vm', + 'crypto', + 'react-dom/server', + 'teacup/lib/express', + 'arc-templates/dist/es5', + 'then-pug', + 'then-jade' + ] + } +} + +build({ + entryPoints: [resolve(__dirname, `../packages/${target}/src/index.ts`)], + outfile, + bundle: true, + external, + sourcemap: true, + format: outputFormat, + globalName: pkg.buildOptions?.name, + platform: format === 'cjs' ? 'node' : 'browser', + plugins: + format === 'cjs' || pkg.buildOptions?.enableNonBrowserBranches + ? [nodePolyfills.default()] + : undefined, + define: { + __COMMIT__: `"dev"`, + __VERSION__: `"${pkg.version}"`, + __DEV__: `true`, + __TEST__: `false`, + __BROWSER__: String( + format !== 'cjs' && !pkg.buildOptions?.enableNonBrowserBranches + ), + __GLOBAL__: String(format === 'global'), + __ESM_BUNDLER__: String(format.includes('esm-bundler')), + __ESM_BROWSER__: String(format.includes('esm-browser')), + __NODE_JS__: String(format === 'cjs'), + __SSR__: String(format === 'cjs' || format.includes('esm-bundler')), + __COMPAT__: `false`, + __FEATURE_SUSPENSE__: `true`, + __FEATURE_OPTIONS_API__: `true`, + __FEATURE_PROD_DEVTOOLS__: `false` + }, + watch: { + onRebuild(error) { + if (!error) console.log(`rebuilt: ${relativeOutfile}`) + } + } +}).then(() => { + console.log(`watching: ${relativeOutfile}`) +})