diff --git a/.eslintrc.js b/.eslintrc.js index 77b30694c234b6..edf6be5da94729 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,7 +11,7 @@ module.exports = { 'node/no-missing-import': [ 'error', { - allowModules: ['types', 'estree', 'testUtils'], + allowModules: ['types', 'estree', 'testUtils', 'stylus'], tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'] } ], @@ -31,7 +31,7 @@ module.exports = { message: `devDependencies can only be imported using ESM syntax so ` + `that they are included in the rollup bundle. If you are trying to ` + - `lazy load a dep, use (await import('dep')).default instead.` + `lazy load a dependency, use (await import('dependency')).default instead.` }) ) ], diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 5d7a1f5413ca4c..c81c77e4875a95 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -2,7 +2,7 @@ name: "\U0001F680 New feature proposal" about: Propose a new feature to be added to Vite title: '' -labels: 'feat: pending triage' +labels: 'enhancement: pending triage' assignees: '' --- diff --git a/docs/config/index.md b/docs/config/index.md index 86a6b7ca41a81f..2b1d614dc32536 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -417,7 +417,7 @@ export default ({ command, mode }) => { The transform is performed with esbuild and the value should be a valid [esbuild target option](https://esbuild.github.io/api/#target). Custom targets can either be a ES version (e.g. `es2015`), a browser with version (e.g. `chrome58`), or an array of multiple target strings. - Note the build will fail if the code contains features that cannot be safely transpiled by esbuild. See [esbuid docs](https://esbuild.github.io/content-types/#javascript) for more details. + Note the build will fail if the code contains features that cannot be safely transpiled by esbuild. See [esbuild docs](https://esbuild.github.io/content-types/#javascript) for more details. ### build.polyfillDynamicImport @@ -569,6 +569,15 @@ export default ({ command, mode }) => { By default, linked packages not inside `node_modules` are not pre-bundled. Use this option to force a linked package to be pre-bundled. +### optimizeDeps.keepNames + +- **Type:** `boolean` +- **Default:** `false` + + The bundler sometimes needs to rename symbols to avoid collisions. + Set this to `true` to keep the `name` property on functions and classes. + See [`keepNames`](https://esbuild.github.io/api/#keep-names). + ## SSR Options :::warning Experimental diff --git a/docs/guide/comparisons.md b/docs/guide/comparisons.md index f68319696a986e..3e944d9b23aba5 100644 --- a/docs/guide/comparisons.md +++ b/docs/guide/comparisons.md @@ -39,7 +39,7 @@ Vite was initially created to serve as the future foundation of [Vue.js](https:/ [WMR](https://github.com/preactjs/wmr) by the Preact team provides a similar feature set, and Vite 2.0's support for Rollup's plugin interface is inspired by it. -WMR is mainly designed for [Preact](https://preactjs.com/) projects, and offers more integrated features such as pre-rendering. In terms of scope, it's closer to a Preact meta framework, with the same emphasis on compact size as Preact itself. If you are using Preact, WMR is likely going to offer a more fine-tuned experience. However, it's unlikely for WMR to prioritize support for other frameworks. +WMR is mainly designed for [Preact](https://preactjs.com/) projects, and offers more integrated features such as pre-rendering. In terms of scope, it's closer to a Preact meta framework, with the same emphasis on compact size as Preact itself. If you are using Preact, WMR is likely going to offer a more fine-tuned experience. ## @web/dev-server diff --git a/packages/create-app/CHANGELOG.md b/packages/create-app/CHANGELOG.md index 819b2b433ce439..3de339465ae0c0 100644 --- a/packages/create-app/CHANGELOG.md +++ b/packages/create-app/CHANGELOG.md @@ -1,3 +1,11 @@ +## [2.2.2](https://github.com/vitejs/vite/compare/create-app@2.2.1...create-app@2.2.2) (2021-03-25) + + + +## [2.2.1](https://github.com/vitejs/vite/compare/create-app@2.2.0...create-app@2.2.1) (2021-03-25) + + + # [2.2.0](https://github.com/vitejs/vite/compare/create-app@2.1.0...create-app@2.2.0) (2021-03-16) diff --git a/packages/create-app/package.json b/packages/create-app/package.json index 8f3524b5030e03..877fbb4b7dc4a9 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/create-app", - "version": "2.2.0", + "version": "2.2.2", "license": "MIT", "author": "Evan You", "bin": { @@ -21,7 +21,8 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/vitejs/vite.git" + "url": "git+https://github.com/vitejs/vite.git", + "directory": "packages/create-app" }, "bugs": { "url": "https://github.com/vitejs/vite/issues" diff --git a/packages/create-app/template-lit-element-ts/package.json b/packages/create-app/template-lit-element-ts/package.json index 26f4bb50dfed7a..ae88cc044970da 100644 --- a/packages/create-app/template-lit-element-ts/package.json +++ b/packages/create-app/template-lit-element-ts/package.json @@ -18,7 +18,7 @@ "lit-element": "^2.4.0" }, "devDependencies": { - "vite": "^2.1.0", + "vite": "^2.1.3", "typescript": "^4.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-lit-element/package.json b/packages/create-app/template-lit-element/package.json index 50e3f1ef3897db..94b98007ae8389 100644 --- a/packages/create-app/template-lit-element/package.json +++ b/packages/create-app/template-lit-element/package.json @@ -16,6 +16,6 @@ "lit-element": "^2.4.0" }, "devDependencies": { - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-preact-ts/package.json b/packages/create-app/template-preact-ts/package.json index 50b2ab0a60e20a..97beb965b95440 100644 --- a/packages/create-app/template-preact-ts/package.json +++ b/packages/create-app/template-preact-ts/package.json @@ -12,6 +12,6 @@ "devDependencies": { "@preact/preset-vite": "^2.0.0", "typescript": "^4.1.3", - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-preact/package.json b/packages/create-app/template-preact/package.json index 247311f78d3bd7..275575ed65dc27 100644 --- a/packages/create-app/template-preact/package.json +++ b/packages/create-app/template-preact/package.json @@ -11,6 +11,6 @@ }, "devDependencies": { "@preact/preset-vite": "^2.0.0", - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-react-ts/package.json b/packages/create-app/template-react-ts/package.json index 31caf280489db5..2ae4fa2e2885b4 100644 --- a/packages/create-app/template-react-ts/package.json +++ b/packages/create-app/template-react-ts/package.json @@ -15,6 +15,6 @@ "@types/react-dom": "^17.0.0", "@vitejs/plugin-react-refresh": "^1.3.1", "typescript": "^4.1.2", - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-react/package.json b/packages/create-app/template-react/package.json index 9abf4a6cc05d5d..9c5af4769fc06d 100644 --- a/packages/create-app/template-react/package.json +++ b/packages/create-app/template-react/package.json @@ -12,6 +12,6 @@ }, "devDependencies": { "@vitejs/plugin-react-refresh": "^1.3.1", - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-svelte-ts/package.json b/packages/create-app/template-svelte-ts/package.json index 42909c008923cd..17ae9bd3a6a934 100644 --- a/packages/create-app/template-svelte-ts/package.json +++ b/packages/create-app/template-svelte-ts/package.json @@ -11,6 +11,6 @@ "svelte": "^3.35.0", "svelte-preprocess": "^4.6.9", "typescript": "^4.2.3", - "vite": "^2.1.2" + "vite": "^2.1.3" } -} +} \ No newline at end of file diff --git a/packages/create-app/template-svelte/package.json b/packages/create-app/template-svelte/package.json index e9c02f90d0bba0..ea8852a6219fb3 100644 --- a/packages/create-app/template-svelte/package.json +++ b/packages/create-app/template-svelte/package.json @@ -9,6 +9,6 @@ "devDependencies": { "@sveltejs/vite-plugin-svelte": "next", "svelte": "^3.35.0", - "vite": "^2.1.2" + "vite": "^2.1.3" } -} +} \ No newline at end of file diff --git a/packages/create-app/template-vanilla/package.json b/packages/create-app/template-vanilla/package.json index 7b671abfdb1087..0336bcb68802f6 100644 --- a/packages/create-app/template-vanilla/package.json +++ b/packages/create-app/template-vanilla/package.json @@ -7,6 +7,6 @@ "serve": "vite preview" }, "devDependencies": { - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-vue-ts/package.json b/packages/create-app/template-vue-ts/package.json index 3a557f747a395b..e08b516a0e2f69 100644 --- a/packages/create-app/template-vue-ts/package.json +++ b/packages/create-app/template-vue-ts/package.json @@ -13,7 +13,7 @@ "@vitejs/plugin-vue": "^1.1.5", "@vue/compiler-sfc": "^3.0.5", "typescript": "^4.1.3", - "vite": "^2.1.0", - "vue-tsc": "^0.0.8" + "vite": "^2.1.3", + "vue-tsc": "^0.0.15" } -} \ No newline at end of file +} diff --git a/packages/create-app/template-vue/package.json b/packages/create-app/template-vue/package.json index 3cff059b7294a2..3da544228de86f 100644 --- a/packages/create-app/template-vue/package.json +++ b/packages/create-app/template-vue/package.json @@ -12,6 +12,6 @@ "devDependencies": { "@vitejs/plugin-vue": "^1.1.5", "@vue/compiler-sfc": "^3.0.5", - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/playground/alias/package.json b/packages/playground/alias/package.json index d76e350b2e4c69..2f047851e9af5d 100644 --- a/packages/playground/alias/package.json +++ b/packages/playground/alias/package.json @@ -9,6 +9,6 @@ "serve": "vite preview" }, "dependencies": { - "vue": "^3.0.5" + "vue": "^3.0.8" } } diff --git a/packages/playground/assets/__tests__/assets.spec.ts b/packages/playground/assets/__tests__/assets.spec.ts index cc0047dd736ca4..b640d95f294c49 100644 --- a/packages/playground/assets/__tests__/assets.spec.ts +++ b/packages/playground/assets/__tests__/assets.spec.ts @@ -5,7 +5,8 @@ import { getColor, isBuild, listAssets, - readManifest + readManifest, + readFile } from '../../testUtils' const assetMatch = isBuild @@ -180,7 +181,7 @@ test('?raw import', async () => { }) test('?url import', async () => { - const src = `console.log('hi')\n` + const src = readFile('foo.js') expect(await page.textContent('.url')).toMatch( isBuild ? `data:application/javascript;base64,${Buffer.from(src).toString( diff --git a/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts b/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts index fa97cc1393f28a..32333059ad7381 100644 --- a/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts +++ b/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts @@ -1,29 +1,31 @@ -import { untilUpdated } from '../../testUtils' +import { isBuild, untilUpdated } from '../../testUtils' test('should load literal dynamic import', async () => { await page.click('.baz') - await untilUpdated(() => page.textContent('.view'), 'Baz view') + await untilUpdated(() => page.textContent('.view'), 'Baz view', true) }) test('should load full dynamic import from public', async () => { await page.click('.qux') - await untilUpdated(() => page.textContent('.view'), 'Qux view') + await untilUpdated(() => page.textContent('.view'), 'Qux view', true) +}) + +test('should load data URL of `blob:`', async () => { + await page.click('.issue-2658-1') + await untilUpdated(() => page.textContent('.view'), 'blob', true) +}) + +test('should load data URL of `data:`', async () => { + await page.click('.issue-2658-2') + await untilUpdated(() => page.textContent('.view'), 'data', true) }) // since this test has a timeout, it should be put last so that it // does not bleed on the last test('should load dynamic import with vars', async () => { await page.click('.foo') - await untilUpdated(() => page.textContent('.view'), 'Foo view') + await untilUpdated(() => page.textContent('.view'), 'Foo view', true) - // first page click will not load the remote message - // because vite needs to compile the lodash dependency await page.click('.bar') - await untilUpdated(() => page.textContent('.view'), '') - - // wait until reload and click again - setTimeout(async () => { - await page.click('.bar') - await untilUpdated(() => page.textContent('.view'), 'Bar view') - }, 10) + await untilUpdated(() => page.textContent('.view'), 'Bar view', true) }) diff --git a/packages/playground/dynamic-import/index.html b/packages/playground/dynamic-import/index.html index ad5e7ab57c98b7..87bb6ebdaa37e8 100644 --- a/packages/playground/dynamic-import/index.html +++ b/packages/playground/dynamic-import/index.html @@ -2,6 +2,8 @@ + +
diff --git a/packages/playground/dynamic-import/nested/index.js b/packages/playground/dynamic-import/nested/index.js index 383e51f3d5dfdd..cc6522016fc1d8 100644 --- a/packages/playground/dynamic-import/nested/index.js +++ b/packages/playground/dynamic-import/nested/index.js @@ -21,6 +21,26 @@ document.querySelector('.qux').addEventListener('click', async () => { text('.view', msg) }) +// data URLs (`blob:`) +const code1 = 'export const msg = "blob"' +const blob = new Blob([code1], { type: 'text/javascript;charset=UTF-8' }) +// eslint-disable-next-line node/no-unsupported-features/node-builtins +const blobURL = URL.createObjectURL(blob) +document.querySelector('.issue-2658-1').addEventListener('click', async () => { + const { msg } = await import(/*@vite-ignore*/ blobURL) + text('.view', msg) +}) + +// data URLs (`data:`) +const code2 = 'export const msg = "data";' +const dataURL = `data:text/javascript;charset=utf-8,${encodeURIComponent( + code2 +)}` +document.querySelector('.issue-2658-2').addEventListener('click', async () => { + const { msg } = await import(/*@vite-ignore*/ dataURL) + text('.view', msg) +}) + function text(el, text) { document.querySelector(el).textContent = text } diff --git a/packages/playground/dynamic-import/package.json b/packages/playground/dynamic-import/package.json index 1bc86fbf6bf84e..91048d3c3b90a2 100644 --- a/packages/playground/dynamic-import/package.json +++ b/packages/playground/dynamic-import/package.json @@ -7,8 +7,5 @@ "build": "vite build", "debug": "node --inspect-brk ../../vite/bin/vite", "serve": "vite preview" - }, - "dependencies": { - "lodash": "4.17.21" } } diff --git a/packages/playground/dynamic-import/views/bar.js b/packages/playground/dynamic-import/views/bar.js index bf14cd33bceb5e..94401802f2dd50 100644 --- a/packages/playground/dynamic-import/views/bar.js +++ b/packages/playground/dynamic-import/views/bar.js @@ -1,5 +1 @@ -import { n } from '../nested/shared' -import { isBoolean } from 'lodash' -console.log('bar' + isBoolean(n)) - export const msg = 'Bar view' diff --git a/packages/playground/file-delete-restore/App.jsx b/packages/playground/file-delete-restore/App.jsx new file mode 100644 index 00000000000000..de41c853cdc3ed --- /dev/null +++ b/packages/playground/file-delete-restore/App.jsx @@ -0,0 +1,12 @@ +import { useState } from 'react' +import Child from './Child' + +function App() { + return ( +Child state 1
+} diff --git a/packages/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts b/packages/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts new file mode 100644 index 00000000000000..24f1237efedeec --- /dev/null +++ b/packages/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts @@ -0,0 +1,61 @@ +import { + editFile, + untilUpdated, + removeFile, + addFile, + isBuild +} from '../../testUtils' + +if (!isBuild) { + test('should hmr when file is deleted and restored', async () => { + await untilUpdated(() => page.textContent('p'), 'Child state 1') + + editFile('Child.jsx', (code) => + code.replace('Child state 1', 'Child state 2') + ) + + await untilUpdated(() => page.textContent('p'), 'Child state 2') + + editFile('App.jsx', (code) => + code + .replace(`import Child from './Child'`, '') + .replace(`Child deleted
') + ) + removeFile('Child.jsx') + await untilUpdated(() => page.textContent('p'), 'Child deleted') + + // restore Child.jsx + addFile( + 'Child.jsx', + ` export default function Child() { + returnChild state 1
+ } + ` + ) + + // restore App.jsx + editFile( + 'App.jsx', + (code) => + `import { useState } from 'react' + import Child from './Child' + + function App() { + return ( +fail
+fail
+ +fail
+fail
@@ -95,13 +101,40 @@