diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 48a0bd7773b0d7..9f6bf0deb86303 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -8,6 +8,7 @@ module.exports = defineConfig({ 'plugin:node/recommended', 'plugin:@typescript-eslint/recommended' ], + plugins: ['import'], parser: '@typescript-eslint/parser', parserOptions: { sourceType: 'module', @@ -29,14 +30,7 @@ module.exports = defineConfig({ 'node/no-missing-import': [ 'error', { - allowModules: [ - 'types', - 'estree', - 'testUtils', - 'less', - 'sass', - 'stylus' - ], + allowModules: ['types', 'estree', 'less', 'sass', 'stylus'], tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'] } ], @@ -63,7 +57,7 @@ module.exports = defineConfig({ 'node/no-extraneous-import': [ 'error', { - allowModules: ['vite', 'less', 'sass'] + allowModules: ['vite', 'less', 'sass', 'vitest'] } ], 'node/no-extraneous-require': [ @@ -93,6 +87,18 @@ module.exports = defineConfig({ '@typescript-eslint/consistent-type-imports': [ 'error', { prefer: 'type-imports' } + ], + + 'import/order': 'error', + 'sort-imports': [ + 'error', + { + ignoreCase: false, + ignoreDeclarationSort: true, + ignoreMemberSort: false, + memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], + allowSeparatedGroups: false + } ] }, overrides: [ @@ -103,16 +109,18 @@ module.exports = defineConfig({ } }, { - files: ['packages/vite/types/**'], + files: ['packages/vite/types/**', '*.spec.ts'], rules: { 'node/no-extraneous-import': 'off' } }, { - files: ['packages/playground/**'], + files: ['playground/**'], rules: { 'node/no-extraneous-import': 'off', - 'node/no-extraneous-require': 'off' + 'node/no-extraneous-require': 'off', + 'node/no-missing-import': 'off', + 'node/no-missing-require': 'off' } }, { diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 06fe0e7ea2aaff..17898db2741284 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -1,11 +1,7 @@ { "extends": ["config:base", "schedule:weekly", "group:allNonMajor"], "labels": ["dependencies"], - "ignorePaths": [ - "packages/playground/**", - "packages/create-vite/template-*/**", - "**/__tests__/**" - ], + "ignorePaths": ["**/__tests__/**"], "pin": false, "rangeStrategy": "bump", "node": false, diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2832dab118e279..05813fbd73e244 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ on: - feat/* - fix/* - perf/* + - v1 + - v2 pull_request: workflow_dispatch: @@ -27,7 +29,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node_version: [12, 14, 16, 17, 18] + node_version: [14, 16, 18] include: - os: macos-latest node_version: 16 @@ -40,6 +42,10 @@ jobs: # node_version: 18 fail-fast: false + env: + # Install playwright's binray under node_modules so it will be cached together + PLAYWRIGHT_BROWSERS_PATH: "0" + name: "Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }}" steps: - name: Checkout @@ -47,8 +53,6 @@ jobs: - name: Install pnpm uses: pnpm/action-setup@v2 - with: - version: 6 - name: Set node version to ${{ matrix.node_version }} uses: actions/setup-node@v3 @@ -59,6 +63,9 @@ jobs: - name: Install deps run: pnpm install + - name: Install Playwright + run: pnpm playwright install + - name: Build vite run: pnpm run ci-build-vite @@ -68,11 +75,14 @@ jobs: - name: Build plugin-react run: pnpm run build-plugin-react + - name: Test unit + run: pnpm run test-unit + - name: Test serve - run: pnpm run test-serve -- --runInBand + run: pnpm run test-serve - name: Test build - run: pnpm run test-build -- --runInBand + run: pnpm run test-build lint: timeout-minutes: 10 @@ -85,8 +95,6 @@ jobs: - name: Install pnpm uses: pnpm/action-setup@v2 - with: - version: 6 - name: Set node version to 16 uses: actions/setup-node@v3 @@ -96,14 +104,20 @@ jobs: - name: Install deps run: pnpm install + env: + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1" - name: Prepare run: | pnpm run ci-build-vite pnpm run build-plugin-vue + pnpm run build-plugin-react - name: Lint run: pnpm run lint - name: Check formatting run: pnpm prettier --check . + + - name: Typecheck + run: pnpm run typecheck diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c58c28adac7b40..022a0cbc77e7fc 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -31,14 +31,8 @@ jobs: - name: Install deps run: pnpm install - - - name: Creating .npmrc - run: | - cat << EOF > "$HOME/.npmrc" - //registry.npmjs.org/:_authToken=$NPM_TOKEN - EOF env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1" - name: Publish package run: pnpm run ci-publish -- ${{ github.ref_name }} diff --git a/.gitignore b/.gitignore index 44abdd7bf563db..9194d44b544c4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,15 @@ -.DS_Store -node_modules !**/glob-import/dir/node_modules -dist -dist-ssr -TODOs.md -*.log -temp -explorations +.DS_Store .idea -*.local -/packages/vite/LICENSE *.cpuprofile +*.local +*.log /.vscode/ +/packages/vite/LICENSE +dist +dist-ssr +explorations +node_modules +playground-temp +temp +TODOs.md diff --git a/.npmrc b/.npmrc index 4abbb42e5ef159..0a8182ea5f2c53 100644 --- a/.npmrc +++ b/.npmrc @@ -1,6 +1,5 @@ hoist-pattern[]=*eslint* hoist-pattern[]=*babel* -hoist-pattern[]=*jest* hoist-pattern[]=@emotion/* hoist-pattern[]=postcss hoist-pattern[]=pug diff --git a/.prettierignore b/.prettierignore index c624a3a21eecfe..a2c1f98cf5cc02 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,10 +4,11 @@ packages/vite/temp/ packages/plugin-react/dist/ packages/plugin-vue/dist/ packages/*/CHANGELOG.md +playground-temp/ LICENSE.md .prettierignore pnpm-lock.yaml pnpm-workspace.yaml -packages/playground/tsconfig-json-load-error/has-error/tsconfig.json -packages/playground/html/invalid.html -packages/playground/worker/classic-worker.js +playground/tsconfig-json-load-error/has-error/tsconfig.json +playground/html/invalid.html +playground/worker/classic-worker.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c7020c97a84c80..e489730c907f44 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,6 +16,8 @@ To develop and test the core `vite` package: You can alternatively use [Vite.js Docker Dev](https://github.com/nystudio107/vitejs-docker-dev) for a containerized Docker setup for Vite.js development. +> Vite uses pnpm v7. If you are working on multiple projects with different versions of pnpm, it's recommend to enable [Corepack](https://github.com/nodejs/corepack) by running `corepack enable`. + ## Debugging If you want to use break point and explore code execution you can use the ["Run and debug"](https://code.visualstudio.com/docs/editor/debugging) feature from vscode. @@ -26,23 +28,23 @@ If you want to use break point and explore code execution you can use the ["Run 3. Click on the "JavaScript Debug Terminal" button. -4. It will open a terminal, then go to `packages/playground/xxx` and run `pnpm run dev`. +4. It will open a terminal, then go to `playground/xxx` and run `pnpm run dev`. 5. The execution will stop and you'll use the [Debug toolbar](https://code.visualstudio.com/docs/editor/debugging#_debug-actions) to continue, step over, restart the process... -### Debugging errors in Jest tests using Playwright (Chromium) +### Debugging errors in Vitest tests using Playwright (Chromium) -Some errors are masked and hidden away because of the layers of abstraction and sandboxed nature added by Jest, Playwright, and Chromium. In order to see what's actually going wrong and the contents of the devtools console in those instances, follow this setup: +Some errors are masked and hidden away because of the layers of abstraction and sandboxed nature added by Vitest, Playwright, and Chromium. In order to see what's actually going wrong and the contents of the devtools console in those instances, follow this setup: -1. Add a `debugger` statement to the `scripts/jestPerTestSetup.ts` -> `afterAll` hook. This will pause execution before the tests quit and the Playwright browser instance exits. +1. Add a `debugger` statement to the `playground/vitestSetup.ts` -> `afterAll` hook. This will pause execution before the tests quit and the Playwright browser instance exits. -1. Run the tests with the `debug-serve` script command which will enable remote debugging: `pnpm run debug-serve -- --runInBand resolve`. +1. Run the tests with the `debug-serve` script command which will enable remote debugging: `pnpm run debug-serve resolve`. 1. Wait for inspector devtools to open in your browser and the debugger to attach. 1. In the sources panel in the right column, click the play button to resume execution and allow the tests to run which will open a Chromium instance. -1. Focusing the Chomium instance, you can open the browser devtools and inspect the console there to find the underlying problems. +1. Focusing the Chromium instance, you can open the browser devtools and inspect the console there to find the underlying problems. 1. To close everything, just stop the test process back in your terminal. @@ -67,46 +69,58 @@ And re-run `pnpm install` to link the package. ## Running Tests -Each package under `packages/playground/` contains a `__tests__` directory. The tests are run using [Jest](https://jestjs.io/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `jest.config.js` and `scripts/jest*` files. +### Integration Tests + +Each package under `playground/` contains a `__tests__` directory. The tests are run using [Vitest](https://vitest.dev/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `vitest.config.e2e.js` and `playground/vitest*` files. -Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to solve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390). +Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to solve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390). Also you may want to [set git `core.symlinks` to `true` to solve issues with symlinks in git](https://github.com/vitejs/vite/issues/5242). -Each test can be run under either dev server mode or build mode. +Each integration test can be run under either dev server mode or build mode. -- `pnpm test` by default runs every test in both serve and build mode. +- `pnpm test` by default runs every integration test in both serve and build mode, and also unit tests. -- `pnpm run test-serve` runs tests only under serve mode. This is just calling `jest` so you can pass any Jest flags to this command. Since Jest will attempt to run tests in parallel, if your machine has many cores this may cause flaky test failures with multiple Playwright instances running at the same time. You can force the tests to run in series with `pnpm run test-serve -- --runInBand`. +- `pnpm run test-serve` runs tests only under serve mode. - `pnpm run test-build` runs tests only under build mode. -- You can also use `pnpm run test-serve -- [match]` or `pnpm run test-build -- [match]` to run tests in a specific playground package, e.g. `pnpm run test-serve -- asset` will run tests for both `playground/asset` and `vite/src/node/__tests__/asset` under serve mode and `vite/src/node/__tests__/**/*` just run in serve mode. +- You can also use `pnpm run test-serve [match]` or `pnpm run test-build [match]` to run tests in a specific playground package, e.g. `pnpm run test-serve asset` will run tests for both `playground/asset` and `vite/src/node/__tests__/asset` under serve mode and `vite/src/node/__tests__/**/*` just run in serve mode. Note package matching is not available for the `pnpm test` script, which always runs all tests. +### Unit Tests + +Other than tests under `playground/` for integration tests, packages might contains unit tests under their `__tests__` directory. Unit tests are powered by [Vitest](https://vitest.dev/). The detailed config is inside `vitest.config.ts` files. + +- `pnpm run test-unit` runs unit tests under each package. + +- You can also use `pnpm run test-unit [match]` to run related tests. + ### Test Env and Helpers -Inside playground tests, a global `page` object is automatically available, which is a Playwright [`Page`](https://playwright.dev/docs/api/class-page) instance that has already navigated to the served page of the current playground. So writing a test is as simple as: +Inside playground tests, you can import the `page` object from `~utils`, which is a Playwright [`Page`](https://playwright.dev/docs/api/class-page) instance that has already navigated to the served page of the current playground. So writing a test is as simple as: ```js +import { page } from '~utils' + test('should work', async () => { expect(await page.textContent('.foo')).toMatch('foo') }) ``` -Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are available in `packages/playground/testUtils.ts`. +Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are also available in the utils. Source code is located at `playground/test-utils.ts`. -Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/9c6501d9c363eaa3c1e7708d531fb2a92b633db6/scripts/jestPerTestSetup.ts#L102-L122) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build. +Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/main/playground/vitestSetup.ts#L102-L122) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build. ### Extending the Test Suite -To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading are tested in the [assets playground](https://github.com/vitejs/vite/tree/main/packages/playground/assets). In this Vite App, there is a test for `?raw` imports, with [a section is defined in the `index.html` for it](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/index.html#L121): +To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading are tested in the [assets playground](https://github.com/vitejs/vite/tree/main/playground/assets). In this Vite App, there is a test for `?raw` imports, with [a section is defined in the `index.html` for it](https://github.com/vitejs/vite/blob/main/playground/assets/index.html#L121): ```html
```
-This will be modified [with the result of a file import](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/index.html#L151):
+This will be modified [with the result of a file import](https://github.com/vitejs/vite/blob/main/playground/assets/index.html#L151):
```js
import rawSvg from './nested/fragment.svg?raw'
@@ -121,7 +135,7 @@ function text(el, text) {
}
```
-In the [spec tests](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/__tests__/assets.spec.ts#L180), the modifications to the DOM listed above are used to test this feature:
+In the [spec tests](https://github.com/vitejs/vite/blob/main/playground/assets/__tests__/assets.spec.ts#L180), the modifications to the DOM listed above are used to test this feature:
```js
test('?raw import', async () => {
@@ -138,7 +152,7 @@ To work around this, playground packages that uses the `file:` protocol should a
```jsonc
"scripts": {
//...
- "postinstall": "ts-node ../../../scripts/patchFileDeps.ts"
+ "postinstall": "ts-node ../../scripts/patchFileDeps.ts"
}
```
diff --git a/README.md b/README.md
index 546014a12c7116..a6f13829f2635f 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,8 @@ In addition, Vite is highly extensible via its [Plugin API](https://vitejs.dev/g
## Packages
+> This branch is for the upcoming v3.0, if you are looking for current stable releases, check the [`v2` branch](https://github.com/vitejs/vite/tree/v2) instead.
+
| Package | Version (click for changelogs) |
| ------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------- |
| [vite](packages/vite) | [![vite version](https://img.shields.io/npm/v/vite.svg?label=%20)](packages/vite/CHANGELOG.md) |
diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.ts
similarity index 94%
rename from docs/.vitepress/config.js
rename to docs/.vitepress/config.ts
index ee76a29986d3fb..4659ea5ab7ae4f 100644
--- a/docs/.vitepress/config.js
+++ b/docs/.vitepress/config.ts
@@ -1,9 +1,6 @@
-// @ts-check
+import { defineConfig } from 'vitepress'
-/**
- * @type {import('vitepress').UserConfig}
- */
-module.exports = {
+export default defineConfig({
title: 'Vite',
description: 'Next Generation Frontend Tooling',
head: [['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }]],
@@ -64,6 +61,15 @@ module.exports = {
}
]
},
+ {
+ text: 'v3 (next)',
+ items: [
+ {
+ text: 'v2.x (stable)',
+ link: 'https://v2.vitejs.dev'
+ }
+ ]
+ },
{
text: 'Languages',
items: [
@@ -169,4 +175,4 @@ module.exports = {
]
}
}
-}
+})
diff --git a/docs/config/index.md b/docs/config/index.md
index bab7df7a144987..8fc772f345e0ea 100644
--- a/docs/config/index.md
+++ b/docs/config/index.md
@@ -28,12 +28,14 @@ vite --config my-config.js
```
::: tip NOTE
-Vite will replace `__filename`, `__dirname`, and `import.meta.url` in config files and its deps. Using these as variable names will result in an error:
+Vite will replace `__filename`, `__dirname`, and `import.meta.url` in config files and its deps. Using these as variable names or passing as a parameter to a function with string double quote (example `console.log`) will result in an error:
```js
const __filename = "value"
// will be transformed to
const "path/vite.config.js" = "value"
+
+console.log("import.meta.url") // break error on build
```
:::
@@ -94,7 +96,7 @@ If the config needs to call async function, it can export a async function inste
export default defineConfig(async ({ command, mode }) => {
const data = await asyncFunction()
return {
- // build specific config
+ // vite config
}
})
```
@@ -109,10 +111,14 @@ Note that Vite doesn't load `.env` files by default as the files to load can onl
import { defineConfig, loadEnv } from 'vite'
export default defineConfig(({ command, mode }) => {
- // Load env file based on `mode` in the current working directory
- const env = loadEnv(mode, process.cwd())
+ // Load env file based on `mode` in the current working directory.
+ // Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
+ const env = loadEnv(mode, process.cwd(), '')
return {
- // build specific config
+ // vite config
+ define: {
+ __APP_ENV__: env.APP_ENV
+ }
}
})
```
@@ -160,7 +166,7 @@ export default defineConfig(({ command, mode }) => {
- To be consistent with [esbuild behavior](https://esbuild.github.io/api/#define), expressions must either be a JSON object (null, boolean, number, string, array, or object) or a single identifier.
- - Replacements are performed only when the match is surrounded by word boundaries (`\b`).
+ - Replacements are performed only when the match isn't surrounded by other letters, numbers, `_` or `$`.
::: warning
Because it's implemented as straightforward text replacements without any syntax analysis, we recommend using `define` for CONSTANTS only.
@@ -180,6 +186,20 @@ export default defineConfig(({ command, mode }) => {
:::
+ ::: tip NOTE
+ Since dev and build implement `define` differently, we should avoid some use cases to avoid inconsistency.
+
+ Example:
+
+ ```js
+ const obj = {
+ __NAME__, // Don't define object shorthand property names
+ __KEY__: value // Don't define object key
+ }
+ ```
+
+ :::
+
### plugins
- **Type:** `(Plugin | Plugin[])[]`
@@ -237,7 +257,7 @@ export default defineConfig(({ command, mode }) => {
{
"exports": {
".": {
- "import": "./index.esm.js",
+ "import": "./index.esm.mjs",
"require": "./index.cjs.js"
}
}
@@ -499,6 +519,8 @@ export default defineConfig(({ command, mode }) => {
Uses [`http-proxy`](https://github.com/http-party/node-http-proxy). Full options [here](https://github.com/http-party/node-http-proxy#options).
+ In some cases, you might also want to configure the underlying dev server (e.g. to add custom middlewares to the internal [connect](https://github.com/senchalabs/connect) app). In order to do that, you need to write your own [plugin](/guide/using-plugins.html) and use [configureServer](/guide/api-plugin.html#configureserver) function.
+
**Example:**
```js
@@ -706,7 +728,7 @@ Defines the origin of the generated asset URLs during development.
```js
export default defineConfig({
server: {
- origin: 'http://127.0.0.1:8080/'
+ origin: 'http://127.0.0.1:8080'
}
})
```
@@ -1018,7 +1040,6 @@ export default defineConfig({
- `external` is also omitted, use Vite's `optimizeDeps.exclude` option
- `plugins` are merged with Vite's dep plugin
- - `keepNames` takes precedence over the deprecated `optimizeDeps.keepNames`
## SSR Options
diff --git a/docs/guide/api-plugin.md b/docs/guide/api-plugin.md
index 50353765261e34..76b9984a069828 100644
--- a/docs/guide/api-plugin.md
+++ b/docs/guide/api-plugin.md
@@ -305,6 +305,28 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
Note `configureServer` is not called when running the production build so your other hooks need to guard against its absence.
+### `configurePreviewServer`
+
+- **Type:** `(server: { middlewares: Connect.Server, httpServer: http.Server }) => (() => void) | void | Promise<(() => void) | void>`
+- **Kind:** `async`, `sequential`
+
+ Same as [`configureServer`](/guide/api-plugin.html#configureserver) but for the preview server. It provides the [connect](https://github.com/senchalabs/connect) server and its underlying [http server](https://nodejs.org/api/http.html). Similarly to `configureServer`, the `configurePreviewServer` hook is called before other middlewares are installed. If you want to inject a middleware **after** other middlewares, you can return a function from `configurePreviewServer`, which will be called after internal middlewares are installed:
+
+ ```js
+ const myPlugin = () => ({
+ name: 'configure-preview-server',
+ configurePreviewServer(server) {
+ // return a post hook that is called after other middlewares are
+ // installed
+ return () => {
+ server.middlewares.use((req, res, next) => {
+ // custom handle request...
+ })
+ }
+ }
+ })
+ ```
+
### `transformIndexHtml`
- **Type:** `IndexHtmlTransformHook | { enforce?: 'pre' | 'post', transform: IndexHtmlTransformHook }`
diff --git a/docs/guide/backend-integration.md b/docs/guide/backend-integration.md
index 55a4b87f1ac481..17387bb7819ec0 100644
--- a/docs/guide/backend-integration.md
+++ b/docs/guide/backend-integration.md
@@ -36,7 +36,12 @@ If you need a custom integration, you can follow the steps in this guide to conf
```
- Also make sure the server is configured to serve static assets in the Vite working directory, otherwise assets such as images won't be loaded properly.
+ In order to properly serve assets, you have two options:
+
+ - Make sure the server is configured to proxy static assets requests to the Vite server
+ - Set [`server.origin`](https://vitejs.dev/config/#server-origin) so that generated asset URLs will be resolved using the back-end server URL instead of a relative path
+
+ This is needed for assets such as images to load properly.
Note if you are using React with `@vitejs/plugin-react`, you'll also need to add this before the above scripts, since the plugin is not able to modify the HTML you are serving:
diff --git a/docs/guide/build.md b/docs/guide/build.md
index 8216bcbfbac060..358745d02f2cf1 100644
--- a/docs/guide/build.md
+++ b/docs/guide/build.md
@@ -127,7 +127,8 @@ module.exports = defineConfig({
lib: {
entry: path.resolve(__dirname, 'lib/main.js'),
name: 'MyLib',
- fileName: (format) => `my-lib.${format}.js`
+ // the proper extensions will be added
+ fileName: 'my-lib'
},
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
@@ -159,7 +160,7 @@ Running `vite build` with this config uses a Rollup preset that is oriented towa
```
$ vite build
building for production...
-[write] my-lib.es.js 0.08kb, brotli: 0.07kb
+[write] my-lib.es.mjs 0.08kb, brotli: 0.07kb
[write] my-lib.umd.js 0.30kb, brotli: 0.16kb
```
@@ -170,10 +171,10 @@ Recommended `package.json` for your lib:
"name": "my-lib",
"files": ["dist"],
"main": "./dist/my-lib.umd.js",
- "module": "./dist/my-lib.es.js",
+ "module": "./dist/my-lib.es.mjs",
"exports": {
".": {
- "import": "./dist/my-lib.es.js",
+ "import": "./dist/my-lib.es.mjs",
"require": "./dist/my-lib.umd.js"
}
}
diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md
index b2b1264e85a8e4..d5f45ea1158808 100644
--- a/docs/guide/env-and-mode.md
+++ b/docs/guide/env-and-mode.md
@@ -81,6 +81,14 @@ interface ImportMeta {
}
```
+If your code relies on types from browser environments such as [DOM](https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts) and [WebWorker](https://github.com/microsoft/TypeScript/blob/main/lib/lib.webworker.d.ts), you can update the [lib](https://www.typescriptlang.org/tsconfig#lib) field in `tsconfig.json`.
+
+```json
+{
+ "lib": ["WebWorker"]
+}
+```
+
## Modes
By default, the dev server (`dev` command) runs in `development` mode and the `build` command run in `production` mode.
diff --git a/docs/guide/features.md b/docs/guide/features.md
index 1a8c03bbd0be22..01798ad0d4ea56 100644
--- a/docs/guide/features.md
+++ b/docs/guide/features.md
@@ -282,10 +282,10 @@ for (const path in modules) {
}
```
-Matched files are by default lazy loaded via dynamic import and will be split into separate chunks during build. If you'd rather import all the modules directly (e.g. relying on side-effects in these modules to be applied first), you can use `import.meta.globEager` instead:
+Matched files are by default lazy-loaded via dynamic import and will be split into separate chunks during build. If you'd rather import all the modules directly (e.g. relying on side-effects in these modules to be applied first), you can pass `{ eager: true }` as the second argument:
```js
-const modules = import.meta.globEager('./dir/*.js')
+const modules = import.meta.glob('./dir/*.js', { eager: true })
```
The above will be transformed into the following:
@@ -300,7 +300,9 @@ const modules = {
}
```
-`import.meta.glob` and `import.meta.globEager` also support importing files as strings (similar to [Importing Asset as String](https://vitejs.dev/guide/assets.html#importing-asset-as-string)) with the [Import Reflection](https://github.com/tc39/proposal-import-reflection) syntax:
+### Glob Import As
+
+`import.meta.glob` also supports importing files as strings (similar to [Importing Asset as String](https://vitejs.dev/guide/assets.html#importing-asset-as-string)) with the [Import Reflection](https://github.com/tc39/proposal-import-reflection) syntax:
```js
const modules = import.meta.glob('./dir/*.js', { as: 'raw' })
@@ -311,18 +313,115 @@ The above will be transformed into the following:
```js
// code produced by vite
const modules = {
- './dir/foo.js': '{\n "msg": "foo"\n}\n',
- './dir/bar.js': '{\n "msg": "bar"\n}\n'
+ './dir/foo.js': 'export default "foo"\n',
+ './dir/bar.js': 'export default "bar"\n'
+}
+```
+
+`{ as: 'url' }` is also supported for loading assets as URLs.
+
+### Multiple Patterns
+
+The first argument can be an array of globs, for example
+
+```js
+const modules = import.meta.glob(['./dir/*.js', './another/*.js'])
+```
+
+### Negative Patterns
+
+Negative glob patterns are also supported (prefixed with `!`). To ignore some files from the result, you can add exclude glob patterns to the first argument:
+
+```js
+const modules = import.meta.glob(['./dir/*.js', '!**/bar.js'])
+```
+
+```js
+// code produced by vite
+const modules = {
+ './dir/foo.js': () => import('./dir/foo.js')
+}
+```
+
+#### Named Imports
+
+It's possible to only import parts of the modules with the `import` options.
+
+```ts
+const modules = import.meta.glob('./dir/*.js', { import: 'setup' })
+```
+
+```ts
+// code produced by vite
+const modules = {
+ './dir/foo.js': () => import('./dir/foo.js').then((m) => m.setup),
+ './dir/bar.js': () => import('./dir/bar.js').then((m) => m.setup)
+}
+```
+
+When combined with `eager` it's even possible to have tree-shaking enabled for those modules.
+
+```ts
+const modules = import.meta.glob('./dir/*.js', { import: 'setup', eager: true })
+```
+
+```ts
+// code produced by vite:
+import { setup as __glob__0_0 } from './dir/foo.js'
+import { setup as __glob__0_1 } from './dir/bar.js'
+const modules = {
+ './dir/foo.js': __glob__0_0,
+ './dir/bar.js': __glob__0_1
+}
+```
+
+Set `import` to `default` to import the default export.
+
+```ts
+const modules = import.meta.glob('./dir/*.js', {
+ import: 'default',
+ eager: true
+})
+```
+
+```ts
+// code produced by vite:
+import __glob__0_0 from './dir/foo.js'
+import __glob__0_1 from './dir/bar.js'
+const modules = {
+ './dir/foo.js': __glob__0_0,
+ './dir/bar.js': __glob__0_1
+}
+```
+
+#### Custom Queries
+
+You can also use the `query` option to provide custom queries to imports for other plugins to consume.
+
+```ts
+const modules = import.meta.glob('./dir/*.js', {
+ query: { foo: 'bar', bar: true }
+})
+```
+
+```ts
+// code produced by vite:
+const modules = {
+ './dir/foo.js': () =>
+ import('./dir/foo.js?foo=bar&bar=true').then((m) => m.setup),
+ './dir/bar.js': () =>
+ import('./dir/bar.js?foo=bar&bar=true').then((m) => m.setup)
}
```
+### Glob Import Caveats
+
Note that:
- This is a Vite-only feature and is not a web or ES standard.
- The glob patterns are treated like import specifiers: they must be either relative (start with `./`) or absolute (start with `/`, resolved relative to project root) or an alias path (see [`resolve.alias` option](/config/#resolve-alias)).
-- The glob matching is done via `fast-glob` - check out its documentation for [supported glob patterns](https://github.com/mrmlnc/fast-glob#pattern-syntax).
-- You should also be aware that glob imports do not accept variables, you need to directly pass the string pattern.
-- The glob patterns cannot contain the same quote string (i.e. `'`, `"`, `` ` ``) as outer quotes, e.g. `'/Tom\'s files/**'`, use `"/Tom's files/**"` instead.
+- The glob matching is done via [`fast-glob`](https://github.com/mrmlnc/fast-glob) - check out its documentation for [supported glob patterns](https://github.com/mrmlnc/fast-glob#pattern-syntax).
+- You should also be aware that all the arguments in the `import.meta.glob` must be **passed as literals**. You can NOT use variables or expressions in them.
## WebAssembly
diff --git a/docs/guide/index.md b/docs/guide/index.md
index ff0d3f21b90e65..338bd42a565aa3 100644
--- a/docs/guide/index.md
+++ b/docs/guide/index.md
@@ -38,7 +38,7 @@ The supported template presets are:
## Scaffolding Your First Vite Project
::: tip Compatibility Note
-Vite requires [Node.js](https://nodejs.org/en/) version >=12.2.0. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
+Vite requires [Node.js](https://nodejs.org/en/) version >=14.6.0. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
:::
With NPM:
@@ -113,7 +113,7 @@ Running `vite` starts the dev server using the current working directory as root
## Command Line Interface
-In a project where Vite is installed, you can use the `vite` binary in your npm scripts, or run it directly with `npx vite`. Here is the default npm scripts in a scaffolded Vite project:
+In a project where Vite is installed, you can use the `vite` binary in your npm scripts, or run it directly with `npx vite`. Here are the default npm scripts in a scaffolded Vite project:
```json5
diff --git a/docs/guide/ssr.md b/docs/guide/ssr.md
index d1fca329abd58d..1abd4874bca0e2 100644
--- a/docs/guide/ssr.md
+++ b/docs/guide/ssr.md
@@ -22,8 +22,8 @@ If you have questions, the community is usually helpful at [Vite Discord's #ssr
Vite provides built-in support for server-side rendering (SSR). The Vite playground contains example SSR setups for Vue 3 and React, which can be used as references for this guide:
-- [Vue 3](https://github.com/vitejs/vite/tree/main/packages/playground/ssr-vue)
-- [React](https://github.com/vitejs/vite/tree/main/packages/playground/ssr-react)
+- [Vue 3](https://github.com/vitejs/vite/tree/main/playground/ssr-vue)
+- [React](https://github.com/vitejs/vite/tree/main/playground/ssr-react)
## Source Structure
@@ -177,7 +177,7 @@ Then, in `server.js` we need to add some production specific logic by checking `
- Move the creation and all usage of the `vite` dev server behind dev-only conditional branches, then add static file serving middlewares to serve files from `dist/client`.
-Refer to the [Vue](https://github.com/vitejs/vite/tree/main/packages/playground/ssr-vue) and [React](https://github.com/vitejs/vite/tree/main/packages/playground/ssr-react) demos for working setup.
+Refer to the [Vue](https://github.com/vitejs/vite/tree/main/playground/ssr-vue) and [React](https://github.com/vitejs/vite/tree/main/playground/ssr-react) demos for working setup.
## Generating Preload Directives
@@ -201,11 +201,11 @@ const html = await vueServerRenderer.renderToString(app, ctx)
// ctx.modules is now a Set of module IDs that were used during the render
```
-In the production branch of `server.js` we need to read and pass the manifest to the `render` function exported by `src/entry-server.js`. This would provide us with enough information to render preload directives for files used by async routes! See [demo source](https://github.com/vitejs/vite/blob/main/packages/playground/ssr-vue/src/entry-server.js) for full example.
+In the production branch of `server.js` we need to read and pass the manifest to the `render` function exported by `src/entry-server.js`. This would provide us with enough information to render preload directives for files used by async routes! See [demo source](https://github.com/vitejs/vite/blob/main/playground/ssr-vue/src/entry-server.js) for full example.
## Pre-Rendering / SSG
-If the routes and the data needed for certain routes are known ahead of time, we can pre-render these routes into static HTML using the same logic as production SSR. This can also be considered a form of Static-Site Generation (SSG). See [demo pre-render script](https://github.com/vitejs/vite/blob/main/packages/playground/ssr-vue/prerender.js) for working example.
+If the routes and the data needed for certain routes are known ahead of time, we can pre-render these routes into static HTML using the same logic as production SSR. This can also be considered a form of Static-Site Generation (SSG). See [demo pre-render script](https://github.com/vitejs/vite/blob/main/playground/ssr-vue/prerender.js) for working example.
## SSR Externals
diff --git a/jest.config.ts b/jest.config.ts
deleted file mode 100644
index 11663af4e08107..00000000000000
--- a/jest.config.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-// eslint-disable-next-line node/no-extraneous-import
-import type { Config } from '@jest/types'
-
-const config: Config.InitialOptions = {
- preset: 'ts-jest',
- testMatch: process.env.VITE_TEST_BUILD
- ? ['**/playground/**/*.spec.[jt]s?(x)']
- : ['**/*.spec.[jt]s?(x)'],
- testTimeout: process.env.CI ? 50000 : 20000,
- globalSetup: './scripts/jestGlobalSetup.cjs',
- globalTeardown: './scripts/jestGlobalTeardown.cjs',
- testEnvironment: './scripts/jestEnv.cjs',
- setupFilesAfterEnv: ['./scripts/jestPerTestSetup.ts'],
- watchPathIgnorePatterns: ['
+
+<inline>
- -<linked>: no import
-<linked>: with import
- -<imported>: no import
-<imported>: with import
- -<imported sass>
-<imported sass> with module
- -<imported less> with string additionalData
- -<imported stylus>
-Raw Support
+ +PostCSS source.input.from. Should include query
+ diff --git a/packages/playground/css/inline.module.css b/playground/css/inline.module.css similarity index 100% rename from packages/playground/css/inline.module.css rename to playground/css/inline.module.css diff --git a/packages/playground/css/inlined.css b/playground/css/inlined.css similarity index 100% rename from packages/playground/css/inlined.css rename to playground/css/inlined.css diff --git a/packages/playground/css/less.less b/playground/css/less.less similarity index 100% rename from packages/playground/css/less.less rename to playground/css/less.less diff --git a/packages/playground/css/less/components/form.less b/playground/css/less/components/form.less similarity index 100% rename from packages/playground/css/less/components/form.less rename to playground/css/less/components/form.less diff --git a/packages/playground/css/less/images/backgrounds/form-select.svg b/playground/css/less/images/backgrounds/form-select.svg similarity index 100% rename from packages/playground/css/less/images/backgrounds/form-select.svg rename to playground/css/less/images/backgrounds/form-select.svg diff --git a/packages/playground/css/linked-at-import.css b/playground/css/linked-at-import.css similarity index 100% rename from packages/playground/css/linked-at-import.css rename to playground/css/linked-at-import.css diff --git a/packages/playground/css/linked.css b/playground/css/linked.css similarity index 100% rename from packages/playground/css/linked.css rename to playground/css/linked.css diff --git a/packages/playground/css/main.js b/playground/css/main.js similarity index 89% rename from packages/playground/css/main.js rename to playground/css/main.js index 0d03aafbf0ec7f..90f74c96793c55 100644 --- a/packages/playground/css/main.js +++ b/playground/css/main.js @@ -80,10 +80,15 @@ text('.inlined-code', inlined) // glob const glob = import.meta.glob('./glob-import/*.css') -Promise.all(Object.keys(glob).map((key) => glob[key]())).then((res) => { +Promise.all( + Object.keys(glob).map((key) => glob[key]().then((i) => i.default)) +).then((res) => { text('.imported-css-glob', JSON.stringify(res, null, 2)) }) // globEager -const globEager = import.meta.globEager('./glob-import/*.css') +const globEager = import.meta.glob('./glob-import/*.css', { eager: true }) text('.imported-css-globEager', JSON.stringify(globEager, null, 2)) + +import postcssSourceInput from './postcss-source-input.css?query=foo' +text('.postcss-source-input', postcssSourceInput) diff --git a/packages/playground/css/minify.css b/playground/css/minify.css similarity index 100% rename from packages/playground/css/minify.css rename to playground/css/minify.css diff --git a/packages/playground/css/mod.module.css b/playground/css/mod.module.css similarity index 100% rename from packages/playground/css/mod.module.css rename to playground/css/mod.module.css diff --git a/packages/playground/css/mod.module.scss b/playground/css/mod.module.scss similarity index 100% rename from packages/playground/css/mod.module.scss rename to playground/css/mod.module.scss diff --git a/packages/playground/css/nested/_index.scss b/playground/css/nested/_index.scss similarity index 100% rename from packages/playground/css/nested/_index.scss rename to playground/css/nested/_index.scss diff --git a/packages/playground/css/nested/_partial.scss b/playground/css/nested/_partial.scss similarity index 100% rename from packages/playground/css/nested/_partial.scss rename to playground/css/nested/_partial.scss diff --git a/packages/playground/css/nested/css-in-less-2.less b/playground/css/nested/css-in-less-2.less similarity index 100% rename from packages/playground/css/nested/css-in-less-2.less rename to playground/css/nested/css-in-less-2.less diff --git a/packages/playground/css/nested/css-in-less.css b/playground/css/nested/css-in-less.css similarity index 100% rename from packages/playground/css/nested/css-in-less.css rename to playground/css/nested/css-in-less.css diff --git a/packages/playground/css/nested/css-in-less.less b/playground/css/nested/css-in-less.less similarity index 100% rename from packages/playground/css/nested/css-in-less.less rename to playground/css/nested/css-in-less.less diff --git a/packages/playground/css/nested/css-in-scss.css b/playground/css/nested/css-in-scss.css similarity index 100% rename from packages/playground/css/nested/css-in-scss.css rename to playground/css/nested/css-in-scss.css diff --git a/packages/playground/css/nested/icon.png b/playground/css/nested/icon.png similarity index 100% rename from packages/playground/css/nested/icon.png rename to playground/css/nested/icon.png diff --git a/packages/playground/css/nested/nested.less b/playground/css/nested/nested.less similarity index 100% rename from packages/playground/css/nested/nested.less rename to playground/css/nested/nested.less diff --git a/packages/playground/css/nested/nested.styl b/playground/css/nested/nested.styl similarity index 100% rename from packages/playground/css/nested/nested.styl rename to playground/css/nested/nested.styl diff --git a/packages/playground/css/ok.png b/playground/css/ok.png similarity index 100% rename from packages/playground/css/ok.png rename to playground/css/ok.png diff --git a/packages/playground/css/options/absolute-import.styl b/playground/css/options/absolute-import.styl similarity index 100% rename from packages/playground/css/options/absolute-import.styl rename to playground/css/options/absolute-import.styl diff --git a/packages/playground/css/options/relative-import.styl b/playground/css/options/relative-import.styl similarity index 100% rename from packages/playground/css/options/relative-import.styl rename to playground/css/options/relative-import.styl diff --git a/packages/playground/css/package.json b/playground/css/package.json similarity index 79% rename from packages/playground/css/package.json rename to playground/css/package.json index b45063100be089..daaad66a9bb41f 100644 --- a/packages/playground/css/package.json +++ b/playground/css/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" }, "devDependencies": { @@ -13,7 +13,7 @@ "fast-glob": "^3.2.11", "less": "^4.1.2", "postcss-nested": "^5.0.6", - "sass": "^1.43.4", + "sass": "^1.51.0", "stylus": "^0.55.0" } } diff --git a/packages/playground/css/pkg-dep/_index.scss b/playground/css/pkg-dep/_index.scss similarity index 100% rename from packages/playground/css/pkg-dep/_index.scss rename to playground/css/pkg-dep/_index.scss diff --git a/packages/playground/css/pkg-dep/index.js b/playground/css/pkg-dep/index.js similarity index 100% rename from packages/playground/css/pkg-dep/index.js rename to playground/css/pkg-dep/index.js diff --git a/packages/playground/css/pkg-dep/package.json b/playground/css/pkg-dep/package.json similarity index 100% rename from packages/playground/css/pkg-dep/package.json rename to playground/css/pkg-dep/package.json diff --git a/packages/playground/css/postcss-caching/blue-app/imported.css b/playground/css/postcss-caching/blue-app/imported.css similarity index 100% rename from packages/playground/css/postcss-caching/blue-app/imported.css rename to playground/css/postcss-caching/blue-app/imported.css diff --git a/packages/playground/css/postcss-caching/blue-app/index.html b/playground/css/postcss-caching/blue-app/index.html similarity index 100% rename from packages/playground/css/postcss-caching/blue-app/index.html rename to playground/css/postcss-caching/blue-app/index.html diff --git a/packages/playground/css/postcss-caching/blue-app/main.js b/playground/css/postcss-caching/blue-app/main.js similarity index 100% rename from packages/playground/css/postcss-caching/blue-app/main.js rename to playground/css/postcss-caching/blue-app/main.js diff --git a/packages/playground/css/postcss-caching/blue-app/package.json b/playground/css/postcss-caching/blue-app/package.json similarity index 71% rename from packages/playground/css/postcss-caching/blue-app/package.json rename to playground/css/postcss-caching/blue-app/package.json index 34be8916bb2c9e..82ba64fadd44b4 100644 --- a/packages/playground/css/postcss-caching/blue-app/package.json +++ b/playground/css/postcss-caching/blue-app/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" } } diff --git a/packages/playground/css/postcss-caching/blue-app/postcss.config.js b/playground/css/postcss-caching/blue-app/postcss.config.js similarity index 100% rename from packages/playground/css/postcss-caching/blue-app/postcss.config.js rename to playground/css/postcss-caching/blue-app/postcss.config.js diff --git a/packages/playground/css/postcss-caching/css.spec.ts b/playground/css/postcss-caching/css.spec.ts similarity index 96% rename from packages/playground/css/postcss-caching/css.spec.ts rename to playground/css/postcss-caching/css.spec.ts index e8ba73154b6bc8..bbffdb618280e4 100644 --- a/packages/playground/css/postcss-caching/css.spec.ts +++ b/playground/css/postcss-caching/css.spec.ts @@ -1,4 +1,4 @@ -import { getColor, ports } from '../../testUtils' +import { getColor, page, ports } from '~utils' import { createServer } from 'vite' import path from 'path' diff --git a/packages/playground/css/postcss-caching/green-app/imported.css b/playground/css/postcss-caching/green-app/imported.css similarity index 100% rename from packages/playground/css/postcss-caching/green-app/imported.css rename to playground/css/postcss-caching/green-app/imported.css diff --git a/packages/playground/css/postcss-caching/green-app/index.html b/playground/css/postcss-caching/green-app/index.html similarity index 100% rename from packages/playground/css/postcss-caching/green-app/index.html rename to playground/css/postcss-caching/green-app/index.html diff --git a/packages/playground/css/postcss-caching/green-app/main.js b/playground/css/postcss-caching/green-app/main.js similarity index 100% rename from packages/playground/css/postcss-caching/green-app/main.js rename to playground/css/postcss-caching/green-app/main.js diff --git a/packages/playground/css/postcss-caching/green-app/package.json b/playground/css/postcss-caching/green-app/package.json similarity index 71% rename from packages/playground/css/postcss-caching/green-app/package.json rename to playground/css/postcss-caching/green-app/package.json index 947b30384a1a53..72bd0f45b8865f 100644 --- a/packages/playground/css/postcss-caching/green-app/package.json +++ b/playground/css/postcss-caching/green-app/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" } } diff --git a/packages/playground/css/postcss-caching/green-app/postcss.config.js b/playground/css/postcss-caching/green-app/postcss.config.js similarity index 100% rename from packages/playground/css/postcss-caching/green-app/postcss.config.js rename to playground/css/postcss-caching/green-app/postcss.config.js diff --git a/playground/css/postcss-source-input.css b/playground/css/postcss-source-input.css new file mode 100644 index 00000000000000..c6c3cb0c16dece --- /dev/null +++ b/playground/css/postcss-source-input.css @@ -0,0 +1 @@ +@source-input; diff --git a/packages/playground/css/postcss.config.js b/playground/css/postcss.config.js similarity index 68% rename from packages/playground/css/postcss.config.js rename to playground/css/postcss.config.js index f3d6ac9548b6a9..33058023541515 100644 --- a/packages/playground/css/postcss.config.js +++ b/playground/css/postcss.config.js @@ -1,5 +1,5 @@ module.exports = { - plugins: [require('postcss-nested'), testDirDep] + plugins: [require('postcss-nested'), testDirDep, testSourceInput] } const fs = require('fs') @@ -35,3 +35,20 @@ function testDirDep() { } } testDirDep.postcss = true + +function testSourceInput() { + return { + postcssPlugin: 'source-input', + AtRule(atRule) { + if (atRule.name === 'source-input') { + atRule.after( + `.source-input::before { content: ${JSON.stringify( + atRule.source.input.from + )}; }` + ) + atRule.remove() + } + } + } +} +testSourceInput.postcss = true diff --git a/packages/playground/css/raw-imported.css b/playground/css/raw-imported.css similarity index 100% rename from packages/playground/css/raw-imported.css rename to playground/css/raw-imported.css diff --git a/packages/playground/css/sass.scss b/playground/css/sass.scss similarity index 100% rename from packages/playground/css/sass.scss rename to playground/css/sass.scss diff --git a/packages/playground/css/stylus.styl b/playground/css/stylus.styl similarity index 100% rename from packages/playground/css/stylus.styl rename to playground/css/stylus.styl diff --git a/packages/playground/css/vite.config.js b/playground/css/vite.config.js similarity index 100% rename from packages/playground/css/vite.config.js rename to playground/css/vite.config.js diff --git a/playground/data-uri/__tests__/data-uri.spec.ts b/playground/data-uri/__tests__/data-uri.spec.ts new file mode 100644 index 00000000000000..4b7f3d6e1e471b --- /dev/null +++ b/playground/data-uri/__tests__/data-uri.spec.ts @@ -0,0 +1,14 @@ +import { findAssetFile, isBuild, page } from '~utils' + +test('plain', async () => { + expect(await page.textContent('.plain')).toBe('hi') +}) + +test('base64', async () => { + expect(await page.textContent('.base64')).toBe('hi') +}) + +test.runIf(isBuild)('should compile away the import for build', async () => { + const file = findAssetFile('index') + expect(file).not.toMatch('import') +}) diff --git a/packages/playground/data-uri/index.html b/playground/data-uri/index.html similarity index 100% rename from packages/playground/data-uri/index.html rename to playground/data-uri/index.html diff --git a/packages/playground/data-uri/package.json b/playground/data-uri/package.json similarity index 72% rename from packages/playground/data-uri/package.json rename to playground/data-uri/package.json index a07c9a2cd6a663..4d30ad97b9acbb 100644 --- a/packages/playground/data-uri/package.json +++ b/playground/data-uri/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" } } diff --git a/packages/playground/define/__tests__/define.spec.ts b/playground/define/__tests__/define.spec.ts similarity index 64% rename from packages/playground/define/__tests__/define.spec.ts rename to playground/define/__tests__/define.spec.ts index 709f7a935dc8c1..b2eb571734cc54 100644 --- a/packages/playground/define/__tests__/define.spec.ts +++ b/playground/define/__tests__/define.spec.ts @@ -1,10 +1,16 @@ +import viteConfig from '../vite.config' +import { page } from '~utils' + test('string', async () => { - const defines = require('../vite.config.js').define + const defines = viteConfig.define - expect(await page.textContent('.exp')).toBe(String(eval(defines.__EXP__))) + expect(await page.textContent('.exp')).toBe( + String(typeof eval(defines.__EXP__)) + ) expect(await page.textContent('.string')).toBe(JSON.parse(defines.__STRING__)) expect(await page.textContent('.number')).toBe(String(defines.__NUMBER__)) expect(await page.textContent('.boolean')).toBe(String(defines.__BOOLEAN__)) + expect(await page.textContent('.object')).toBe( JSON.stringify(defines.__OBJ__, null, 2) ) @@ -20,6 +26,14 @@ test('string', async () => { expect(await page.textContent('.spread-array')).toBe( JSON.stringify([...defines.__STRING__]) ) + expect(await page.textContent('.dollar-identifier')).toBe( + String(defines.$DOLLAR) + ) + expect(await page.textContent('.unicode-identifier')).toBe( + String(defines.ÖUNICODE_LETTERɵ) + ) + expect(await page.textContent('.no-identifier-substring')).toBe(String(true)) + expect(await page.textContent('.no-property')).toBe(String(true)) // html would't need to define replacement expect(await page.textContent('.exp-define')).toBe('__EXP__') expect(await page.textContent('.import-json')).toBe('__EXP__') diff --git a/packages/playground/define/data.json b/playground/define/data.json similarity index 100% rename from packages/playground/define/data.json rename to playground/define/data.json diff --git a/packages/playground/define/index.html b/playground/define/index.html similarity index 68% rename from packages/playground/define/index.html rename to playground/define/index.html index da78d192216b11..97a7b9902a1dcb 100644 --- a/packages/playground/define/index.html +++ b/playground/define/index.html @@ -9,12 +9,16 @@process as property:
spread object:
spread array:
dollar identifier:
unicode identifier:
no property:
no identifier substring:
define variable in html: __EXP__
import json:
inline a
diff --git a/packages/playground/html/inline/unique.html b/playground/html/inline/unique.html similarity index 100% rename from packages/playground/html/inline/unique.html rename to playground/html/inline/unique.html diff --git a/packages/playground/html/inline/unique.js b/playground/html/inline/unique.js similarity index 100% rename from packages/playground/html/inline/unique.js rename to playground/html/inline/unique.js diff --git a/packages/playground/html/invalid.html b/playground/html/invalid.html similarity index 100% rename from packages/playground/html/invalid.html rename to playground/html/invalid.html diff --git a/packages/playground/html/link.html b/playground/html/link.html similarity index 100% rename from packages/playground/html/link.html rename to playground/html/link.html diff --git a/packages/playground/html/main.css b/playground/html/main.css similarity index 100% rename from packages/playground/html/main.css rename to playground/html/main.css diff --git a/packages/playground/html/main.js b/playground/html/main.js similarity index 100% rename from packages/playground/html/main.js rename to playground/html/main.js diff --git a/packages/playground/html/nested/index.html b/playground/html/nested/index.html similarity index 100% rename from packages/playground/html/nested/index.html rename to playground/html/nested/index.html diff --git a/packages/playground/html/nested/nested.css b/playground/html/nested/nested.css similarity index 100% rename from packages/playground/html/nested/nested.css rename to playground/html/nested/nested.css diff --git a/packages/playground/html/nested/nested.js b/playground/html/nested/nested.js similarity index 100% rename from packages/playground/html/nested/nested.js rename to playground/html/nested/nested.js diff --git a/packages/playground/html/noBody.html b/playground/html/noBody.html similarity index 100% rename from packages/playground/html/noBody.html rename to playground/html/noBody.html diff --git a/packages/playground/html/noHead.html b/playground/html/noHead.html similarity index 100% rename from packages/playground/html/noHead.html rename to playground/html/noHead.html diff --git a/packages/playground/html/package.json b/playground/html/package.json similarity index 71% rename from packages/playground/html/package.json rename to playground/html/package.json index a101033f8d3470..6db0bd91981ce0 100644 --- a/packages/playground/html/package.json +++ b/playground/html/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" } } diff --git a/packages/playground/html/scriptAsync.html b/playground/html/scriptAsync.html similarity index 100% rename from packages/playground/html/scriptAsync.html rename to playground/html/scriptAsync.html diff --git a/packages/playground/html/scriptMixed.html b/playground/html/scriptMixed.html similarity index 100% rename from packages/playground/html/scriptMixed.html rename to playground/html/scriptMixed.html diff --git a/packages/playground/html/shared.js b/playground/html/shared.js similarity index 100% rename from packages/playground/html/shared.js rename to playground/html/shared.js diff --git "a/packages/playground/html/unicode-path/\344\270\255\346\226\207-\343\201\253\343\201\273\343\202\223\343\201\224-\355\225\234\352\270\200-\360\237\214\225\360\237\214\226\360\237\214\227/index.html" "b/playground/html/unicode-path/\344\270\255\346\226\207-\343\201\253\343\201\273\343\202\223\343\201\224-\355\225\234\352\270\200-\360\237\214\225\360\237\214\226\360\237\214\227/index.html" similarity index 100% rename from "packages/playground/html/unicode-path/\344\270\255\346\226\207-\343\201\253\343\201\273\343\202\223\343\201\224-\355\225\234\352\270\200-\360\237\214\225\360\237\214\226\360\237\214\227/index.html" rename to "playground/html/unicode-path/\344\270\255\346\226\207-\343\201\253\343\201\273\343\202\223\343\201\224-\355\225\234\352\270\200-\360\237\214\225\360\237\214\226\360\237\214\227/index.html" diff --git a/packages/playground/html/vite.config.js b/playground/html/vite.config.js similarity index 98% rename from packages/playground/html/vite.config.js rename to playground/html/vite.config.js index 1703e02cc05366..bfe48675cbc18f 100644 --- a/packages/playground/html/vite.config.js +++ b/playground/html/vite.config.js @@ -17,6 +17,7 @@ module.exports = { zeroJS: resolve(__dirname, 'zeroJS.html'), noHead: resolve(__dirname, 'noHead.html'), noBody: resolve(__dirname, 'noBody.html'), + inlinea: resolve(__dirname, 'inline/shared_a.html'), inline1: resolve(__dirname, 'inline/shared-1.html'), inline2: resolve(__dirname, 'inline/shared-2.html'), inline3: resolve(__dirname, 'inline/unique.html'), diff --git a/packages/playground/html/zeroJS.html b/playground/html/zeroJS.html similarity index 100% rename from packages/playground/html/zeroJS.html rename to playground/html/zeroJS.html diff --git a/playground/js-sourcemap/__tests__/build.spec.ts b/playground/js-sourcemap/__tests__/build.spec.ts new file mode 100644 index 00000000000000..b30284731a76d9 --- /dev/null +++ b/playground/js-sourcemap/__tests__/build.spec.ts @@ -0,0 +1,7 @@ +import { isBuild, serverLogs } from '~utils' + +test.runIf(isBuild)('should not output sourcemap warning (#4939)', () => { + serverLogs.forEach((log) => { + expect(log).not.toMatch('Sourcemap is likely to be incorrect') + }) +}) diff --git a/packages/playground/js-sourcemap/__tests__/serve.spec.ts b/playground/js-sourcemap/__tests__/serve.spec.ts similarity index 91% rename from packages/playground/js-sourcemap/__tests__/serve.spec.ts rename to playground/js-sourcemap/__tests__/serve.spec.ts index a1ffdddc37ecd5..8f36f5f6f832f1 100644 --- a/packages/playground/js-sourcemap/__tests__/serve.spec.ts +++ b/playground/js-sourcemap/__tests__/serve.spec.ts @@ -2,8 +2,10 @@ import { URL } from 'url' import { extractSourcemap, formatSourcemapForSnapshot, - isBuild -} from 'testUtils' + isBuild, + page, + serverLogs +} from '~utils' if (!isBuild) { test('js', async () => { @@ -18,12 +20,12 @@ if (!isBuild) { const js = await res.text() const map = extractSourcemap(js) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": "AAAO,aAAM,MAAM;", - "sources": Array [ + "sources": [ "/root/bar.ts", ], - "sourcesContent": Array [ + "sourcesContent": [ "export const bar = 'bar' ", ], diff --git a/packages/playground/js-sourcemap/bar.ts b/playground/js-sourcemap/bar.ts similarity index 100% rename from packages/playground/js-sourcemap/bar.ts rename to playground/js-sourcemap/bar.ts diff --git a/packages/playground/js-sourcemap/foo.js b/playground/js-sourcemap/foo.js similarity index 100% rename from packages/playground/js-sourcemap/foo.js rename to playground/js-sourcemap/foo.js diff --git a/packages/playground/js-sourcemap/index.html b/playground/js-sourcemap/index.html similarity index 100% rename from packages/playground/js-sourcemap/index.html rename to playground/js-sourcemap/index.html diff --git a/packages/playground/js-sourcemap/package.json b/playground/js-sourcemap/package.json similarity index 72% rename from packages/playground/js-sourcemap/package.json rename to playground/js-sourcemap/package.json index e5a97aea80830f..92b166d2f302c2 100644 --- a/packages/playground/js-sourcemap/package.json +++ b/playground/js-sourcemap/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" } } diff --git a/packages/playground/js-sourcemap/vite.config.js b/playground/js-sourcemap/vite.config.js similarity index 100% rename from packages/playground/js-sourcemap/vite.config.js rename to playground/js-sourcemap/vite.config.js diff --git a/packages/playground/json/__tests__/json.spec.ts b/playground/json/__tests__/json.spec.ts similarity index 96% rename from packages/playground/json/__tests__/json.spec.ts rename to playground/json/__tests__/json.spec.ts index 2897ee22332e44..8c64d619361bfb 100644 --- a/packages/playground/json/__tests__/json.spec.ts +++ b/playground/json/__tests__/json.spec.ts @@ -1,7 +1,7 @@ -import { isBuild } from '../../testUtils' +import { isBuild, page } from '~utils' -const json = require('../test.json') const deepJson = require('vue/package.json') +const json = require('../test.json') const stringified = JSON.stringify(json) const deepStringified = JSON.stringify(deepJson) diff --git a/packages/playground/json/index.html b/playground/json/index.html similarity index 100% rename from packages/playground/json/index.html rename to playground/json/index.html diff --git a/packages/playground/json/json-module/index.json b/playground/json/json-module/index.json similarity index 100% rename from packages/playground/json/json-module/index.json rename to playground/json/json-module/index.json diff --git a/packages/playground/json/json-module/package.json b/playground/json/json-module/package.json similarity index 100% rename from packages/playground/json/json-module/package.json rename to playground/json/json-module/package.json diff --git a/playground/json/package.json b/playground/json/package.json new file mode 100644 index 00000000000000..b919c42eb6ef5d --- /dev/null +++ b/playground/json/package.json @@ -0,0 +1,20 @@ +{ + "name": "test-json", + "private": true, + "version": "0.0.0", + "scripts": { + "dev": "vite", + "build": "vite build", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", + "preview": "vite preview", + "dev:ssr": "node server", + "serve:ssr": "cross-env NODE_ENV=production node server", + "debug:ssr": "node --inspect-brk server" + }, + "devDependencies": { + "cross-env": "^7.0.3", + "express": "^4.17.1", + "json-module": "file:./json-module", + "vue": "^3.2.33" + } +} diff --git a/packages/playground/json/public/public.json b/playground/json/public/public.json similarity index 100% rename from packages/playground/json/public/public.json rename to playground/json/public/public.json diff --git a/packages/playground/json/test.json b/playground/json/test.json similarity index 100% rename from packages/playground/json/test.json rename to playground/json/test.json diff --git a/packages/playground/legacy/__tests__/legacy.spec.ts b/playground/legacy/__tests__/legacy.spec.ts similarity index 82% rename from packages/playground/legacy/__tests__/legacy.spec.ts rename to playground/legacy/__tests__/legacy.spec.ts index 65bd39ff32b1d1..b21f42afcbd7ed 100644 --- a/packages/playground/legacy/__tests__/legacy.spec.ts +++ b/playground/legacy/__tests__/legacy.spec.ts @@ -1,11 +1,12 @@ import { - listAssets, findAssetFile, + getColor, isBuild, + listAssets, + page, readManifest, - untilUpdated, - getColor -} from '../../testUtils' + untilUpdated +} from '~utils' test('should work', async () => { expect(await page.textContent('#app')).toMatch('Hello') @@ -56,12 +57,23 @@ test('correctly emits styles', async () => { expect(await getColor('#app')).toBe('red') }) -if (isBuild) { +// dynamic import css +test('should load dynamic import with css', async () => { + await page.click('#dynamic-css-button') + await untilUpdated( + () => + page.$eval('#dynamic-css', (node) => window.getComputedStyle(node).color), + 'rgb(255, 0, 0)', + true + ) +}) + +describe.runIf(isBuild)('build', () => { test('should generate correct manifest', async () => { const manifest = readManifest() - expect(manifest['../../../vite/legacy-polyfills']).toBeDefined() - expect(manifest['../../../vite/legacy-polyfills'].src).toBe( - '../../../vite/legacy-polyfills' + expect(manifest['../../vite/legacy-polyfills']).toBeDefined() + expect(manifest['../../vite/legacy-polyfills'].src).toBe( + '../../vite/legacy-polyfills' ) }) @@ -87,4 +99,4 @@ if (isBuild) { test('includes structuredClone polyfill which is supported after core-js v3', () => { expect(findAssetFile(/polyfills-legacy/)).toMatch('"structuredClone"') }) -} +}) diff --git a/packages/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts b/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts similarity index 65% rename from packages/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts rename to playground/legacy/__tests__/ssr/legacy-ssr.spec.ts index dad9b94d83509e..b5cfe82cd93910 100644 --- a/packages/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts +++ b/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts @@ -1,9 +1,9 @@ -import { isBuild } from '../../../testUtils' import { port } from './serve' +import { isBuild, page } from '~utils' const url = `http://localhost:${port}` -if (isBuild) { +describe.runIf(isBuild)('legacy-ssr', () => { test('should work', async () => { await page.goto(url) expect(await page.textContent('#app')).toMatch('Hello') @@ -13,8 +13,4 @@ if (isBuild) { // SSR build is always modern expect(await page.textContent('#env')).toMatch('false') }) -} else { - // this test doesn't support serve mode - // must contain at least one test - test('should work', () => void 0) -} +}) diff --git a/packages/playground/legacy/__tests__/ssr/serve.js b/playground/legacy/__tests__/ssr/serve.ts similarity index 72% rename from packages/playground/legacy/__tests__/ssr/serve.js rename to playground/legacy/__tests__/ssr/serve.ts index c7ef2ed3520e53..ec16b39e550965 100644 --- a/packages/playground/legacy/__tests__/ssr/serve.js +++ b/playground/legacy/__tests__/ssr/serve.ts @@ -1,16 +1,11 @@ -// @ts-check -// this is automtically detected by scripts/jestPerTestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior -const path = require('path') -const { ports } = require('../../../testUtils') +import path from 'path' +import { ports } from '~utils' -const port = (exports.port = ports['legacy/ssr']) +export const port = ports['legacy/ssr'] -/** - * @param {string} root - * @param {boolean} _isProd - */ -exports.serve = async function serve(root, _isProd) { +export async function serve(root: string, _isProd: boolean) { const { build } = require('vite') await build({ root, diff --git a/packages/playground/legacy/async.js b/playground/legacy/async.js similarity index 100% rename from packages/playground/legacy/async.js rename to playground/legacy/async.js diff --git a/playground/legacy/dynamic.css b/playground/legacy/dynamic.css new file mode 100644 index 00000000000000..160ee45a8a850a --- /dev/null +++ b/playground/legacy/dynamic.css @@ -0,0 +1,3 @@ +#dynamic-css { + color: red; +} diff --git a/packages/playground/legacy/entry-server.js b/playground/legacy/entry-server.js similarity index 100% rename from packages/playground/legacy/entry-server.js rename to playground/legacy/entry-server.js diff --git a/packages/playground/legacy/immutable-chunk.js b/playground/legacy/immutable-chunk.js similarity index 100% rename from packages/playground/legacy/immutable-chunk.js rename to playground/legacy/immutable-chunk.js diff --git a/packages/playground/legacy/index.html b/playground/legacy/index.html similarity index 72% rename from packages/playground/legacy/index.html rename to playground/legacy/index.html index d481766463cd4f..cbf6242fad756b 100644 --- a/packages/playground/legacy/index.html +++ b/playground/legacy/index.html @@ -4,4 +4,6 @@ + + diff --git a/packages/playground/legacy/main.js b/playground/legacy/main.js similarity index 84% rename from packages/playground/legacy/main.js rename to playground/legacy/main.js index 31579b4717810d..157b6c8448e9c3 100644 --- a/packages/playground/legacy/main.js +++ b/playground/legacy/main.js @@ -42,6 +42,14 @@ import('./immutable-chunk.js') text('#assets', assets.join('\n')) }) +// dynamic css +document + .querySelector('#dynamic-css-button') + .addEventListener('click', async () => { + await import('./dynamic.css') + text('#dynamic-css', 'dynamic import css') + }) + function text(el, text) { document.querySelector(el).textContent = text } diff --git a/packages/playground/legacy/package.json b/playground/legacy/package.json similarity index 65% rename from packages/playground/legacy/package.json rename to playground/legacy/package.json index 3a3315c42aa832..4f11c234573f40 100644 --- a/packages/playground/legacy/package.json +++ b/playground/legacy/package.json @@ -6,11 +6,12 @@ "dev": "vite", "build": "vite build --debug legacy", "build:custom-filename": "vite --config ./vite.config-custom-filename.js build --debug legacy", - "debug": "node --inspect-brk ../../vite/bin/vite", + "build:dynamic-css": "vite --config ./vite.config-dynamic-css.js build --debug legacy", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" }, "devDependencies": { "@vitejs/plugin-legacy": "workspace:*", - "express": "^4.17.1" + "express": "^4.18.1" } } diff --git a/packages/playground/legacy/style.css b/playground/legacy/style.css similarity index 100% rename from packages/playground/legacy/style.css rename to playground/legacy/style.css diff --git a/packages/playground/legacy/vite.config-custom-filename.js b/playground/legacy/vite.config-custom-filename.js similarity index 100% rename from packages/playground/legacy/vite.config-custom-filename.js rename to playground/legacy/vite.config-custom-filename.js diff --git a/playground/legacy/vite.config-dynamic-css.js b/playground/legacy/vite.config-dynamic-css.js new file mode 100644 index 00000000000000..10565768ac4d49 --- /dev/null +++ b/playground/legacy/vite.config-dynamic-css.js @@ -0,0 +1,39 @@ +const fs = require('fs') +const path = require('path') +const legacy = require('@vitejs/plugin-legacy').default + +module.exports = { + plugins: [ + legacy({ + targets: 'IE 11' + }) + ], + + build: { + cssCodeSplit: true, + manifest: true, + rollupOptions: { + output: { + chunkFileNames(chunkInfo) { + if (chunkInfo.name === 'immutable-chunk') { + return `assets/${chunkInfo.name}.js` + } + + return `assets/chunk-[name].[hash].js` + } + } + } + }, + + // special test only hook + // for tests, remove ` diff --git a/packages/playground/lib/index.html b/playground/lib/index.html similarity index 100% rename from packages/playground/lib/index.html rename to playground/lib/index.html diff --git a/packages/playground/lib/package.json b/playground/lib/package.json similarity index 72% rename from packages/playground/lib/package.json rename to playground/lib/package.json index 2c3ae4be3d4bcb..66b827b7c84179 100644 --- a/packages/playground/lib/package.json +++ b/playground/lib/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" } } diff --git a/playground/lib/src/dynamic.css b/playground/lib/src/dynamic.css new file mode 100644 index 00000000000000..4378c8d328cfbe --- /dev/null +++ b/playground/lib/src/dynamic.css @@ -0,0 +1,4 @@ +@import 'https://cdn.jsdelivr.net/npm/@mdi/font@5.9.55/css/materialdesignicons.min.css'; +.dynamic { + color: red; +} diff --git a/playground/lib/src/index.css b/playground/lib/src/index.css new file mode 100644 index 00000000000000..b0bd670bd9ecad --- /dev/null +++ b/playground/lib/src/index.css @@ -0,0 +1,3 @@ +.index { + color: blue; +} diff --git a/playground/lib/src/main.js b/playground/lib/src/main.js new file mode 100644 index 00000000000000..cb2fb3b842dc4f --- /dev/null +++ b/playground/lib/src/main.js @@ -0,0 +1,6 @@ +export default function myLib(sel) { + // Force esbuild spread helpers (https://github.com/evanw/esbuild/issues/951) + console.log({ ...'foo' }) + + document.querySelector(sel).textContent = 'It works' +} diff --git a/packages/playground/lib/src/main2.js b/playground/lib/src/main2.js similarity index 73% rename from packages/playground/lib/src/main2.js rename to playground/lib/src/main2.js index 0c729fad8d165c..f19a16bb128949 100644 --- a/packages/playground/lib/src/main2.js +++ b/playground/lib/src/main2.js @@ -1,4 +1,9 @@ +import './index.css' + export default async function message(sel) { const message = await import('./message.js') + + await import('./dynamic.css') + document.querySelector(sel).textContent = message.default } diff --git a/packages/playground/lib/src/message.js b/playground/lib/src/message.js similarity index 100% rename from packages/playground/lib/src/message.js rename to playground/lib/src/message.js diff --git a/packages/playground/lib/vite.config.js b/playground/lib/vite.config.js similarity index 89% rename from packages/playground/lib/vite.config.js rename to playground/lib/vite.config.js index 50cd188b1a40cc..72c040d38d6dcf 100644 --- a/packages/playground/lib/vite.config.js +++ b/playground/lib/vite.config.js @@ -10,7 +10,7 @@ module.exports = { entry: path.resolve(__dirname, 'src/main.js'), name: 'MyLib', formats: ['es', 'umd', 'iife'], - fileName: (format) => `my-lib-custom-filename.${format}.js` + fileName: 'my-lib-custom-filename' } }, plugins: [ diff --git a/packages/playground/lib/vite.dyimport.config.js b/playground/lib/vite.dyimport.config.js similarity index 94% rename from packages/playground/lib/vite.dyimport.config.js rename to playground/lib/vite.dyimport.config.js index 76311f4b8ba138..d738503f0c9d09 100644 --- a/packages/playground/lib/vite.dyimport.config.js +++ b/playground/lib/vite.dyimport.config.js @@ -6,7 +6,6 @@ const path = require('path') */ module.exports = { build: { - minify: false, lib: { entry: path.resolve(__dirname, 'src/main2.js'), formats: ['es'], diff --git a/packages/playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts b/playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts similarity index 84% rename from packages/playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts rename to playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts index 56c0b46c8a3e6f..e61c2187556f08 100644 --- a/packages/playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts +++ b/playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts @@ -1,4 +1,4 @@ -import { getColor, untilUpdated } from '../../testUtils' +import { getColor, page, untilUpdated } from '~utils' test('should have css applied on second dynamic import', async () => { await untilUpdated(() => page.textContent('.content'), 'Initial', true) diff --git a/packages/playground/multiple-entrypoints/deps.json b/playground/multiple-entrypoints/deps.json similarity index 100% rename from packages/playground/multiple-entrypoints/deps.json rename to playground/multiple-entrypoints/deps.json diff --git a/packages/playground/multiple-entrypoints/dynamic-a.js b/playground/multiple-entrypoints/dynamic-a.js similarity index 100% rename from packages/playground/multiple-entrypoints/dynamic-a.js rename to playground/multiple-entrypoints/dynamic-a.js diff --git a/packages/playground/multiple-entrypoints/dynamic-b.js b/playground/multiple-entrypoints/dynamic-b.js similarity index 100% rename from packages/playground/multiple-entrypoints/dynamic-b.js rename to playground/multiple-entrypoints/dynamic-b.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a0.js b/playground/multiple-entrypoints/entrypoints/a0.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a0.js rename to playground/multiple-entrypoints/entrypoints/a0.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a1.js b/playground/multiple-entrypoints/entrypoints/a1.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a1.js rename to playground/multiple-entrypoints/entrypoints/a1.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a10.js b/playground/multiple-entrypoints/entrypoints/a10.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a10.js rename to playground/multiple-entrypoints/entrypoints/a10.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a11.js b/playground/multiple-entrypoints/entrypoints/a11.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a11.js rename to playground/multiple-entrypoints/entrypoints/a11.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a12.js b/playground/multiple-entrypoints/entrypoints/a12.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a12.js rename to playground/multiple-entrypoints/entrypoints/a12.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a13.js b/playground/multiple-entrypoints/entrypoints/a13.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a13.js rename to playground/multiple-entrypoints/entrypoints/a13.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a14.js b/playground/multiple-entrypoints/entrypoints/a14.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a14.js rename to playground/multiple-entrypoints/entrypoints/a14.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a15.js b/playground/multiple-entrypoints/entrypoints/a15.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a15.js rename to playground/multiple-entrypoints/entrypoints/a15.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a16.js b/playground/multiple-entrypoints/entrypoints/a16.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a16.js rename to playground/multiple-entrypoints/entrypoints/a16.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a17.js b/playground/multiple-entrypoints/entrypoints/a17.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a17.js rename to playground/multiple-entrypoints/entrypoints/a17.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a18.js b/playground/multiple-entrypoints/entrypoints/a18.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a18.js rename to playground/multiple-entrypoints/entrypoints/a18.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a19.js b/playground/multiple-entrypoints/entrypoints/a19.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a19.js rename to playground/multiple-entrypoints/entrypoints/a19.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a2.js b/playground/multiple-entrypoints/entrypoints/a2.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a2.js rename to playground/multiple-entrypoints/entrypoints/a2.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a20.js b/playground/multiple-entrypoints/entrypoints/a20.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a20.js rename to playground/multiple-entrypoints/entrypoints/a20.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a21.js b/playground/multiple-entrypoints/entrypoints/a21.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a21.js rename to playground/multiple-entrypoints/entrypoints/a21.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a22.js b/playground/multiple-entrypoints/entrypoints/a22.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a22.js rename to playground/multiple-entrypoints/entrypoints/a22.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a23.js b/playground/multiple-entrypoints/entrypoints/a23.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a23.js rename to playground/multiple-entrypoints/entrypoints/a23.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a24.js b/playground/multiple-entrypoints/entrypoints/a24.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a24.js rename to playground/multiple-entrypoints/entrypoints/a24.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a3.js b/playground/multiple-entrypoints/entrypoints/a3.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a3.js rename to playground/multiple-entrypoints/entrypoints/a3.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a4.js b/playground/multiple-entrypoints/entrypoints/a4.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a4.js rename to playground/multiple-entrypoints/entrypoints/a4.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a5.js b/playground/multiple-entrypoints/entrypoints/a5.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a5.js rename to playground/multiple-entrypoints/entrypoints/a5.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a6.js b/playground/multiple-entrypoints/entrypoints/a6.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a6.js rename to playground/multiple-entrypoints/entrypoints/a6.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a7.js b/playground/multiple-entrypoints/entrypoints/a7.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a7.js rename to playground/multiple-entrypoints/entrypoints/a7.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a8.js b/playground/multiple-entrypoints/entrypoints/a8.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a8.js rename to playground/multiple-entrypoints/entrypoints/a8.js diff --git a/packages/playground/multiple-entrypoints/entrypoints/a9.js b/playground/multiple-entrypoints/entrypoints/a9.js similarity index 100% rename from packages/playground/multiple-entrypoints/entrypoints/a9.js rename to playground/multiple-entrypoints/entrypoints/a9.js diff --git a/packages/playground/multiple-entrypoints/index.html b/playground/multiple-entrypoints/index.html similarity index 100% rename from packages/playground/multiple-entrypoints/index.html rename to playground/multiple-entrypoints/index.html diff --git a/packages/playground/multiple-entrypoints/index.js b/playground/multiple-entrypoints/index.js similarity index 100% rename from packages/playground/multiple-entrypoints/index.js rename to playground/multiple-entrypoints/index.js diff --git a/packages/playground/multiple-entrypoints/package.json b/playground/multiple-entrypoints/package.json similarity index 72% rename from packages/playground/multiple-entrypoints/package.json rename to playground/multiple-entrypoints/package.json index 6c338a64518ddb..07818337be7bba 100644 --- a/packages/playground/multiple-entrypoints/package.json +++ b/playground/multiple-entrypoints/package.json @@ -5,11 +5,11 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" }, "devDependencies": { "fast-glob": "^3.2.11", - "sass": "^1.43.4" + "sass": "^1.51.0" } } diff --git a/packages/playground/multiple-entrypoints/reference.js b/playground/multiple-entrypoints/reference.js similarity index 100% rename from packages/playground/multiple-entrypoints/reference.js rename to playground/multiple-entrypoints/reference.js diff --git a/packages/playground/multiple-entrypoints/reference.scss b/playground/multiple-entrypoints/reference.scss similarity index 100% rename from packages/playground/multiple-entrypoints/reference.scss rename to playground/multiple-entrypoints/reference.scss diff --git a/packages/playground/multiple-entrypoints/vite.config.js b/playground/multiple-entrypoints/vite.config.js similarity index 100% rename from packages/playground/multiple-entrypoints/vite.config.js rename to playground/multiple-entrypoints/vite.config.js diff --git a/packages/playground/nested-deps/__tests__/nested-deps.spec.ts b/playground/nested-deps/__tests__/nested-deps.spec.ts similarity index 94% rename from packages/playground/nested-deps/__tests__/nested-deps.spec.ts rename to playground/nested-deps/__tests__/nested-deps.spec.ts index 2ef0e191da7b50..e4adb68792d116 100644 --- a/packages/playground/nested-deps/__tests__/nested-deps.spec.ts +++ b/playground/nested-deps/__tests__/nested-deps.spec.ts @@ -1,3 +1,5 @@ +import { page } from '~utils' + test('handle nested package', async () => { expect(await page.textContent('.a')).toBe('A@2.0.0') expect(await page.textContent('.b')).toBe('B@1.0.0') diff --git a/packages/playground/nested-deps/index.html b/playground/nested-deps/index.html similarity index 100% rename from packages/playground/nested-deps/index.html rename to playground/nested-deps/index.html diff --git a/packages/playground/nested-deps/package.json b/playground/nested-deps/package.json similarity index 87% rename from packages/playground/nested-deps/package.json rename to playground/nested-deps/package.json index d7450d0545fcb4..cbfcfe44df551b 100644 --- a/packages/playground/nested-deps/package.json +++ b/playground/nested-deps/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" }, "dependencies": { diff --git a/packages/playground/nested-deps/test-package-a/index.js b/playground/nested-deps/test-package-a/index.js similarity index 100% rename from packages/playground/nested-deps/test-package-a/index.js rename to playground/nested-deps/test-package-a/index.js diff --git a/packages/playground/nested-deps/test-package-a/package.json b/playground/nested-deps/test-package-a/package.json similarity index 100% rename from packages/playground/nested-deps/test-package-a/package.json rename to playground/nested-deps/test-package-a/package.json diff --git a/packages/playground/nested-deps/test-package-b/index.js b/playground/nested-deps/test-package-b/index.js similarity index 100% rename from packages/playground/nested-deps/test-package-b/index.js rename to playground/nested-deps/test-package-b/index.js diff --git a/packages/playground/nested-deps/test-package-b/node_modules/test-package-a/index.js b/playground/nested-deps/test-package-b/node_modules/test-package-a/index.js similarity index 100% rename from packages/playground/nested-deps/test-package-b/node_modules/test-package-a/index.js rename to playground/nested-deps/test-package-b/node_modules/test-package-a/index.js diff --git a/packages/playground/nested-deps/test-package-b/node_modules/test-package-a/package.json b/playground/nested-deps/test-package-b/node_modules/test-package-a/package.json similarity index 100% rename from packages/playground/nested-deps/test-package-b/node_modules/test-package-a/package.json rename to playground/nested-deps/test-package-b/node_modules/test-package-a/package.json diff --git a/packages/playground/nested-deps/test-package-b/package.json b/playground/nested-deps/test-package-b/package.json similarity index 100% rename from packages/playground/nested-deps/test-package-b/package.json rename to playground/nested-deps/test-package-b/package.json diff --git a/packages/playground/nested-deps/test-package-c/index-es.js b/playground/nested-deps/test-package-c/index-es.js similarity index 100% rename from packages/playground/nested-deps/test-package-c/index-es.js rename to playground/nested-deps/test-package-c/index-es.js diff --git a/packages/playground/nested-deps/test-package-c/index.js b/playground/nested-deps/test-package-c/index.js similarity index 100% rename from packages/playground/nested-deps/test-package-c/index.js rename to playground/nested-deps/test-package-c/index.js diff --git a/packages/playground/nested-deps/test-package-c/package.json b/playground/nested-deps/test-package-c/package.json similarity index 100% rename from packages/playground/nested-deps/test-package-c/package.json rename to playground/nested-deps/test-package-c/package.json diff --git a/packages/playground/nested-deps/test-package-c/side.js b/playground/nested-deps/test-package-c/side.js similarity index 100% rename from packages/playground/nested-deps/test-package-c/side.js rename to playground/nested-deps/test-package-c/side.js diff --git a/packages/playground/nested-deps/test-package-d/index.js b/playground/nested-deps/test-package-d/index.js similarity index 100% rename from packages/playground/nested-deps/test-package-d/index.js rename to playground/nested-deps/test-package-d/index.js diff --git a/packages/playground/nested-deps/test-package-d/package.json b/playground/nested-deps/test-package-d/package.json similarity index 100% rename from packages/playground/nested-deps/test-package-d/package.json rename to playground/nested-deps/test-package-d/package.json diff --git a/packages/playground/nested-deps/test-package-d/test-package-d-nested/index.js b/playground/nested-deps/test-package-d/test-package-d-nested/index.js similarity index 100% rename from packages/playground/nested-deps/test-package-d/test-package-d-nested/index.js rename to playground/nested-deps/test-package-d/test-package-d-nested/index.js diff --git a/packages/playground/nested-deps/test-package-d/test-package-d-nested/package.json b/playground/nested-deps/test-package-d/test-package-d-nested/package.json similarity index 100% rename from packages/playground/nested-deps/test-package-d/test-package-d-nested/package.json rename to playground/nested-deps/test-package-d/test-package-d-nested/package.json diff --git a/packages/playground/nested-deps/test-package-e/index.js b/playground/nested-deps/test-package-e/index.js similarity index 100% rename from packages/playground/nested-deps/test-package-e/index.js rename to playground/nested-deps/test-package-e/index.js diff --git a/packages/playground/nested-deps/test-package-e/package.json b/playground/nested-deps/test-package-e/package.json similarity index 100% rename from packages/playground/nested-deps/test-package-e/package.json rename to playground/nested-deps/test-package-e/package.json diff --git a/packages/playground/nested-deps/test-package-e/test-package-e-excluded/index.js b/playground/nested-deps/test-package-e/test-package-e-excluded/index.js similarity index 100% rename from packages/playground/nested-deps/test-package-e/test-package-e-excluded/index.js rename to playground/nested-deps/test-package-e/test-package-e-excluded/index.js diff --git a/packages/playground/nested-deps/test-package-e/test-package-e-excluded/package.json b/playground/nested-deps/test-package-e/test-package-e-excluded/package.json similarity index 100% rename from packages/playground/nested-deps/test-package-e/test-package-e-excluded/package.json rename to playground/nested-deps/test-package-e/test-package-e-excluded/package.json diff --git a/packages/playground/nested-deps/test-package-e/test-package-e-included/index.js b/playground/nested-deps/test-package-e/test-package-e-included/index.js similarity index 100% rename from packages/playground/nested-deps/test-package-e/test-package-e-included/index.js rename to playground/nested-deps/test-package-e/test-package-e-included/index.js diff --git a/packages/playground/nested-deps/test-package-e/test-package-e-included/package.json b/playground/nested-deps/test-package-e/test-package-e-included/package.json similarity index 100% rename from packages/playground/nested-deps/test-package-e/test-package-e-included/package.json rename to playground/nested-deps/test-package-e/test-package-e-included/package.json diff --git a/packages/playground/nested-deps/vite.config.js b/playground/nested-deps/vite.config.js similarity index 100% rename from packages/playground/nested-deps/vite.config.js rename to playground/nested-deps/vite.config.js diff --git a/playground/optimize-deps/.env b/playground/optimize-deps/.env new file mode 100644 index 00000000000000..995fca4af2ee24 --- /dev/null +++ b/playground/optimize-deps/.env @@ -0,0 +1 @@ +NODE_ENV=production \ No newline at end of file diff --git a/packages/playground/optimize-deps/.hidden-dir/foo.js b/playground/optimize-deps/.hidden-dir/foo.js similarity index 100% rename from packages/playground/optimize-deps/.hidden-dir/foo.js rename to playground/optimize-deps/.hidden-dir/foo.js diff --git a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts b/playground/optimize-deps/__tests__/optimize-deps.spec.ts similarity index 95% rename from packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts rename to playground/optimize-deps/__tests__/optimize-deps.spec.ts index d95a6d984cd9aa..898d75f6bf9f0d 100644 --- a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts +++ b/playground/optimize-deps/__tests__/optimize-deps.spec.ts @@ -1,4 +1,4 @@ -import { getColor, isBuild } from '../../testUtils' +import { getColor, isBuild, page } from '~utils' test('default + named imports from cjs dep (react)', async () => { expect(await page.textContent('.cjs button')).toBe('count is 0') @@ -62,6 +62,10 @@ test('import * from optimized dep', async () => { expect(await page.textContent('.import-star')).toMatch(`[success]`) }) +test('import from dep with process.env.NODE_ENV', async () => { + expect(await page.textContent('.node-env')).toMatch(`prod`) +}) + test('import from dep with .notjs files', async () => { expect(await page.textContent('.not-js')).toMatch(`[success]`) }) diff --git a/packages/playground/optimize-deps/cjs-dynamic.js b/playground/optimize-deps/cjs-dynamic.js similarity index 100% rename from packages/playground/optimize-deps/cjs-dynamic.js rename to playground/optimize-deps/cjs-dynamic.js diff --git a/packages/playground/optimize-deps/cjs.js b/playground/optimize-deps/cjs.js similarity index 100% rename from packages/playground/optimize-deps/cjs.js rename to playground/optimize-deps/cjs.js diff --git a/packages/playground/optimize-deps/dedupe.js b/playground/optimize-deps/dedupe.js similarity index 100% rename from packages/playground/optimize-deps/dedupe.js rename to playground/optimize-deps/dedupe.js diff --git a/packages/playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js b/playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js similarity index 100% rename from packages/playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js rename to playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js diff --git a/packages/playground/optimize-deps/dep-cjs-compiled-from-cjs/package.json b/playground/optimize-deps/dep-cjs-compiled-from-cjs/package.json similarity index 100% rename from packages/playground/optimize-deps/dep-cjs-compiled-from-cjs/package.json rename to playground/optimize-deps/dep-cjs-compiled-from-cjs/package.json diff --git a/packages/playground/optimize-deps/dep-cjs-compiled-from-esm/index.js b/playground/optimize-deps/dep-cjs-compiled-from-esm/index.js similarity index 100% rename from packages/playground/optimize-deps/dep-cjs-compiled-from-esm/index.js rename to playground/optimize-deps/dep-cjs-compiled-from-esm/index.js diff --git a/packages/playground/optimize-deps/dep-cjs-compiled-from-esm/package.json b/playground/optimize-deps/dep-cjs-compiled-from-esm/package.json similarity index 100% rename from packages/playground/optimize-deps/dep-cjs-compiled-from-esm/package.json rename to playground/optimize-deps/dep-cjs-compiled-from-esm/package.json diff --git a/packages/playground/optimize-deps/dep-esbuild-plugin-transform/index.js b/playground/optimize-deps/dep-esbuild-plugin-transform/index.js similarity index 100% rename from packages/playground/optimize-deps/dep-esbuild-plugin-transform/index.js rename to playground/optimize-deps/dep-esbuild-plugin-transform/index.js diff --git a/packages/playground/optimize-deps/dep-esbuild-plugin-transform/package.json b/playground/optimize-deps/dep-esbuild-plugin-transform/package.json similarity index 100% rename from packages/playground/optimize-deps/dep-esbuild-plugin-transform/package.json rename to playground/optimize-deps/dep-esbuild-plugin-transform/package.json diff --git a/packages/playground/optimize-deps/dep-linked-include/Test.vue b/playground/optimize-deps/dep-linked-include/Test.vue similarity index 100% rename from packages/playground/optimize-deps/dep-linked-include/Test.vue rename to playground/optimize-deps/dep-linked-include/Test.vue diff --git a/packages/playground/optimize-deps/dep-linked-include/foo.js b/playground/optimize-deps/dep-linked-include/foo.js similarity index 100% rename from packages/playground/optimize-deps/dep-linked-include/foo.js rename to playground/optimize-deps/dep-linked-include/foo.js diff --git a/packages/playground/optimize-deps/dep-linked-include/index.mjs b/playground/optimize-deps/dep-linked-include/index.mjs similarity index 100% rename from packages/playground/optimize-deps/dep-linked-include/index.mjs rename to playground/optimize-deps/dep-linked-include/index.mjs diff --git a/packages/playground/optimize-deps/dep-linked-include/package.json b/playground/optimize-deps/dep-linked-include/package.json similarity index 100% rename from packages/playground/optimize-deps/dep-linked-include/package.json rename to playground/optimize-deps/dep-linked-include/package.json diff --git a/packages/playground/optimize-deps/dep-linked-include/test.css b/playground/optimize-deps/dep-linked-include/test.css similarity index 100% rename from packages/playground/optimize-deps/dep-linked-include/test.css rename to playground/optimize-deps/dep-linked-include/test.css diff --git a/packages/playground/optimize-deps/dep-linked/index.js b/playground/optimize-deps/dep-linked/index.js similarity index 100% rename from packages/playground/optimize-deps/dep-linked/index.js rename to playground/optimize-deps/dep-linked/index.js diff --git a/packages/playground/optimize-deps/dep-linked/package.json b/playground/optimize-deps/dep-linked/package.json similarity index 100% rename from packages/playground/optimize-deps/dep-linked/package.json rename to playground/optimize-deps/dep-linked/package.json diff --git a/playground/optimize-deps/dep-node-env/index.js b/playground/optimize-deps/dep-node-env/index.js new file mode 100644 index 00000000000000..8548c37894539f --- /dev/null +++ b/playground/optimize-deps/dep-node-env/index.js @@ -0,0 +1 @@ +export const env = process.env.NODE_ENV === 'production' ? 'prod' : 'dev' diff --git a/playground/optimize-deps/dep-node-env/package.json b/playground/optimize-deps/dep-node-env/package.json new file mode 100644 index 00000000000000..59a00fb153c522 --- /dev/null +++ b/playground/optimize-deps/dep-node-env/package.json @@ -0,0 +1,5 @@ +{ + "name": "dep-node-env", + "private": true, + "version": "1.0.0" +} diff --git a/packages/playground/optimize-deps/dep-not-js/foo.js b/playground/optimize-deps/dep-not-js/foo.js similarity index 100% rename from packages/playground/optimize-deps/dep-not-js/foo.js rename to playground/optimize-deps/dep-not-js/foo.js diff --git a/packages/playground/optimize-deps/dep-not-js/index.notjs b/playground/optimize-deps/dep-not-js/index.notjs similarity index 100% rename from packages/playground/optimize-deps/dep-not-js/index.notjs rename to playground/optimize-deps/dep-not-js/index.notjs diff --git a/packages/playground/optimize-deps/dep-not-js/package.json b/playground/optimize-deps/dep-not-js/package.json similarity index 100% rename from packages/playground/optimize-deps/dep-not-js/package.json rename to playground/optimize-deps/dep-not-js/package.json diff --git a/packages/playground/optimize-deps/dep-with-dynamic-import/dynamic.js b/playground/optimize-deps/dep-with-dynamic-import/dynamic.js similarity index 100% rename from packages/playground/optimize-deps/dep-with-dynamic-import/dynamic.js rename to playground/optimize-deps/dep-with-dynamic-import/dynamic.js diff --git a/packages/playground/optimize-deps/dep-with-dynamic-import/index.js b/playground/optimize-deps/dep-with-dynamic-import/index.js similarity index 100% rename from packages/playground/optimize-deps/dep-with-dynamic-import/index.js rename to playground/optimize-deps/dep-with-dynamic-import/index.js diff --git a/packages/playground/optimize-deps/dep-with-dynamic-import/package.json b/playground/optimize-deps/dep-with-dynamic-import/package.json similarity index 100% rename from packages/playground/optimize-deps/dep-with-dynamic-import/package.json rename to playground/optimize-deps/dep-with-dynamic-import/package.json diff --git a/packages/playground/optimize-deps/glob/foo.js b/playground/optimize-deps/glob/foo.js similarity index 100% rename from packages/playground/optimize-deps/glob/foo.js rename to playground/optimize-deps/glob/foo.js diff --git a/packages/playground/optimize-deps/index.html b/playground/optimize-deps/index.html similarity index 94% rename from packages/playground/optimize-deps/index.html rename to playground/optimize-deps/index.html index 2be896d00acba9..d11383bfcb3e04 100644 --- a/packages/playground/optimize-deps/index.html +++ b/playground/optimize-deps/index.html @@ -38,6 +38,9 @@