From 5d180db4bd19e26de20bb816d594226b4d492804 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 9 Jan 2021 22:26:27 -0500 Subject: [PATCH 001/514] fix(optimizer): properly externalize css/asset imports in optimized deps fix #1443 --- .../optimize-deps-linked-include/index.js | 3 +++ .../optimize-deps-linked-include/test.css | 3 +++ .../__tests__/optimize-deps.spec.ts | 6 ++++++ packages/playground/optimize-deps/index.html | 16 +++++++-------- .../vite/src/node/optimizer/depAssetPlugin.ts | 20 ++++++++++++------- packages/vite/src/node/optimizer/index.ts | 4 ++-- packages/vite/src/node/plugins/resolve.ts | 2 +- 7 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 packages/playground/optimize-deps-linked-include/test.css diff --git a/packages/playground/optimize-deps-linked-include/index.js b/packages/playground/optimize-deps-linked-include/index.js index 74c1e295715f63..508a908abefa6a 100644 --- a/packages/playground/optimize-deps-linked-include/index.js +++ b/packages/playground/optimize-deps-linked-include/index.js @@ -5,3 +5,6 @@ import { useState } from 'react' export function useCount() { return useState(0) } + +// test dep with css/asset imports +import './test.css' diff --git a/packages/playground/optimize-deps-linked-include/test.css b/packages/playground/optimize-deps-linked-include/test.css new file mode 100644 index 00000000000000..b719c608467fdd --- /dev/null +++ b/packages/playground/optimize-deps-linked-include/test.css @@ -0,0 +1,3 @@ +body { + color: red; +} \ No newline at end of file diff --git a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts b/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts index f7616fb9d6be71..9623590c007b7b 100644 --- a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts +++ b/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts @@ -1,3 +1,5 @@ +import { getColor } from '../../testUtils' + test('default + named imports from cjs dep (react)', async () => { expect(await page.textContent('.cjs button')).toBe('count is 0') await page.click('.cjs button') @@ -27,3 +29,7 @@ test('dep from linked dep (lodash-es)', async () => { test('forced include', async () => { expect(await page.textContent('.force-include')).toMatch(`[success]`) }) + +test('dep with css import', async () => { + expect(await getColor('h1')).toBe('red') +}) diff --git a/packages/playground/optimize-deps/index.html b/packages/playground/optimize-deps/index.html index d79167fa82bf80..7e881b1daeabab 100644 --- a/packages/playground/optimize-deps/index.html +++ b/packages/playground/optimize-deps/index.html @@ -22,15 +22,15 @@

Optimizing force included dep even when it's linked

diff --git a/packages/vite/src/node/optimizer/depAssetPlugin.ts b/packages/vite/src/node/optimizer/depAssetPlugin.ts index 3922a204387f6d..e3b21d42c71b83 100644 --- a/packages/vite/src/node/optimizer/depAssetPlugin.ts +++ b/packages/vite/src/node/optimizer/depAssetPlugin.ts @@ -3,8 +3,9 @@ import { Plugin } from 'rollup' import { init, parse } from 'es-module-lexer' import { isCSSRequest } from '../plugins/css' import MagicString from 'magic-string' -import { bareImportRE, normalizePath, resolveFrom } from '../utils' +import { normalizePath } from '../utils' import { ResolvedConfig } from '../config' +import { idToPkgMap } from '../plugins/resolve' export const depAssetExternalPlugin = (config: ResolvedConfig): Plugin => ({ name: 'vite:dep-assets-external', @@ -47,12 +48,17 @@ export const depAssetRewritePlugin = (config: ResolvedConfig): Plugin => { s.remove(statementStart, statementEnd) continue } - const deepPath = `/@fs/${normalizePath( - bareImportRE.test(importee) - ? resolveFrom(config.root, importee) - : path.resolve(path.dirname(id), importee) - )}` - s.overwrite(start, end, deepPath) + if (importee.startsWith('.')) { + const pkg = idToPkgMap.get(id) + if (pkg) { + const fsPath = path.resolve(path.dirname(id), importee) + const deepPath = + pkg.data.name + + '/' + + normalizePath(path.relative(pkg.dir, fsPath)) + s.overwrite(start, end, deepPath) + } + } } } else { // ignore dynamic import diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 195d031605b65a..380f88bfda4310 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -326,12 +326,12 @@ async function resolveQualifiedDeps( if (i.startsWith('.')) { debug(`optimizing ${id} (contains relative imports)`) qualified[id] = filePath - continue + break } if (!deps.includes(i)) { debug(`optimizing ${id} (imports sub dependencies)`) qualified[id] = filePath - continue + break } } debug(`skipping ${id} (single esm file, doesn't need optimization)`) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index a092b0600446ec..c9c8956bc05a67 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -221,7 +221,7 @@ function tryResolveFile( } } -const idToPkgMap = new Map() +export const idToPkgMap = new Map() export function tryNodeResolve( id: string, From 8b8d5061ea44affd3b9bed97da2e629254a6ec28 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 9 Jan 2021 22:53:51 -0500 Subject: [PATCH 002/514] refactor(optimizer): adjust node built-in handling - prefer resolved if resolvable - externalize to empty module when not resolved - better plugin warning handling --- docs/config/index.md | 14 +--- .../optimize-deps-linked-include/index.js | 9 +++ packages/vite/src/node/build.ts | 79 ++++++------------- packages/vite/src/node/optimizer/index.ts | 35 +++----- packages/vite/src/node/plugins/resolve.ts | 25 ++++-- 5 files changed, 59 insertions(+), 103 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 336e83984b31e8..6507755e824364 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -415,22 +415,10 @@ export default ({ command, mode }) => { ### optimizeDeps.exclude -- **Type:** `string[]` +- **Type:** `string | RegExp | (string | RegExp)[]` Dependencies to force exclude in pre-bundling. -### optimizeDeps.link - -- **Type:** `string[]` - - Dependencies to be explicitly treated as linked source in pre-bundling. Note Vite 2.0 automatically detects linked packages (deps whose resolved path is not inside `node_modules`) so this should only be needed in rare cases. - -### optimizeDeps.allowNodeBuiltins - -- **Type:** `string[]` - - A list of dependencies that imports Node built-ins, but do not actually use them in browsers. Suppresses related warnings. - ### optimizeDeps.auto - **Type:** `boolean` diff --git a/packages/playground/optimize-deps-linked-include/index.js b/packages/playground/optimize-deps-linked-include/index.js index 508a908abefa6a..a869157f53ed1b 100644 --- a/packages/playground/optimize-deps-linked-include/index.js +++ b/packages/playground/optimize-deps-linked-include/index.js @@ -8,3 +8,12 @@ export function useCount() { // test dep with css/asset imports import './test.css' + +// test importing node built-ins +import fs from 'fs' + +if (false) { + fs.readFileSync() +} else { + console.log('ok') +} diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 0c953b276f7c58..d8ef6812574f4f 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -8,7 +8,6 @@ import Rollup, { RollupOptions, RollupWarning, WarningHandler, - WarningHandlerWithDefault, OutputOptions, RollupOutput } from 'rollup' @@ -22,7 +21,6 @@ import { copyDir, emptyDir, lookupFile } from './utils' import { manifestPlugin } from './plugins/manifest' import commonjsPlugin from '@rollup/plugin-commonjs' import dynamicImportVars from '@rollup/plugin-dynamic-import-vars' -import isBuiltin from 'isbuiltin' import { Logger } from './logger' import { TransformOptions } from 'esbuild' import { CleanCSS } from 'types/clean-css' @@ -280,12 +278,7 @@ async function doBuild( ...options.rollupOptions, plugins: config.plugins as Plugin[], onwarn(warning, warn) { - onRollupWarning( - warning, - warn, - config.optimizeDeps?.allowNodeBuiltins, - options.rollupOptions?.onwarn - ) + onRollupWarning(warning, warn, config) } }) @@ -397,59 +390,20 @@ const dynamicImportWarningIgnoreList = [ export function onRollupWarning( warning: RollupWarning, warn: WarningHandler, - allowNodeBuiltins: string[] = [], - userOnWarn?: WarningHandlerWithDefault + config: ResolvedConfig ) { - function doWarn() { - if (userOnWarn) { - userOnWarn(warning, warn) - } else { - warn(warning) - } - } - if (warning.code === 'UNRESOLVED_IMPORT') { - let message: string const id = warning.source const importer = warning.importer - - if (importer && /\?commonjs-external$/.test(importer)) { - // allow commonjs external... - warning.message = chalk.yellow(warning.message) - return doWarn() - } - - if (id && isBuiltin(id)) { - let importingDep: string | undefined - if (importer) { - const pkg = JSON.parse(lookupFile(importer, ['package.json']) || `{}`) - if (pkg.name) { - importingDep = pkg.name - } - } - if ( - importingDep && - allowNodeBuiltins.some((allowed) => importingDep!.startsWith(allowed)) - ) { - return - } - const dep = importingDep - ? `Dependency ${chalk.yellow(importingDep)}` - : `A dependency` - message = - `${dep} is attempting to import Node built-in module ${chalk.yellow( - id - )}.\n` + - `This will not work in a browser environment.\n` + - `Imported by: ${chalk.gray(importer)}` - } else { - message = - `[vite]: Rollup failed to resolve import "${warning.source}" from "${warning.importer}".\n` + - `This is most likely unintended because it can break your application at runtime.\n` + - `If you do want to externalize this module explicitly add it to\n` + - `\`build.rollupOptions.external\`` + // throw unless it's commonjs external... + if (!importer || !/\?commonjs-external$/.test(importer)) { + throw new Error( + `[vite]: Rollup failed to resolve import "${id}" from "${importer}".\n` + + `This is most likely unintended because it can break your application at runtime.\n` + + `If you do want to externalize this module explicitly add it to\n` + + `\`build.rollupOptions.external\`` + ) } - throw new Error(message) } if ( @@ -460,6 +414,17 @@ export function onRollupWarning( } if (!warningIgnoreList.includes(warning.code!)) { - doWarn() + const userOnWarn = config.build.rollupOptions?.onwarn + if (userOnWarn) { + userOnWarn(warning, warn) + } else if (warning.code === 'PLUGIN_WARNING') { + config.logger.warn( + `${chalk.bold.yellow(`[plugin:${warning.plugin}]`)} ${chalk.yellow( + warning.message + )}` + ) + } else { + warn(warning) + } } } diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 380f88bfda4310..befeb4cca8751e 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -25,6 +25,7 @@ import aliasPlugin from '@rollup/plugin-alias' import commonjsPlugin from '@rollup/plugin-commonjs' import jsonPlugin from '@rollup/plugin-json' import { buildDefinePlugin } from '../plugins/define' +import { createFilter } from '@rollup/pluginutils' const debug = createDebugger('vite:optimize') @@ -36,21 +37,17 @@ export interface DepOptimizationOptions { /** * Do not optimize these dependencies. */ - exclude?: string[] - /** - * A list of linked dependencies that should be treated as source code. - */ - link?: string[] - /** - * A list of dependencies that imports Node built-ins, but do not actually - * use them in browsers. - */ - allowNodeBuiltins?: string[] + exclude?: string | RegExp | (string | RegExp)[] /** * Automatically run `vite optimize` on server start? * @default true */ auto?: boolean + /** + * A list of linked dependencies that should be treated as source code. + * @deprecated + */ + link?: string[] } export interface DepOptimizationMetadata { @@ -174,7 +171,7 @@ export async function optimizeDeps( input: qualified, external, onwarn(warning, warn) { - onRollupWarning(warning, warn, options.allowNodeBuiltins) + onRollupWarning(warning, warn, config) }, plugins: [ aliasPlugin({ entries: config.alias }), @@ -219,19 +216,6 @@ export async function optimizeDeps( e.message += `\n\n${chalk.cyan( path.relative(root, e.loc.file) )}\n${chalk.dim(e.frame)}` - } else if (e.message.match('Node built-in')) { - e.message += chalk.yellow( - `\n\nTip:\nMake sure your "dependencies" only include packages that you\n` + - `intend to use in the browser. If it's a Node.js package, it\n` + - `should be in "devDependencies".\n\n` + - `If you do intend to use this dependency in the browser and the\n` + - `dependency does not actually use these Node built-ins in the\n` + - `browser, you can add the dependency (not the built-in) to the\n` + - `"optimizeDeps.allowNodeBuiltins" option in vite.config.js.\n\n` + - `If that results in a runtime error, then unfortunately the\n` + - `package is not distributed in a web-friendly format. You should\n` + - `open an issue in its repo, or look for a modern alternative.` - ) } throw e } @@ -271,13 +255,14 @@ async function resolveQualifiedDeps( const pkg = JSON.parse(pkgContent) const deps = Object.keys(pkg.dependencies || {}) const linked: string[] = [] + const excludeFilter = exclude && createFilter(exclude) for (const id of deps) { if (include && include.includes(id)) { // already force included continue } - if (exclude && exclude.includes(id)) { + if (excludeFilter && excludeFilter(id)) { debug(`skipping ${id} (excluded)`) continue } diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index c9c8956bc05a67..0906beb9a806e5 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -146,14 +146,6 @@ export function resolvePlugin({ // bare package imports, perform node resolve if (bareImportRE.test(id)) { - // externalize node built-ins only when building for ssr - if (isBuild && config && config.build.ssr && isBuiltin(id)) { - return { - id, - external: true - } - } - if (asSrc && server && (res = tryOptimizedResolve(id, server))) { return res } @@ -170,6 +162,23 @@ export function resolvePlugin({ ) { return res } + + // node built-ins. + // externalize if building for SSR, otherwise redirect to empty module + if (isBuiltin(id)) { + if (isBuild && config && config.build.ssr) { + return { + id, + external: true + } + } else { + this.warn( + `externalized node built-in "${id}" to empty module. ` + + `(imported by: ${chalk.white.dim(importer)})` + ) + return browserExternalId + } + } } isDebug && debug(`[fallthrough] ${chalk.dim(id)}`) From 60b9e10405c513c440c393925d74757d5c2fa15b Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 9 Jan 2021 23:19:34 -0500 Subject: [PATCH 003/514] refactor: fix js request check & deep import error on assets --- packages/vite/src/node/plugins/resolve.ts | 3 ++- packages/vite/src/node/utils.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 0906beb9a806e5..800df619cdd37b 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -259,7 +259,8 @@ export function tryNodeResolve( server && server.optimizeDepsMetadata && pkg.data.name in server.optimizeDepsMetadata.map && - !isCSSRequest(id) + !isCSSRequest(id) && + !server.config.assetsInclude(id) ) { throw new Error( chalk.yellow( diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 1518b5c8d38a88..44de579d6e64f5 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -77,8 +77,16 @@ const dataUrlRE = /^\s*data:/i export const isDataUrl = (url: string) => dataUrlRE.test(url) const knownJsSrcRE = /\.((j|t)sx?|mjs|vue)($|\?)/ -export const isJSRequest = (url: string) => - knownJsSrcRE.test(url) || (!path.extname(url) && !url.endsWith('/')) +export const isJSRequest = (url: string) => { + if (knownJsSrcRE.test(url)) { + return true + } + url = cleanUrl(url) + if (!path.extname(url) && !url.endsWith('/')) { + return true + } + return false +} const importQueryRE = /(\?|&)import(&|$)/ export const isImportRequest = (url: string) => importQueryRE.test(url) From 1ea016823975f3d0e37bf7b65614eded213e0869 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 9 Jan 2021 23:40:53 -0500 Subject: [PATCH 004/514] feat(optimizer): support specifying plugins for the optimizer --- docs/config/index.md | 8 ++++++++ .../optimize-deps-linked-include/Test.vue | 1 + .../optimize-deps-linked-include/index.js | 2 ++ .../optimize-deps/__tests__/optimize-deps.spec.ts | 4 ++++ packages/playground/optimize-deps/index.html | 6 +++++- packages/playground/optimize-deps/vite.config.js | 6 +++++- packages/vite/src/node/config.ts | 4 ++-- packages/vite/src/node/optimizer/index.ts | 14 ++++++++++++-- 8 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 packages/playground/optimize-deps-linked-include/Test.vue diff --git a/docs/config/index.md b/docs/config/index.md index 6507755e824364..1ace65ae99990c 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -419,6 +419,14 @@ export default ({ command, mode }) => { Dependencies to force exclude in pre-bundling. +### optimizeDeps.plugins + +- **Type:** `Plugin[]` + + By default, Vite assumes dependencies ship plain JavaScript and will not attempt to transform non-js file formats during pre-bundling. If you wish to support speical file types, e.g. `.vue` files, you will need to supply the relevant plugins via this option. + + Note that you will also need to include these plugins in the main `plugins` option in order to support the same file types during production build. + ### optimizeDeps.auto - **Type:** `boolean` diff --git a/packages/playground/optimize-deps-linked-include/Test.vue b/packages/playground/optimize-deps-linked-include/Test.vue new file mode 100644 index 00000000000000..ca11049b3e883b --- /dev/null +++ b/packages/playground/optimize-deps-linked-include/Test.vue @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/playground/optimize-deps-linked-include/index.js b/packages/playground/optimize-deps-linked-include/index.js index a869157f53ed1b..81c43abc0387ac 100644 --- a/packages/playground/optimize-deps-linked-include/index.js +++ b/packages/playground/optimize-deps-linked-include/index.js @@ -17,3 +17,5 @@ if (false) { } else { console.log('ok') } + +export { default as VueSFC } from './Test.vue' diff --git a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts b/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts index 9623590c007b7b..9b65f11e8ffd4a 100644 --- a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts +++ b/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts @@ -33,3 +33,7 @@ test('forced include', async () => { test('dep with css import', async () => { expect(await getColor('h1')).toBe('red') }) + +test('dep w/ non-js files handled via plugin', async () => { + expect(await page.textContent('.plugin')).toMatch(`[success]`) +}) diff --git a/packages/playground/optimize-deps/index.html b/packages/playground/optimize-deps/index.html index 7e881b1daeabab..19762f17a2b557 100644 --- a/packages/playground/optimize-deps/index.html +++ b/packages/playground/optimize-deps/index.html @@ -21,6 +21,9 @@

Detecting linked src package and optimizing its deps (lodash-es)

Optimizing force included dep even when it's linked

+

Dep w/ speical file format supported via plugins

+
+ diff --git a/packages/playground/optimize-deps/vite.config.js b/packages/playground/optimize-deps/vite.config.js index 267e0ff2be1995..5c3b4a2d48b5f4 100644 --- a/packages/playground/optimize-deps/vite.config.js +++ b/packages/playground/optimize-deps/vite.config.js @@ -1,3 +1,5 @@ +const vue = require('@vitejs/plugin-vue') + /** * @type {import('vite').UserConfig} */ @@ -5,7 +7,8 @@ module.exports = { dedupe: ['react'], optimizeDeps: { - include: ['optimize-deps-linked-include'] + include: ['optimize-deps-linked-include'], + plugins: [vue()] }, build: { @@ -14,6 +17,7 @@ module.exports = { }, plugins: [ + vue(), // for axios request test { name: 'mock', diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 9c751f2df54b87..4e27d7009554ff 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -161,7 +161,7 @@ export async function resolveConfig( const rawUserPlugins = (config.plugins || []).flat().filter((p) => { return !p.apply || p.apply === command }) - const [prePlugins, postPlugins, normalPlugins] = sortUserPlugins( + const [prePlugins, normalPlugins, postPlugins] = sortUserPlugins( rawUserPlugins ) @@ -345,7 +345,7 @@ export function sortUserPlugins( }) } - return [prePlugins, postPlugins, normalPlugins] + return [prePlugins, normalPlugins, postPlugins] } export async function loadConfigFromFile( diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index befeb4cca8751e..71076118825585 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -3,7 +3,7 @@ import path from 'path' import chalk from 'chalk' import Rollup from 'rollup' import { createHash } from 'crypto' -import { ResolvedConfig } from '../config' +import { ResolvedConfig, sortUserPlugins } from '../config' import { SUPPORTED_EXTS } from '../constants' import { init, parse } from 'es-module-lexer' import { onRollupWarning } from '../build' @@ -26,6 +26,7 @@ import commonjsPlugin from '@rollup/plugin-commonjs' import jsonPlugin from '@rollup/plugin-json' import { buildDefinePlugin } from '../plugins/define' import { createFilter } from '@rollup/pluginutils' +import { Plugin } from '../plugin' const debug = createDebugger('vite:optimize') @@ -38,6 +39,10 @@ export interface DepOptimizationOptions { * Do not optimize these dependencies. */ exclude?: string | RegExp | (string | RegExp)[] + /** + * Plugins to use for dep optimizations. + */ + plugins?: Plugin[] /** * Automatically run `vite optimize` on server start? * @default true @@ -164,6 +169,8 @@ export async function optimizeDeps( logger.info(chalk.greenBright(`Optimizing dependencies:\n${depsString}`)) } + const [pre, normal, post] = sortUserPlugins(options.plugins) + try { const rollup = require('rollup') as typeof Rollup @@ -175,6 +182,7 @@ export async function optimizeDeps( }, plugins: [ aliasPlugin({ entries: config.alias }), + ...pre, depAssetExternalPlugin(config), resolvePlugin({ root: config.root, @@ -186,13 +194,15 @@ export async function optimizeDeps( preferConst: true, namedExports: true }), + ...normal, commonjsPlugin({ include: [/node_modules/], extensions: ['.js', '.cjs'] }), buildDefinePlugin(config), depAssetRewritePlugin(config), - recordCjsEntryPlugin(data) + recordCjsEntryPlugin(data), + ...post ] }) From bbfe06ce1af8f89490032e609377c6516f7da773 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 9 Jan 2021 23:54:30 -0500 Subject: [PATCH 005/514] fix: fix dynamic import with parent relative paths fix #1461 --- packages/playground/dynamic-import/index.html | 21 +------------------ .../playground/dynamic-import/nested/index.js | 18 ++++++++++++++++ packages/vite/src/client/client.ts | 4 +++- 3 files changed, 22 insertions(+), 21 deletions(-) create mode 100644 packages/playground/dynamic-import/nested/index.js diff --git a/packages/playground/dynamic-import/index.html b/packages/playground/dynamic-import/index.html index 6bf5eee0d017a6..a71c770741d80d 100644 --- a/packages/playground/dynamic-import/index.html +++ b/packages/playground/dynamic-import/index.html @@ -4,23 +4,4 @@
- + diff --git a/packages/playground/dynamic-import/nested/index.js b/packages/playground/dynamic-import/nested/index.js new file mode 100644 index 00000000000000..9c22d25a17682b --- /dev/null +++ b/packages/playground/dynamic-import/nested/index.js @@ -0,0 +1,18 @@ +async function setView(view) { + const { msg } = await import(`../views/${view}.js`) + text('.view', msg) +} + +;['foo', 'bar'].forEach((id) => { + document.querySelector(`.${id}`).addEventListener('click', () => setView(id)) +}) + +document.querySelector('.baz').addEventListener('click', async () => { + // literal dynamic + const { msg } = await import('../views/baz.js') + text('.view', msg) +}) + +function text(el, text) { + document.querySelector(el).textContent = text +} diff --git a/packages/vite/src/client/client.ts b/packages/vite/src/client/client.ts index e2cb1a379b35d7..949145a2103d0b 100644 --- a/packages/vite/src/client/client.ts +++ b/packages/vite/src/client/client.ts @@ -438,7 +438,9 @@ export const createHotContext = (ownerPath: string) => { } export function injectQuery(url: string, queryToInject: string) { - const { pathname, search, hash } = new URL(url, 'http://vitejs.dev') + // can't use pathname from URL since it may be relative like ../ + const pathname = url.replace(/#.*$/, '').replace(/\?.*$/, '') + const { search, hash } = new URL(url, 'http://vitejs.dev') return `${pathname}?${queryToInject}${search ? `&` + search.slice(1) : ''}${ hash || '' }` From 8497f52953646d610db6579b0e77807011a2dba1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 9 Jan 2021 23:55:56 -0500 Subject: [PATCH 006/514] chore: deprecation message --- packages/vite/src/node/optimizer/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 71076118825585..40d3f4e76e5ce6 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -50,7 +50,7 @@ export interface DepOptimizationOptions { auto?: boolean /** * A list of linked dependencies that should be treated as source code. - * @deprecated + * @deprecated local linked deps are auto detected in Vite 2. */ link?: string[] } From cf8342bef45bebb05d020d4f220b12d2bf526256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Han=EF=BC=88=E3=83=8F=E3=83=B3=EF=BC=89?= Date: Sun, 10 Jan 2021 14:02:52 +0900 Subject: [PATCH 007/514] fix: transform json in deep import (#1459) fix #1458 --- .../playground/json/__tests__/json.spec.ts | 10 +++ packages/playground/json/index.html | 9 +++ packages/vite/src/node/plugins/index.ts | 2 +- packages/vite/src/node/plugins/json.ts | 81 +++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 packages/vite/src/node/plugins/json.ts diff --git a/packages/playground/json/__tests__/json.spec.ts b/packages/playground/json/__tests__/json.spec.ts index cd15c1d50dc4de..2a9451d1c41ca7 100644 --- a/packages/playground/json/__tests__/json.spec.ts +++ b/packages/playground/json/__tests__/json.spec.ts @@ -1,5 +1,7 @@ const json = require('../test.json') +const deepJson = require('@vue/runtime-core/package.json') const stringified = JSON.stringify(json) +const deepStringified = JSON.stringify(deepJson) test('default import', async () => { expect(await page.textContent('.full')).toBe(stringified) @@ -9,6 +11,14 @@ test('named import', async () => { expect(await page.textContent('.named')).toBe(json.hello) }) +test('deep import', async () => { + expect(await page.textContent('.deep-full')).toBe(deepStringified) +}) + +test('named deep import', async () => { + expect(await page.textContent('.deep-named')).toBe(deepJson.name) +}) + test('dynamic import', async () => { expect(await page.textContent('.dynamic')).toBe(stringified) }) diff --git a/packages/playground/json/index.html b/packages/playground/json/index.html index 3c5eaca233d268..0efaea3147a164 100644 --- a/packages/playground/json/index.html +++ b/packages/playground/json/index.html @@ -2,6 +2,10 @@

Normal Import


 

 
+

Deep Import

+

+

+
 

Dynamic Import


 

@@ -11,9 +15,14 @@ 

Raw fetch

diff --git a/docs/public/tailwind-labs.svg b/docs/public/tailwind-labs.svg new file mode 100644 index 00000000000000..300411468cbb5f --- /dev/null +++ b/docs/public/tailwind-labs.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/package.json b/package.json index 352757e0938452..398171d808acd4 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "slash": "^3.0.0", "ts-jest": "^26.4.4", "typescript": "^4.1.2", - "vitepress": "^0.10.7", + "vitepress": "^0.11.0", "yorkie": "^2.0.0" }, "gitHooks": { diff --git a/yarn.lock b/yarn.lock index 47da774e0fccc1..e6bded2c796f2e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7592,10 +7592,10 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -vitepress@^0.10.7: - version "0.10.7" - resolved "https://registry.yarnpkg.com/vitepress/-/vitepress-0.10.7.tgz#53ce1f735cf765fc50ed07cb0a7d5ae4fb92ef29" - integrity sha512-6ZnH3WIYL58E5ddKCDzihI2UKUOD24e15jfi2YEbiMI3Eb6cZwfFehiZUoSVFQ38sJ6/Vh9p8SzH92w+OlXXFQ== +vitepress@^0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/vitepress/-/vitepress-0.11.0.tgz#7f7634c8bbb33be265d026a7ac7356d82fec2a45" + integrity sha512-8nwN1EmEk0k+syg6Njt+4dhCuYp2mYat5X3WuweStS2G9BQDNN8e4jTRbgscyNEmoG0vWvdxZ+mnJr0lA7mnGA== dependencies: "@docsearch/css" "^1.0.0-alpha.28" "@docsearch/js" "^1.0.0-alpha.28" @@ -7622,7 +7622,7 @@ vitepress@^0.10.7: prismjs "^1.20.0" sirv "^1.0.10" slash "^3.0.0" - vite "^2.0.0-beta.8" + vite "^2.0.0-beta.21" vue "^3.0.5" void-elements@^3.1.0: From 43682b41ca1dffb9f81403ab9ee8054882930e44 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 12 Jan 2021 00:22:41 -0500 Subject: [PATCH 044/514] chore: bump vitepress --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 398171d808acd4..14cf29e9f6d717 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "slash": "^3.0.0", "ts-jest": "^26.4.4", "typescript": "^4.1.2", - "vitepress": "^0.11.0", + "vitepress": "^0.11.1", "yorkie": "^2.0.0" }, "gitHooks": { diff --git a/yarn.lock b/yarn.lock index e6bded2c796f2e..b191321db6304e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7592,10 +7592,10 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -vitepress@^0.11.0: - version "0.11.0" - resolved "https://registry.yarnpkg.com/vitepress/-/vitepress-0.11.0.tgz#7f7634c8bbb33be265d026a7ac7356d82fec2a45" - integrity sha512-8nwN1EmEk0k+syg6Njt+4dhCuYp2mYat5X3WuweStS2G9BQDNN8e4jTRbgscyNEmoG0vWvdxZ+mnJr0lA7mnGA== +vitepress@^0.11.1: + version "0.11.1" + resolved "https://registry.yarnpkg.com/vitepress/-/vitepress-0.11.1.tgz#1eee2dac8d3aad8d488558ddbc2367e33b2a2a3f" + integrity sha512-ThjTFNQjlVcVz0UNv1zV6fs1cYs8h/xNWmzrbF08gqKtE6vTSRVEb9SVlIXq1LVt13/0+t5XyddEURi5wo1Big== dependencies: "@docsearch/css" "^1.0.0-alpha.28" "@docsearch/js" "^1.0.0-alpha.28" From b5e591dffb8105b86af272908665b7c64e783398 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 12 Jan 2021 00:26:28 -0500 Subject: [PATCH 045/514] docs: sponsor css fix --- docs/.vitepress/theme/sponsors.css | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/.vitepress/theme/sponsors.css b/docs/.vitepress/theme/sponsors.css index 1aa3b5a82b1fa2..2f30c1a888c540 100644 --- a/docs/.vitepress/theme/sponsors.css +++ b/docs/.vitepress/theme/sponsors.css @@ -9,7 +9,7 @@ .sponsors img { width: 200px; - display: inline-block; + display: block; margin: 1.25rem 0; } @@ -17,6 +17,10 @@ text-align: center; } +.sponsors.frontpage img { + display: inline-block; +} + .sponsors.frontpage h2 { color: #999; font-size: 1.2rem; From ae2e14baf1771c2ccdeece8bbc2b9bd11b279490 Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Tue, 12 Jan 2021 10:51:28 +0200 Subject: [PATCH 046/514] fix: show target build mode in logs (#1498) --- packages/vite/src/node/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 6417c4eb0dc0bb..f9e04991558b44 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -264,7 +264,7 @@ async function doBuild( inlineConfig: InlineConfig = {} ): Promise { const config = await resolveConfig(inlineConfig, 'build', 'production') - config.logger.info(chalk.cyan(`building for production...`)) + config.logger.info(chalk.cyan(`building for ${config.mode}...`)) const options = config.build const libOptions = options.lib From 6bdc3eb2d004a28d2934946e33602f832b1ad8f2 Mon Sep 17 00:00:00 2001 From: JokcyLou Date: Tue, 12 Jan 2021 19:39:29 +0800 Subject: [PATCH 047/514] fix(plugin-vue-jsx): fix vue jsx hmr (#1495) --- .../vue-jsx/__tests__/vue-jsx.spec.ts | 12 ++++---- packages/plugin-vue-jsx/index.js | 29 ++++++------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts b/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts index 3a54cfdbf011e4..104d3bd52642b9 100644 --- a/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts +++ b/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts @@ -1,4 +1,4 @@ -import { editFile, isBuild, untilUpdated } from '../../testUtils' +import { editFile, isBuild, untilUpdated } from 'testUtils' test('should render', async () => { expect(await page.textContent('.named')).toMatch('0') @@ -25,9 +25,10 @@ if (!isBuild) { ) await untilUpdated(() => page.textContent('.named'), 'named updated 0') - // should not affect other components on the page - expect(await page.textContent('.named-specifier')).toMatch('2') - expect(await page.textContent('.default')).toMatch('3') + // affect all components in same file + expect(await page.textContent('.named-specifier')).toMatch('1') + expect(await page.textContent('.default')).toMatch('2') + // should not affect other components from different file expect(await page.textContent('.default-tsx')).toMatch('4') }) @@ -40,8 +41,9 @@ if (!isBuild) { 'named specifier updated 1' ) + // affect all components in same file + expect(await page.textContent('.default')).toMatch('2') // should not affect other components on the page - expect(await page.textContent('.default')).toMatch('3') expect(await page.textContent('.default-tsx')).toMatch('4') }) diff --git a/packages/plugin-vue-jsx/index.js b/packages/plugin-vue-jsx/index.js index 6e9546be103646..86d27be65008b2 100644 --- a/packages/plugin-vue-jsx/index.js +++ b/packages/plugin-vue-jsx/index.js @@ -62,7 +62,7 @@ function vueJsxPlugin(options = {}) { // check for hmr injection /** - * @type {{ name: string, hash: string }[]} + * @type {{ name: string }[]} */ const declaredComponents = [] /** @@ -70,7 +70,6 @@ function vueJsxPlugin(options = {}) { * local: string, * exported: string, * id: string, - * hash: string * }[]} */ const hotComponents = [] @@ -91,11 +90,10 @@ function vueJsxPlugin(options = {}) { ) { hotComponents.push( ...parseComponentDecls(node.declaration, code).map( - ({ name, hash: _hash }) => ({ + ({ name }) => ({ local: name, exported: name, - id: hash(id + name), - hash: _hash + id: hash(id + name) }) ) ) @@ -112,8 +110,7 @@ function vueJsxPlugin(options = {}) { hotComponents.push({ local: spec.local.name, exported: spec.exported.name, - id: hash(id + spec.exported.name), - hash: matched.hash + id: hash(id + spec.exported.name) }) } } @@ -131,8 +128,7 @@ function vueJsxPlugin(options = {}) { hotComponents.push({ local: node.declaration.name, exported: 'default', - id: hash(id + 'default'), - hash: matched.hash + id: hash(id + 'default') }) } } else if (isDefineComponentCall(node.declaration)) { @@ -140,10 +136,7 @@ function vueJsxPlugin(options = {}) { hotComponents.push({ local: '__default__', exported: 'default', - id: hash(id + 'default'), - hash: hash( - code.slice(node.declaration.start, node.declaration.end) - ) + id: hash(id + 'default') }) } } @@ -160,14 +153,11 @@ function vueJsxPlugin(options = {}) { } let callbackCode = `` - for (const { local, exported, id, hash } of hotComponents) { + for (const { local, exported, id } of hotComponents) { code += `\n${local}.__hmrId = "${id}"` + - `\n${local}.__hmrHash = "${hash}"` + `\n__VUE_HMR_RUNTIME__.createRecord("${id}", ${local})` - callbackCode += - `\n if (__${exported}.__hmrHash !== ${local}.__hmrHash) ` + - `__VUE_HMR_RUNTIME__.reload("${id}", __${exported})` + callbackCode += `\n__VUE_HMR_RUNTIME__.reload("${id}", __${exported})` } code += `\nimport.meta.hot.accept(({${hotComponents @@ -195,8 +185,7 @@ function parseComponentDecls(node, source) { for (const decl of node.declarations) { if (decl.id.type === 'Identifier' && isDefineComponentCall(decl.init)) { names.push({ - name: decl.id.name, - hash: hash(source.slice(decl.init.start, decl.init.end)) + name: decl.id.name }) } } From cf5f3ab2c33aca6ab6bff8d600854f93586adcf0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 12 Jan 2021 11:50:53 -0500 Subject: [PATCH 048/514] fix: support import.meta.url in ts esm config file close #1499 --- packages/vite/src/node/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 7878014cbe2e60..8f0862f30e2e86 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -481,7 +481,7 @@ async function bundleConfigFile( treeshake: false, plugins: [ // use esbuild + node-resolve to support .ts files - esbuildPlugin({ target: 'es2019' }), + esbuildPlugin({ target: 'esnext' }), resolvePlugin({ root: path.dirname(fileName), isBuild: true, From 50bff797c536b08661791a833cfbb9179ff54422 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 12 Jan 2021 12:10:01 -0500 Subject: [PATCH 049/514] fix: more consistent outDir formatting close #1497 --- packages/vite/src/node/plugins/reporter.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/reporter.ts b/packages/vite/src/node/plugins/reporter.ts index 5c5469c8ae2024..f9e72130c08ad4 100644 --- a/packages/vite/src/node/plugins/reporter.ts +++ b/packages/vite/src/node/plugins/reporter.ts @@ -3,6 +3,7 @@ import chalk from 'chalk' import { Plugin } from 'rollup' import { ResolvedConfig } from '../config' import { sync as brotliSizeSync } from 'brotli-size' +import { normalizePath } from '../utils' const enum WriteType { JS, @@ -38,8 +39,13 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin { ).toFixed(2)}kb` : `` - let outDir = path.posix.relative(process.cwd(), config.build.outDir) - if (!outDir.endsWith('/')) outDir += '/' + const outDir = + normalizePath( + path.relative( + config.root, + path.resolve(config.root, config.build.outDir) + ) + ) + '/' config.logger.info( `${chalk.gray(chalk.white.dim(outDir))}${writeColors[type]( filePath.padEnd(maxLength + 2) From a09a03045029a9d7fedf3f8d943269a4346c3882 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 12 Jan 2021 12:13:35 -0500 Subject: [PATCH 050/514] refactor: use consistent cli options style --- packages/vite/src/node/cli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/cli.ts b/packages/vite/src/node/cli.ts index 194617992eb844..3a5d84d768d58a 100644 --- a/packages/vite/src/node/cli.ts +++ b/packages/vite/src/node/cli.ts @@ -61,7 +61,7 @@ cli .option('--https', `[boolean] use TLS + HTTP/2`) .option('--open [browser]', `[boolean | string] open browser on startup`) .option('--cors', `[boolean] enable CORS`) - .option('--strict-port', `[boolean] exit if specified port is already in use`) + .option('--strictPort', `[boolean] exit if specified port is already in use`) .option('-m, --mode ', `[string] set env mode`) .option( '--force', From 730d2f0d8081e11c88b1151086d99b23e0c58823 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 12 Jan 2021 12:33:47 -0500 Subject: [PATCH 051/514] feat: require explicit option to empty outDir when it is out of root close #1501 --- docs/config/index.md | 7 +++++++ packages/vite/package.json | 1 + packages/vite/src/node/build.ts | 28 ++++++++++++++++++++++++++-- packages/vite/src/node/cli.ts | 4 ++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 3c5f72e4075aa8..f07dc6bc4bf6ed 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -415,6 +415,13 @@ export default ({ command, mode }) => { Set to `false` to disable writing the bundle to disk. This is mostly used in [programmatic `build()` calls](/guide/api-javascript#build) where further post processing of the bundle is needed before writing to disk. +### build.emptyOutDir + +- **Type:** `boolean` +- **Default:** `true` if `outDir` is inside `root` + + By default, Vite will empty the `outDir` on build if it is inside project root. It will emit a warning if `outDir` is outside of root to avoid accidentially removing important files. You can explicitly set this option to suppress the warning. This is also available via command line as `--emptyOutDir`. + ## Dep Optimization Options - **Related:** [Dependency Pre-Bundling](/guide/dep-pre-bundling) diff --git a/packages/vite/package.json b/packages/vite/package.json index 4e954297385b67..b586c793cfeb06 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -85,6 +85,7 @@ "debug": "^4.3.1", "dotenv": "^8.2.0", "dotenv-expand": "^5.1.0", + "enquirer": "^2.3.6", "es-module-lexer": "^0.3.26", "etag": "^1.8.1", "execa": "^5.0.0", diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index f9e04991558b44..2f0b1c285a8ebf 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -17,7 +17,7 @@ import { buildHtmlPlugin } from './plugins/html' import { buildEsbuildPlugin } from './plugins/esbuild' import { terserPlugin } from './plugins/terser' import { Terser } from 'types/terser' -import { copyDir, emptyDir, lookupFile } from './utils' +import { copyDir, emptyDir, lookupFile, normalizePath } from './utils' import { manifestPlugin } from './plugins/manifest' import commonjsPlugin from '@rollup/plugin-commonjs' import { RollupCommonJSOptions } from 'types/commonjs' @@ -118,6 +118,11 @@ export interface BuildOptions { * @default true */ write?: boolean + /** + * Empty outDir on write. + * @default true when outDir is a sub directory of project root + */ + emptyOutDir?: boolean | null /** * Whether to emit a manifest.json under assets dir to map hash-less filenames * to their hashed versions. Useful when you want to generate your own HTML @@ -176,6 +181,7 @@ export function resolveBuildOptions( terserOptions: {}, cleanCssOptions: {}, write: true, + emptyOutDir: null, manifest: false, lib: false, ssr: false, @@ -319,7 +325,25 @@ async function doBuild( } if (options.write) { - emptyDir(outDir) + // warn if outDir is outside of root + if (fs.existsSync(outDir)) { + const inferEmpty = options.emptyOutDir === null + if ( + options.emptyOutDir || + (inferEmpty && normalizePath(outDir).startsWith(config.root + '/')) + ) { + emptyDir(outDir) + } else if (inferEmpty) { + config.logger.warn( + chalk.yellow( + `\n${chalk.bold(`(!)`)} outDir ${chalk.white.dim( + outDir + )} is not inside project root and will not be emptied.\n` + + `Use --emptyOutDir to override.\n` + ) + ) + } + } if (fs.existsSync(publicDir)) { copyDir(publicDir, outDir) } diff --git a/packages/vite/src/node/cli.ts b/packages/vite/src/node/cli.ts index 3a5d84d768d58a..23bb9f6c21f84e 100644 --- a/packages/vite/src/node/cli.ts +++ b/packages/vite/src/node/cli.ts @@ -112,6 +112,10 @@ cli `or specify minifier to use (default: terser)` ) .option('--manifest', `[boolean] emit build manifest json`) + .option( + '--emptyOutDir', + `[boolean] force empty outDir when it's outside of root` + ) .option('-m, --mode ', `[string] set env mode`) .action(async (root: string, options: BuildOptions & GlobalCLIOptions) => { const { build } = await import('./build') From cc5fa6efb3448e2f83b5d6d428e79803c8993657 Mon Sep 17 00:00:00 2001 From: Alexandre Bonaventure Geissmann Date: Tue, 12 Jan 2021 12:39:45 -0500 Subject: [PATCH 052/514] fix(hmr): watch file changes even when HMR is disabled (#1504) --- packages/vite/src/node/server/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index b6454e406f7a00..5d834ce1876736 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -243,11 +243,11 @@ export async function createServer( } } - if (serverConfig.hmr !== false) { - watcher.on('change', async (file) => { - file = normalizePath(file) - // invalidate module graph cache on file change - moduleGraph.onFileChange(file) + watcher.on('change', async (file) => { + file = normalizePath(file) + // invalidate module graph cache on file change + moduleGraph.onFileChange(file) + if (serverConfig.hmr !== false) { try { await handleHMRUpdate(file, server) } catch (err) { @@ -256,8 +256,8 @@ export async function createServer( err: prepareError(err) }) } - }) - } + } + }) // apply server configuration hooks from plugins const postHooks: ((() => void) | void)[] = [] From 1629c546158253f155afecb55846771013f90ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Wed, 13 Jan 2021 01:48:05 +0800 Subject: [PATCH 053/514] feat: allow browser new window view source (#1496) --- packages/vite/src/node/server/middlewares/transform.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/vite/src/node/server/middlewares/transform.ts b/packages/vite/src/node/server/middlewares/transform.ts index 6b9a57684de06c..65708262d9c0f1 100644 --- a/packages/vite/src/node/server/middlewares/transform.ts +++ b/packages/vite/src/node/server/middlewares/transform.ts @@ -39,7 +39,6 @@ export function transformMiddleware( return async (req, res, next) => { if ( req.method !== 'GET' || - req.headers.accept?.includes('text/html') || knownIgnoreList.has(req.url!) ) { return next() From 1ff9fe3effe9df80207d82fdae5d8ab367982c61 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 12 Jan 2021 12:48:54 -0500 Subject: [PATCH 054/514] release: v2.0.0-beta.24 --- packages/vite/CHANGELOG.md | 19 +++++++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 8084ae6f01a1e1..a8905c5378cf05 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,22 @@ +# [2.0.0-beta.24](https://github.com/vitejs/vite/compare/v2.0.0-beta.23...v2.0.0-beta.24) (2021-01-12) + + +### Bug Fixes + +* **hmr:** watch file changes even when HMR is disabled ([#1504](https://github.com/vitejs/vite/issues/1504)) ([cc5fa6e](https://github.com/vitejs/vite/commit/cc5fa6efb3448e2f83b5d6d428e79803c8993657)) +* always replace preload marker with value ([2d6f524](https://github.com/vitejs/vite/commit/2d6f5243e16f7debd7ba0de4bf22706df35ccf73)) +* more consistent outDir formatting ([50bff79](https://github.com/vitejs/vite/commit/50bff797c536b08661791a833cfbb9179ff54422)), closes [#1497](https://github.com/vitejs/vite/issues/1497) +* show target build mode in logs ([#1498](https://github.com/vitejs/vite/issues/1498)) ([ae2e14b](https://github.com/vitejs/vite/commit/ae2e14baf1771c2ccdeece8bbc2b9bd11b279490)) +* support import.meta.url in ts esm config file ([cf5f3ab](https://github.com/vitejs/vite/commit/cf5f3ab2c33aca6ab6bff8d600854f93586adcf0)), closes [#1499](https://github.com/vitejs/vite/issues/1499) + + +### Features + +* allow browser new window view source ([#1496](https://github.com/vitejs/vite/issues/1496)) ([1629c54](https://github.com/vitejs/vite/commit/1629c546158253f155afecb55846771013f90ec0)) +* require explicit option to empty outDir when it is out of root ([730d2f0](https://github.com/vitejs/vite/commit/730d2f0d8081e11c88b1151086d99b23e0c58823)), closes [#1501](https://github.com/vitejs/vite/issues/1501) + + + # [2.0.0-beta.23](https://github.com/vitejs/vite/compare/v2.0.0-beta.22...v2.0.0-beta.23) (2021-01-12) diff --git a/packages/vite/package.json b/packages/vite/package.json index b586c793cfeb06..681dcab2964ef4 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.23", + "version": "2.0.0-beta.24", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 14617ec3c57562d1744823dda190ceade8cad6bd Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 12 Jan 2021 15:40:32 -0500 Subject: [PATCH 055/514] release: plugin-vue-jsx@1.0.2 --- packages/plugin-vue-jsx/CHANGELOG.md | 16 ++++++++++++++++ packages/plugin-vue-jsx/package.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/plugin-vue-jsx/CHANGELOG.md b/packages/plugin-vue-jsx/CHANGELOG.md index 70d26f58d1cc1e..f8824dd2e240a9 100644 --- a/packages/plugin-vue-jsx/CHANGELOG.md +++ b/packages/plugin-vue-jsx/CHANGELOG.md @@ -1,3 +1,19 @@ +## [1.0.2](https://github.com/vitejs/vite/compare/plugin-vue-jsx@1.0.1...plugin-vue-jsx@1.0.2) (2021-01-12) + + +### Bug Fixes + +* **plugin-vue-jsx:** files should include `index.d.ts` ([#1473](https://github.com/vitejs/vite/issues/1473)) [skip ci] ([f3ab497](https://github.com/vitejs/vite/commit/f3ab497b762e267721ace628bc6c7c5695b0d431)) +* **plugin-vue-jsx:** fix define call check ([#1480](https://github.com/vitejs/vite/issues/1480)) ([4ea065f](https://github.com/vitejs/vite/commit/4ea065f6278f30c022ed291bfb0412a674b18dd4)) +* **plugin-vue-jsx:** fix vue jsx hmr ([#1495](https://github.com/vitejs/vite/issues/1495)) ([6bdc3eb](https://github.com/vitejs/vite/commit/6bdc3eb2d004a28d2934946e33602f832b1ad8f2)) + + +### Performance Improvements + +* **plugin-vue-jsx:** only gen source map when necessary ([bfa8530](https://github.com/vitejs/vite/commit/bfa8530fc60deada634c38cfd6a23ab8ca05d47c)) + + + ## [1.0.1](https://github.com/vitejs/vite/compare/plugin-vue-jsx@1.0.0...plugin-vue-jsx@1.0.1) (2021-01-04) diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 9f586ca1b303f6..a7a90fef1009a7 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-vue-jsx", - "version": "1.0.1", + "version": "1.0.2", "license": "MIT", "author": "Evan You", "files": [ From 5fc1ea7242db16f1ad7b98286f8dee055481626d Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 12 Jan 2021 16:53:05 -0500 Subject: [PATCH 056/514] docs: a11y and seo --- docs/.vitepress/theme/index.js | 19 ++++++++++++++++--- docs/.vitepress/theme/sponsors.json | 1 + docs/index.md | 6 +++--- package.json | 1 + 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/docs/.vitepress/theme/index.js b/docs/.vitepress/theme/index.js index e99bee1facdfd9..fe497ebfa4bb30 100644 --- a/docs/.vitepress/theme/index.js +++ b/docs/.vitepress/theme/index.js @@ -11,11 +11,24 @@ export default { h('div', { class: 'sponsors' }, [ h( 'a', - { href: 'https://github.com/sponsors/yyx990803', target: '_blank' }, + { + href: 'https://github.com/sponsors/yyx990803', + target: '_blank', + rel: 'noopener' + }, [h('span', 'Sponsors')] ), - ...sponsors.map(({ href, src }) => - h('a', { href, target: '_blank' }, [h('img', { src })]) + ...sponsors.map(({ href, src, name }) => + h( + 'a', + { + href, + target: '_blank', + rel: 'noopener', + 'aria-label': 'sponsor-img' + }, + [h('img', { src, alt: name })] + ) ) ]) }) diff --git a/docs/.vitepress/theme/sponsors.json b/docs/.vitepress/theme/sponsors.json index 1789ca3bcb3699..622638f3d64c72 100644 --- a/docs/.vitepress/theme/sponsors.json +++ b/docs/.vitepress/theme/sponsors.json @@ -1,5 +1,6 @@ [ { + "name": "Tailwind Labs", "href": "https://tailwindcss.com", "src": "/tailwind-labs.svg" } diff --git a/docs/index.md b/docs/index.md index 64dbfbfbe6729f..38e12e939b3ff2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -24,11 +24,11 @@ footer: MIT Licensed | Copyright © 2019-present Evan You & Vite Contributors - \ No newline at end of file + diff --git a/packages/playground/alias/package.json b/packages/playground/alias/package.json index 799762077e811d..de2c9f2756b52a 100644 --- a/packages/playground/alias/package.json +++ b/packages/playground/alias/package.json @@ -6,5 +6,8 @@ "dev": "vite", "build": "vite build", "debug": "node --inspect-brk ../../vite/bin/vite" + }, + "dependencies": { + "vue": "^3.0.5" } } diff --git a/packages/playground/alias/vite.config.js b/packages/playground/alias/vite.config.js index df8a6bf1ac4ba2..fa290d6166457f 100644 --- a/packages/playground/alias/vite.config.js +++ b/packages/playground/alias/vite.config.js @@ -12,6 +12,11 @@ module.exports = { find: /^regex\/(.*)/, replacement: `${path.resolve(__dirname, 'dir')}/$1` }, - { find: '/@', replacement: path.resolve(__dirname, 'dir') } - ] + { find: '/@', replacement: path.resolve(__dirname, 'dir') }, + // aliasing an optimized dep + { find: 'vue', replacement: 'vue/dist/vue.esm-bundler.js' } + ], + build: { + minify: false + } } diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 03df9e84b91901..31a1e1db53d367 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -159,12 +159,13 @@ export async function optimizeDeps( // Force included deps - these can also be deep paths if (options.include) { - options.include.forEach((id) => { - const filePath = tryNodeResolve(id, root, config.isProduction) + for (let id of options.include) { + const aliased = (await aliasResolver.resolveId(id))?.id || id + const filePath = tryNodeResolve(aliased, root, config.isProduction) if (filePath) { qualified[id] = filePath.id } - }) + } } let qualifiedIds = Object.keys(qualified) @@ -345,7 +346,8 @@ async function resolveQualifiedDeps( } let filePath try { - const resolved = tryNodeResolve(id, root, config.isProduction) + const aliased = (await aliasResolver.resolveId(id))?.id || id + const resolved = tryNodeResolve(aliased, root, config.isProduction) filePath = resolved && resolved.id } catch (e) {} if (!filePath) { diff --git a/packages/vite/src/node/plugins/index.ts b/packages/vite/src/node/plugins/index.ts index db514023bf099a..ebbf2f01f22e12 100644 --- a/packages/vite/src/node/plugins/index.ts +++ b/packages/vite/src/node/plugins/index.ts @@ -12,6 +12,7 @@ import { htmlPlugin } from './html' import { wasmPlugin } from './wasm' import { webWorkerPlugin } from './worker' import { dynamicImportPolyfillPlugin } from './dynamicImportPolyfill' +import { preAliasPlugin } from './preAlias' export async function resolvePlugins( config: ResolvedConfig, @@ -26,6 +27,7 @@ export async function resolvePlugins( : { pre: [], post: [] } return [ + isBuild ? null : preAliasPlugin(), aliasPlugin({ entries: config.alias }), ...prePlugins, config.build.polyfillDynamicImport diff --git a/packages/vite/src/node/plugins/preAlias.ts b/packages/vite/src/node/plugins/preAlias.ts new file mode 100644 index 00000000000000..7a7415002effde --- /dev/null +++ b/packages/vite/src/node/plugins/preAlias.ts @@ -0,0 +1,22 @@ +import { ViteDevServer } from '..' +import { Plugin } from '../plugin' +import { bareImportRE } from '../utils' +import { tryOptimizedResolve } from './resolve' + +/** + * A plugin to avoid an aliased AND optimized dep from being aliased in src + */ +export function preAliasPlugin(): Plugin { + let server: ViteDevServer + return { + name: 'vite:pre-alias', + configureServer(_server) { + server = _server + }, + resolveId(id) { + if (bareImportRE.test(id)) { + return tryOptimizedResolve(id, server) + } + } + } +} diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index e2ad5b1cf7bac5..10319b912f5680 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -328,7 +328,7 @@ export function tryNodeResolve( } } -function tryOptimizedResolve( +export function tryOptimizedResolve( rawId: string, server: ViteDevServer ): string | undefined { From 506bf2d542a27ee19a1b1b2d05aad845f4387cf6 Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Thu, 14 Jan 2021 20:43:28 +0200 Subject: [PATCH 081/514] fix: serve out of root static file on windows (#1537) --- packages/vite/src/node/server/middlewares/static.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/middlewares/static.ts b/packages/vite/src/node/server/middlewares/static.ts index 5efba8c1e7827d..6811f36aaee560 100644 --- a/packages/vite/src/node/server/middlewares/static.ts +++ b/packages/vite/src/node/server/middlewares/static.ts @@ -60,7 +60,7 @@ export function serveStaticMiddleware( export function rawFsStaticMiddleware(): Connect.NextHandleFunction { const fsRoot = - os.platform() == 'win32' ? process.cwd().split(path.sep)[0] : '/' + os.platform() == 'win32' ? process.cwd().split(path.sep)[0] + '/' : '/' const serveFromRoot = sirv(fsRoot, sirvOptions) return (req, res, next) => { From 25e9c44992c8b868cec97dbdeddd3a4837d5bb07 Mon Sep 17 00:00:00 2001 From: plq <562714485@qq.com> Date: Fri, 15 Jan 2021 02:48:44 +0800 Subject: [PATCH 082/514] feat: support specifying URL path via server.open option (#1514) --- docs/config/index.md | 13 +++++++++++-- packages/vite/src/node/server/index.ts | 7 ++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 2ae7362aa705fb..a26eca74b61ac7 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -231,9 +231,18 @@ export default ({ command, mode }) => { ### server.open -- **Type:** `boolean` +- **Type:** `boolean | string` - Automatically open the app in the browser on server start. + Automatically open the app in the browser on server start. When the value is a string, it will be used as the URL's pathname. + + **Example:** + ```js + export default { + server: { + open: '/docs/index.html' + } + } + ``` ### server.proxy diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index f57e19ad0a18d8..cc0477b2ea0cea 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -53,7 +53,7 @@ export interface ServerOptions { /** * Open browser window on startup */ - open?: boolean + open?: boolean | string /** * Force dep pre-optimization regardless of whether deps have changed. */ @@ -486,9 +486,10 @@ async function startServer( } if (options.open) { + const path = typeof options.open === 'string' ? options.open : '' openBrowser( - `${protocol}://${hostname}:${port}`, - options.open, + `${protocol}://${hostname}:${port}${path}`, + true, server.config.logger ) } From 4338d7d6f32c8e0e67ff58f0cb8c1a9120294756 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 14 Jan 2021 14:02:55 -0500 Subject: [PATCH 083/514] feat: close server on sigint/sigterm close #1525 --- packages/vite/src/node/server/index.ts | 3 +++ packages/vite/src/node/server/pluginContainer.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index cc0477b2ea0cea..21b10378695913 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -248,6 +248,9 @@ export async function createServer( } } + process.once('SIGINT', server.close) + process.once('SIGTERM', server.close) + watcher.on('change', async (file) => { file = normalizePath(file) // invalidate module graph cache on file change diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index 84b6199e2507b0..72f60bc3085356 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -359,6 +359,7 @@ export async function createPluginContainer( } let nestedResolveCall = 0 + let closed = false const container: PluginContainer = { options: await (async () => { @@ -573,6 +574,7 @@ export async function createPluginContainer( }, async close() { + if (closed) return const ctx = new Context() await Promise.all( plugins.map((p) => p.buildEnd && p.buildEnd.call(ctx as any)) @@ -580,6 +582,7 @@ export async function createPluginContainer( await Promise.all( plugins.map((p) => p.closeBundle && p.closeBundle.call(ctx as any)) ) + closed = true } } From c5c32982f207055229b6bce61ce205d8d20db023 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 14 Jan 2021 15:09:50 -0500 Subject: [PATCH 084/514] feat: add clearScreen option --- docs/config/index.md | 10 +++++++++- packages/vite/src/node/cli.ts | 20 ++++++++++++++------ packages/vite/src/node/config.ts | 6 +++++- packages/vite/src/node/logger.ts | 16 +++++++++------- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index a26eca74b61ac7..1c62c7f84a9a96 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -201,6 +201,13 @@ export default ({ command, mode }) => { Adjust console output verbosity. Default is `'info'`. +### clearScreen + +- **Type:** `boolean` +- **Default:** `true` + + Set to `false` to prevent Vite from clearing the terminal screen when logging certain messages. Via command line, use `--clearScreen false`. + ## Server Options ### server.host @@ -234,8 +241,9 @@ export default ({ command, mode }) => { - **Type:** `boolean | string` Automatically open the app in the browser on server start. When the value is a string, it will be used as the URL's pathname. - + **Example:** + ```js export default { server: { diff --git a/packages/vite/src/node/cli.ts b/packages/vite/src/node/cli.ts index 23bb9f6c21f84e..c3fdf6862f08b6 100644 --- a/packages/vite/src/node/cli.ts +++ b/packages/vite/src/node/cli.ts @@ -22,6 +22,7 @@ interface GlobalCLIOptions { m?: string logLevel?: LogLevel l?: LogLevel + clearScreen?: boolean } /** @@ -42,6 +43,7 @@ function cleanOptions(options: GlobalCLIOptions) { delete ret.m delete ret.logLevel delete ret.l + delete ret.clearScreen return ret } @@ -49,6 +51,7 @@ cli .option('-c, --config ', `[string] use specified config file`) .option('-r, --root ', `[string] use specified root directory`) .option('-l, --logLevel ', `[string] silent | error | warn | all`) + .option('--clearScreen', `[boolean] allow/disable clear screen when logging`) .option('-d, --debug [feat]', `[string | boolean] show debug logs`) .option('-f, --filter ', `[string] filter debug logs`) @@ -77,12 +80,14 @@ cli mode: options.mode, configFile: options.config, logLevel: options.logLevel, + clearScreen: options.clearScreen, server: cleanOptions(options) as ServerOptions }) await server.listen() } catch (e) { - const logError = createLogger(options.logLevel).error - logError(chalk.red(`error when starting dev server:\n${e.stack}`)) + createLogger(options.logLevel).error( + chalk.red(`error when starting dev server:\n${e.stack}`) + ) process.exit(1) } }) @@ -125,11 +130,13 @@ cli mode: options.mode, configFile: options.config, logLevel: options.logLevel, + clearScreen: options.clearScreen, build: cleanOptions(options) as BuildOptions }) } catch (e) { - const logError = createLogger(options.logLevel).error - logError(chalk.red(`error during build:\n${e.stack}`)) + createLogger(options.logLevel).error( + chalk.red(`error during build:\n${e.stack}`) + ) process.exit(1) } }) @@ -156,8 +163,9 @@ cli ) await optimizeDeps(config, options.force, true) } catch (e) { - const logError = createLogger(options.logLevel).error - logError(chalk.red(`error when optimizing deps:\n${e.stack}`)) + createLogger(options.logLevel).error( + chalk.red(`error when optimizing deps:\n${e.stack}`) + ) process.exit(1) } } diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index d1708d487a8492..c9945c5364e889 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -98,6 +98,10 @@ export interface UserConfig { * Default: 'info' */ logLevel?: LogLevel + /** + * Default: true + */ + clearScreen?: boolean } export interface InlineConfig extends UserConfig { @@ -237,7 +241,7 @@ export async function resolveConfig( assetsInclude(file: string) { return DEFAULT_ASSETS_RE.test(file) || assetsFilter(file) }, - logger: createLogger(config.logLevel) + logger: createLogger(config.logLevel, config.clearScreen) } resolved.plugins = await resolvePlugins( diff --git a/packages/vite/src/node/logger.ts b/packages/vite/src/node/logger.ts index 262a491b3b8791..5d8988dc8958d8 100644 --- a/packages/vite/src/node/logger.ts +++ b/packages/vite/src/node/logger.ts @@ -35,8 +35,12 @@ function clearScreen() { readline.clearScreenDown(process.stdout) } -export function createLogger(level: LogLevel = 'info'): Logger { +export function createLogger( + level: LogLevel = 'info', + allowClearScreen = true +): Logger { const thresh = LogLevels[level] + const clear = allowClearScreen ? clearScreen : () => {} function output(type: LogType, msg: string, options: LogOptions = {}) { if (thresh >= LogLevels[type]) { @@ -49,23 +53,21 @@ export function createLogger(level: LogLevel = 'info'): Logger { : type === 'warn' ? chalk.yellow.bold(`[vite]`) : chalk.red.bold(`[vite]`) - return `${chalk.dim( - new Date().toLocaleTimeString() - )} ${tag} ${msg}` + return `${chalk.dim(new Date().toLocaleTimeString())} ${tag} ${msg}` } else { return msg } } if (type === lastType && msg === lastMsg) { sameCount++ - clearScreen() + clear() console[method](format(), chalk.yellow(`(x${sameCount + 1})`)) } else { sameCount = 0 lastMsg = msg lastType = type if (options.clear) { - clearScreen() + clear() } console[method](format()) } @@ -84,7 +86,7 @@ export function createLogger(level: LogLevel = 'info'): Logger { }, clearScreen(type) { if (thresh >= LogLevels[type]) { - clearScreen() + clear() } } } From 8401c8912151ca2c38a3a9e64779d86347eeb96b Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 14 Jan 2021 15:10:27 -0500 Subject: [PATCH 085/514] release: v2.0.0-beta.28 --- packages/vite/CHANGELOG.md | 20 ++++++++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 7ff0d820506bca..0a1ee8babbf763 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,23 @@ +# [2.0.0-beta.28](https://github.com/vitejs/vite/compare/v2.0.0-beta.27...v2.0.0-beta.28) (2021-01-14) + + +### Bug Fixes + +* alias should work for optimized deps ([54dab71](https://github.com/vitejs/vite/commit/54dab71e41cdd9f516460d153b024d0c0cc05097)) +* serve out of root static file on windows ([#1537](https://github.com/vitejs/vite/issues/1537)) ([506bf2d](https://github.com/vitejs/vite/commit/506bf2d542a27ee19a1b1b2d05aad845f4387cf6)) +* **dev:** correct responce for html qurey ([#1526](https://github.com/vitejs/vite/issues/1526)) ([49d294d](https://github.com/vitejs/vite/commit/49d294d36d0f32d00a025a03017c9049d3f48ebd)), closes [#1524](https://github.com/vitejs/vite/issues/1524) +* **optimizer:** should respect rollup external during pre-bundling ([db97317](https://github.com/vitejs/vite/commit/db9731753abf36563172b02961ded54be23dd215)), closes [#1528](https://github.com/vitejs/vite/issues/1528) + + +### Features + +* add clearScreen option ([c5c3298](https://github.com/vitejs/vite/commit/c5c32982f207055229b6bce61ce205d8d20db023)) +* close server on sigint/sigterm ([4338d7d](https://github.com/vitejs/vite/commit/4338d7d6f32c8e0e67ff58f0cb8c1a9120294756)), closes [#1525](https://github.com/vitejs/vite/issues/1525) +* support specifying URL path via server.open option ([#1514](https://github.com/vitejs/vite/issues/1514)) ([25e9c44](https://github.com/vitejs/vite/commit/25e9c44992c8b868cec97dbdeddd3a4837d5bb07)) +* support using vite as a middleware ([960b420](https://github.com/vitejs/vite/commit/960b42068579dddc2c216720a7f16d8d189e8225)) + + + # [2.0.0-beta.27](https://github.com/vitejs/vite/compare/v2.0.0-beta.26...v2.0.0-beta.27) (2021-01-13) diff --git a/packages/vite/package.json b/packages/vite/package.json index 43fce90e032e03..60a6320a0fb884 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.27", + "version": "2.0.0-beta.28", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From fe7238c530533d7ea7bff20ce97485669c7dfb46 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 14 Jan 2021 15:19:59 -0500 Subject: [PATCH 086/514] fix: fix graceful shutdown on sigint --- packages/vite/src/node/server/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 21b10378695913..ab6580a181eb73 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -248,8 +248,15 @@ export async function createServer( } } - process.once('SIGINT', server.close) - process.once('SIGTERM', server.close) + const onExit = async () => { + try { + await server.close() + } finally { + process.exit(0) + } + } + process.once('SIGINT', onExit) + process.once('SIGTERM', onExit) watcher.on('change', async (file) => { file = normalizePath(file) From 7a1261b51695cbe7d41da6835c360b9bb26d189e Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 14 Jan 2021 15:20:30 -0500 Subject: [PATCH 087/514] fix: warn failed source map load instead of erroring --- .../vite/src/node/server/transformRequest.ts | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index 1518545b5a2b0e..cb5e7808a179c9 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -27,7 +27,12 @@ export interface TransformResult { export async function transformRequest( url: string, - { config: { root }, pluginContainer, moduleGraph, watcher }: ViteDevServer + { + config: { root, logger }, + pluginContainer, + moduleGraph, + watcher + }: ViteDevServer ): Promise { url = removeTimestampQuery(url) const prettyUrl = isDebug ? prettifyUrl(url, root) : '' @@ -62,10 +67,16 @@ export async function transformRequest( } } if (code) { - map = ( - convertSourceMap.fromSource(code) || - convertSourceMap.fromMapFileSource(code, path.dirname(file)) - )?.toObject() + try { + map = ( + convertSourceMap.fromSource(code) || + convertSourceMap.fromMapFileSource(code, path.dirname(file)) + )?.toObject() + } catch (e) { + logger.warn(`Failed to load source map for ${url}.`, { + timestamp: true + }) + } } } else { isDebug && debugLoad(`${timeFrom(loadStart)} [plugin] ${prettyUrl}`) From a04db16f0329cfa7ef97d0f58f36189b391494a0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 14 Jan 2021 15:25:06 -0500 Subject: [PATCH 088/514] refactor: do not intercept sigint --- packages/vite/src/node/server/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index ab6580a181eb73..0bfa736e8f8267 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -248,15 +248,13 @@ export async function createServer( } } - const onExit = async () => { + process.once('SIGTERM', async () => { try { await server.close() } finally { process.exit(0) } - } - process.once('SIGINT', onExit) - process.once('SIGTERM', onExit) + }) watcher.on('change', async (file) => { file = normalizePath(file) From 4579c382d4a1b0385510bb708f74305c87c4a68a Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 14 Jan 2021 15:26:40 -0500 Subject: [PATCH 089/514] fix(optimizer): fix empty exclude filter --- packages/vite/src/node/optimizer/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 31a1e1db53d367..eb7f9fea868ab7 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -320,14 +320,14 @@ async function resolveQualifiedDeps( const deps = Object.keys(pkg.dependencies || {}) const linked: string[] = [] const excludeFilter = - exclude && createFilter(exclude, null, { resolve: false }) + exclude && createFilter(null, exclude, { resolve: false }) for (const id of deps) { if (include && include.includes(id)) { // already force included continue } - if (excludeFilter && excludeFilter(id)) { + if (excludeFilter && !excludeFilter(id)) { debug(`skipping ${id} (excluded)`) continue } From bdec0f87e826fbfafc3f76ace6abcce2336eefef Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 14 Jan 2021 15:33:04 -0500 Subject: [PATCH 090/514] release: v2.0.0-beta.29 --- packages/vite/CHANGELOG.md | 11 +++++++++++ packages/vite/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 0a1ee8babbf763..6c0b6ee9269eac 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,14 @@ +# [2.0.0-beta.29](https://github.com/vitejs/vite/compare/v2.0.0-beta.28...v2.0.0-beta.29) (2021-01-14) + + +### Bug Fixes + +* **optimizer:** fix empty exclude filter ([4579c38](https://github.com/vitejs/vite/commit/4579c382d4a1b0385510bb708f74305c87c4a68a)) +* fix graceful shutdown on sigint ([fe7238c](https://github.com/vitejs/vite/commit/fe7238c530533d7ea7bff20ce97485669c7dfb46)) +* warn failed source map load instead of erroring ([7a1261b](https://github.com/vitejs/vite/commit/7a1261b51695cbe7d41da6835c360b9bb26d189e)) + + + # [2.0.0-beta.28](https://github.com/vitejs/vite/compare/v2.0.0-beta.27...v2.0.0-beta.28) (2021-01-14) diff --git a/packages/vite/package.json b/packages/vite/package.json index 60a6320a0fb884..e6402a359d26a6 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.28", + "version": "2.0.0-beta.29", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 9f54510b30e624e10f13bb7d52722a00fc185242 Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Fri, 15 Jan 2021 16:28:45 +0200 Subject: [PATCH 091/514] docs: Add Packages table (#1550) [skip ci] --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index bb26db71c709de..395af493b2e07a 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,17 @@ In addition, Vite is highly extensible via its [Plugin API](https://vitejs.dev/g Vite is now in 2.0 beta. Check out the [Migration Guide](https://vitejs.dev/guide/migration.html) if you are upgrading from 1.x. +## Packages + +| Package | Version | +|---------------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------| +| [vite](packages/vite) | [![vite version](https://img.shields.io/npm/v/vite.svg?label=%20)](packages/vite/CHANGELOG.md) | +| [@vitejs/plugin-vue](packages/plugin-vue) | [![plugin-vue version](https://img.shields.io/npm/v/@vitejs/plugin-vue.svg?label=%20)](packages/plugin-vue/CHANGELOG.md) | +| [@vitejs/plugin-vue-jsx](packages/plugin-vue-jsx) | [![plugin-vue-jsx version](https://img.shields.io/npm/v/@vitejs/plugin-vue-jsx.svg?label=%20)](packages/plugin-vue-jsx/CHANGELOG.md) | +| [@vitejs/plugin-react-refresh](packages/plugin-react-refresh) | [![plugin-react-refresh version](https://img.shields.io/npm/v/@vitejs/plugin-react-refresh.svg?label=%20)](packages/plugin-react-refresh/CHANGELOG.md) | +| [@vitejs/plugin-legacy](packages/plugin-legacy) | [![plugin-legacy version](https://img.shields.io/npm/v/@vitejs/plugin-legacy.svg?label=%20)](packages/plugin-legacy/CHANGELOG.md) | +| [@vitejs/create-app](packages/create-app) | [![create-app version](https://img.shields.io/npm/v/@vitejs/create-app.svg?label=%20)](packages/create-app/CHANGELOG.md) + ## Contribution See [Contributing Guide](https://github.com/vitejs/vite/tree/main/.github/contributing.md). From bd3b1bfd83488b05a188a9d1c7093e3003721d91 Mon Sep 17 00:00:00 2001 From: CHOYSEN <582511362@qq.com> Date: Fri, 15 Jan 2021 22:36:41 +0800 Subject: [PATCH 092/514] fix(config): delete cache correctly when restarting server (#1541) --- packages/vite/src/node/config.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index c9945c5364e889..bd2543819912fd 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -433,7 +433,7 @@ export async function loadConfigFromFile( // 1. try to directly require the module (assuming commonjs) try { // clear cache in case of server restart - delete require.cache[resolvedPath] + delete require.cache[require.resolve(resolvedPath)] userConfig = require(resolvedPath) debug(`cjs config loaded in ${Date.now() - start}ms`) } catch (e) { @@ -530,7 +530,8 @@ async function loadConfigFromBundledFile( defaultLoader(module, filename) } } - delete require.cache[fileName] + // clear cache in case of server restart + delete require.cache[require.resolve(fileName)] const raw = require(fileName) const config = raw.__esModule ? raw.default : raw require.extensions[extension] = defaultLoader From 2ce1efa0871b9d7111ae8265c3f362fb45037664 Mon Sep 17 00:00:00 2001 From: qicoo <757271842@qq.com> Date: Fri, 15 Jan 2021 22:37:32 +0800 Subject: [PATCH 093/514] docs: typo (#1540) --- docs/guide/dep-pre-bundling.md | 2 +- packages/vite/types/chokidar.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guide/dep-pre-bundling.md b/docs/guide/dep-pre-bundling.md index ec66ba2a8eef9a..a574e3772ead8e 100644 --- a/docs/guide/dep-pre-bundling.md +++ b/docs/guide/dep-pre-bundling.md @@ -54,7 +54,7 @@ Some dependencies may be designed to be used via deep imports, e.g. `firebase` e ## Dependency Compatibility -While Vite tries its best to accomodate non-ESM dependencies, there are going to be some dependencies that won't work out of the box. The most common types are those that import Node.js built-in modules (e.g. `os` or `path`) and expect the bundler to automatically shim them. These packages are typically written assuming all users will be consuming it with `webpack`, but such usage does not make sense when targeting browser environments. +While Vite tries its best to accommodate non-ESM dependencies, there are going to be some dependencies that won't work out of the box. The most common types are those that import Node.js built-in modules (e.g. `os` or `path`) and expect the bundler to automatically shim them. These packages are typically written assuming all users will be consuming it with `webpack`, but such usage does not make sense when targeting browser environments. When using Vite, it is strongly recommended to always prefer dependencies that provide ESM formats. This will make your build faster, and results in smaller production bundles due to more efficient tree-shaking. diff --git a/packages/vite/types/chokidar.d.ts b/packages/vite/types/chokidar.d.ts index a1ca6af2a05c15..743c2cb3e19d5b 100644 --- a/packages/vite/types/chokidar.d.ts +++ b/packages/vite/types/chokidar.d.ts @@ -154,7 +154,7 @@ export interface WatchOptions { /** * Whether to use the `fsevents` watching interface if available. When set to `true` explicitly - * and `fsevents` is available this supercedes the `usePolling` setting. When set to `false` on + * and `fsevents` is available this supersedes the `usePolling` setting. When set to `false` on * OS X, `usePolling: true` becomes the default. */ useFsEvents?: boolean From d8754deeb16ef0d86b17dfa2a3394d0919bcd72e Mon Sep 17 00:00:00 2001 From: underfin Date: Fri, 15 Jan 2021 22:39:18 +0800 Subject: [PATCH 094/514] fix(plugin-vue): sfc src import respect alias (#1544) fix #1542 --- .../playground/vue/src-import/SrcImport.vue | 2 +- packages/playground/vue/vite.config.ts | 4 ++ packages/plugin-vue/src/main.ts | 57 ++++++++++++------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/packages/playground/vue/src-import/SrcImport.vue b/packages/playground/vue/src-import/SrcImport.vue index 9ff8831029f10c..ac7ec78c869e65 100644 --- a/packages/playground/vue/src-import/SrcImport.vue +++ b/packages/playground/vue/src-import/SrcImport.vue @@ -1,3 +1,3 @@ - + diff --git a/packages/playground/vue/vite.config.ts b/packages/playground/vue/vite.config.ts index 707f3fbe5a89ce..b528b36535c3c9 100644 --- a/packages/playground/vue/vite.config.ts +++ b/packages/playground/vue/vite.config.ts @@ -1,8 +1,12 @@ +import path from 'path' import { defineConfig } from 'vite' import vuePlugin from '@vitejs/plugin-vue' import { vueI18nPlugin } from './CustomBlockPlugin' export default defineConfig({ + alias: { + '/@': __dirname + }, plugins: [vuePlugin(), vueI18nPlugin], build: { // to make tests faster diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index 2f3ace6f081304..1c8fcafa3d0df4 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -42,7 +42,11 @@ export async function transformMain( const hasScoped = descriptor.styles.some((s) => s.scoped) // script - const { code: scriptCode, map } = await genScriptCode(descriptor, options) + const { code: scriptCode, map } = await genScriptCode( + descriptor, + options, + pluginContext + ) // template // Check if we can use compile template as inlined render function @@ -57,7 +61,7 @@ export async function transformMain( let templateCode = '' let templateMap if (hasTemplateImport) { - ;({ code: templateCode, map: templateMap } = genTemplateCode( + ;({ code: templateCode, map: templateMap } = await genTemplateCode( descriptor, options, pluginContext @@ -71,10 +75,10 @@ export async function transformMain( : '' // styles - const stylesCode = genStyleCode(descriptor) + const stylesCode = await genStyleCode(descriptor, pluginContext) // custom blocks - const customBlocksCode = genCustomBlockCode(descriptor) + const customBlocksCode = await genCustomBlockCode(descriptor, pluginContext) const output: string[] = [ scriptCode, @@ -148,7 +152,7 @@ export async function transformMain( } } -function genTemplateCode( +async function genTemplateCode( descriptor: SFCDescriptor, options: ResolvedOptions, pluginContext: PluginContext @@ -167,7 +171,7 @@ function genTemplateCode( ) } else { if (template.src) { - linkSrcToDescriptor(template.src, descriptor) + await linkSrcToDescriptor(template.src, descriptor, pluginContext) } const src = template.src || descriptor.filename const srcQuery = template.src ? `&src` : `` @@ -184,7 +188,8 @@ function genTemplateCode( async function genScriptCode( descriptor: SFCDescriptor, - options: ResolvedOptions + options: ResolvedOptions, + pluginContext: PluginContext ): Promise<{ code: string map: RawSourceMap @@ -213,7 +218,7 @@ async function genScriptCode( } } else { if (script.src) { - linkSrcToDescriptor(script.src, descriptor) + await linkSrcToDescriptor(script.src, descriptor, pluginContext) } const src = script.src || descriptor.filename const langFallback = (script.src && path.extname(src).slice(1)) || 'js' @@ -231,13 +236,17 @@ async function genScriptCode( } } -function genStyleCode(descriptor: SFCDescriptor) { +async function genStyleCode( + descriptor: SFCDescriptor, + pluginContext: PluginContext +) { let stylesCode = `` let hasCSSModules = false if (descriptor.styles.length) { - descriptor.styles.forEach((style, i) => { + for (let i = 0; i < descriptor.styles.length; i++) { + const style = descriptor.styles[i] if (style.src) { - linkSrcToDescriptor(style.src, descriptor) + await linkSrcToDescriptor(style.src, descriptor, pluginContext) } const src = style.src || descriptor.filename // do not include module in default query, since we use it to indicate @@ -256,16 +265,20 @@ function genStyleCode(descriptor: SFCDescriptor) { stylesCode += `\nimport ${JSON.stringify(styleRequest)}` } // TODO SSR critical CSS collection - }) + } } return stylesCode } -function genCustomBlockCode(descriptor: SFCDescriptor) { +async function genCustomBlockCode( + descriptor: SFCDescriptor, + pluginContext: PluginContext +) { let code = '' - descriptor.customBlocks.forEach((block, index) => { + for (let index = 0; index < descriptor.customBlocks.length; index++) { + const block = descriptor.customBlocks[index] if (block.src) { - linkSrcToDescriptor(block.src, descriptor) + await linkSrcToDescriptor(block.src, descriptor, pluginContext) } const src = block.src || descriptor.filename const attrsQuery = attrsToQuery(block.attrs, block.type) @@ -274,7 +287,7 @@ function genCustomBlockCode(descriptor: SFCDescriptor) { const request = JSON.stringify(src + query) code += `import block${index} from ${request}\n` code += `if (typeof block${index} === 'function') block${index}(_sfc_main)\n` - }) + } return code } @@ -298,11 +311,13 @@ function genCSSModulesCode( * with its owner SFC descriptor so that we can get the information about * the owner SFC when compiling that file in the transform phase. */ -function linkSrcToDescriptor(src: string, descriptor: SFCDescriptor) { - const srcFile = path.posix.resolve( - path.posix.dirname(descriptor.filename), - src - ) +async function linkSrcToDescriptor( + src: string, + descriptor: SFCDescriptor, + pluginContext: PluginContext +) { + const srcFile = + (await pluginContext.resolve(src, descriptor.filename))?.id || src setDescriptor(srcFile, descriptor) } From 55b05dba3d157da72eaf9c445b0bb5084b9858d0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 15 Jan 2021 09:50:34 -0500 Subject: [PATCH 095/514] fix(config): load native esm ts config string with base64 encoding fix #1548 --- packages/vite/src/node/config.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index bd2543819912fd..066c38fe4cd4dd 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -415,7 +415,11 @@ export async function loadConfigFromFile( const code = await bundleConfigFile(resolvedPath, 'es') userConfig = ( await eval( - `import(${JSON.stringify(`data:text/javascript,${code}`)})` + `import(${JSON.stringify( + `data:text/javascript;base64,${Buffer.from(code).toString( + 'base64' + )}` + )})` ) ).default debug(`TS + native esm config loaded in ${Date.now() - start}ms`) From 74b6e3a7e158d84aed36b8cf062a2f726b0f0c4a Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 15 Jan 2021 10:03:32 -0500 Subject: [PATCH 096/514] release: v2.0.0-beta.30 --- packages/vite/CHANGELOG.md | 10 ++++++++++ packages/vite/package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 6c0b6ee9269eac..03eea084830577 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,13 @@ +# [2.0.0-beta.30](https://github.com/vitejs/vite/compare/v2.0.0-beta.29...v2.0.0-beta.30) (2021-01-15) + + +### Bug Fixes + +* **config:** delete cache correctly when restarting server ([#1541](https://github.com/vitejs/vite/issues/1541)) ([bd3b1bf](https://github.com/vitejs/vite/commit/bd3b1bfd83488b05a188a9d1c7093e3003721d91)) +* **config:** load native esm ts config string with base64 encoding ([55b05db](https://github.com/vitejs/vite/commit/55b05dba3d157da72eaf9c445b0bb5084b9858d0)), closes [#1548](https://github.com/vitejs/vite/issues/1548) + + + # [2.0.0-beta.29](https://github.com/vitejs/vite/compare/v2.0.0-beta.28...v2.0.0-beta.29) (2021-01-14) diff --git a/packages/vite/package.json b/packages/vite/package.json index e6402a359d26a6..4220562bc45fd2 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.29", + "version": "2.0.0-beta.30", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 6a9a4aaf8ef78dc37629fd6962fc6d057f126c53 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 15 Jan 2021 10:04:06 -0500 Subject: [PATCH 097/514] release: plugin-vue@1.0.6 --- packages/plugin-vue/CHANGELOG.md | 9 +++++++++ packages/plugin-vue/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/plugin-vue/CHANGELOG.md b/packages/plugin-vue/CHANGELOG.md index e18bf1c3b16d67..deaa35c4b1db99 100644 --- a/packages/plugin-vue/CHANGELOG.md +++ b/packages/plugin-vue/CHANGELOG.md @@ -1,3 +1,12 @@ +## [1.0.6](https://github.com/vitejs/vite/compare/plugin-vue@1.0.5...plugin-vue@1.0.6) (2021-01-15) + + +### Bug Fixes + +* **plugin-vue:** sfc src import respect alias ([#1544](https://github.com/vitejs/vite/issues/1544)) ([d8754de](https://github.com/vitejs/vite/commit/d8754deeb16ef0d86b17dfa2a3394d0919bcd72e)), closes [#1542](https://github.com/vitejs/vite/issues/1542) + + + ## [1.0.5](https://github.com/vitejs/vite/compare/plugin-vue@1.0.4...plugin-vue@1.0.5) (2021-01-09) diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index e9f7cdef60f536..b7463a1f20bf7d 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-vue", - "version": "1.0.5", + "version": "1.0.6", "license": "MIT", "author": "Evan You", "files": [ From 12b706d6ecd99c98f326deae53f9aa79cd8a81f4 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 15 Jan 2021 10:28:22 -0500 Subject: [PATCH 098/514] fix(resolve): also respect browser mapping of dependencies fix #1547 --- .../resolve/browser-field/out/esm.browser.js | 1 + .../resolve/browser-field/package.json | 3 +- packages/vite/src/node/plugins/resolve.ts | 53 ++++++++++++++----- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/packages/playground/resolve/browser-field/out/esm.browser.js b/packages/playground/resolve/browser-field/out/esm.browser.js index a1b93c89f71dd4..bddf03df0b0c22 100644 --- a/packages/playground/resolve/browser-field/out/esm.browser.js +++ b/packages/playground/resolve/browser-field/out/esm.browser.js @@ -1 +1,2 @@ +import jsdom from 'jsdom' // should be redireted to empty module export default '[success] resolve browser field' diff --git a/packages/playground/resolve/browser-field/package.json b/packages/playground/resolve/browser-field/package.json index 65cf0697d576f2..76d68b2ff25d57 100644 --- a/packages/playground/resolve/browser-field/package.json +++ b/packages/playground/resolve/browser-field/package.json @@ -5,6 +5,7 @@ "main": "out/cjs.node.js", "browser": { "./out/cjs.node.js": "./out/esm.browser.js", - "./not-browser.js": false + "./not-browser.js": false, + "jsdom": false } } diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 10319b912f5680..ae5bf89e268135 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -112,21 +112,16 @@ export function resolvePlugin( const basedir = importer ? path.dirname(importer) : process.cwd() let fsPath = path.resolve(basedir, id) // handle browser field mapping for relative imports - const pkg = importer && idToPkgMap.get(importer) - if (pkg && isObject(pkg.data.browser)) { - const pkgRelativePath = './' + slash(path.relative(pkg.dir, fsPath)) - const browserMappedPath = mapWithBrowserField( - pkgRelativePath, - pkg.data.browser - ) - if (browserMappedPath) { - fsPath = path.resolve(pkg.dir, browserMappedPath) - } else { - return browserExternalId - } + + if ( + (res = tryResolveBrowserMapping(fsPath, importer, true, isProduction)) + ) { + return res } + if ((res = tryFsResolve(fsPath, isProduction))) { isDebug && debug(`[relative] ${chalk.cyan(id)} -> ${chalk.dim(res)}`) + const pkg = idToPkgMap.get(id) if (pkg) { idToPkgMap.set(res, pkg) return { @@ -164,6 +159,12 @@ export function resolvePlugin( return res } + if ( + (res = tryResolveBrowserMapping(id, importer, false, isProduction)) + ) { + return res + } + if ( (res = tryNodeResolve( id, @@ -535,6 +536,34 @@ function resolveDeepImport( } } +function tryResolveBrowserMapping( + id: string, + importer: string | undefined, + isFilePath: boolean, + isProduction: boolean +) { + let res: string | undefined + const pkg = importer && idToPkgMap.get(importer) + if (pkg && isObject(pkg.data.browser)) { + const mapId = isFilePath ? './' + slash(path.relative(pkg.dir, id)) : id + const browserMappedPath = mapWithBrowserField(mapId, pkg.data.browser) + if (browserMappedPath) { + const fsPath = path.resolve(pkg.dir, browserMappedPath) + if ((res = tryFsResolve(fsPath, isProduction))) { + isDebug && + debug(`[browser mapped] ${chalk.cyan(id)} -> ${chalk.dim(res)}`) + idToPkgMap.set(res, pkg) + return { + id: res, + moduleSideEffects: pkg.hasSideEffects(res) + } + } + } else { + return browserExternalId + } + } +} + /** * given a relative path in pkg dir, * return a relative path in pkg dir, From 4a7d2ebca1719d83c22d7dce5214e61f7906a772 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 16 Jan 2021 13:45:16 -0500 Subject: [PATCH 099/514] fix: workaround for ts config + native esm w/ imports fix #1560 --- packages/vite/src/node/config.ts | 37 ++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 066c38fe4cd4dd..6eed677aa9638f 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -8,7 +8,12 @@ import { CSSOptions } from './plugins/css' import { createDebugger, isObject, lookupFile, normalizePath } from './utils' import { resolvePlugins } from './plugins' import chalk from 'chalk' -import { ESBuildOptions, esbuildPlugin } from './plugins/esbuild' +import { + ESBuildOptions, + esbuildPlugin, + stopService, + transformWithEsbuild +} from './plugins/esbuild' import dotenv from 'dotenv' import dotenvExpand from 'dotenv-expand' import { Alias, AliasOptions } from 'types/alias' @@ -412,16 +417,17 @@ export async function loadConfigFromFile( if (isMjs) { if (isTS) { - const code = await bundleConfigFile(resolvedPath, 'es') + // before we can register loaders without requiring users to run node + // with --experimental-loader themselves, we have to do a hack here: + // transpile the ts config file with esbuild first, write it to disk, + // load it with native Node ESM, then delete the file. + const src = fs.readFileSync(resolvedPath, 'utf-8') + const { code } = await transformWithEsbuild(src, resolvedPath) + fs.writeFileSync(resolvedPath + '.js', code) userConfig = ( - await eval( - `import(${JSON.stringify( - `data:text/javascript;base64,${Buffer.from(code).toString( - 'base64' - )}` - )})` - ) + await eval(`import(resolvedPath + '.js?t=${Date.now()}')`) ).default + fs.unlinkSync(resolvedPath + '.js') debug(`TS + native esm config loaded in ${Date.now() - start}ms`) } else { // using eval to avoid this from being compiled away by TS/Rollup @@ -453,7 +459,7 @@ export async function loadConfigFromFile( // the user has type: "module" in their package.json (#917) // transpile es import syntax to require syntax using rollup. // lazy require rollup (it's actually in dependencies) - const code = await bundleConfigFile(resolvedPath, 'cjs') + const code = await bundleConfigFile(resolvedPath) userConfig = await loadConfigFromBundledFile(resolvedPath, code) debug(`bundled config file loaded in ${Date.now() - start}ms`) } @@ -472,13 +478,12 @@ export async function loadConfigFromFile( chalk.red(`failed to load config from ${resolvedPath}`) ) throw e + } finally { + await stopService() } } -async function bundleConfigFile( - fileName: string, - format: 'cjs' | 'es' -): Promise { +async function bundleConfigFile(fileName: string): Promise { const rollup = require('rollup') as typeof Rollup // node-resolve must be imported since it's bundled const bundle = await rollup.rollup({ @@ -510,8 +515,8 @@ async function bundleConfigFile( const { output: [{ code }] } = await bundle.generate({ - exports: format === 'cjs' ? 'named' : undefined, - format + exports: 'named', + format: 'cjs' }) return code From 571545d4d83e5cb621990b3d14bb19fadd47ae04 Mon Sep 17 00:00:00 2001 From: bompus Date: Sat, 16 Jan 2021 12:13:59 -0700 Subject: [PATCH 100/514] workflow: pre-commit runs prettier on *.html (#1555) --- package.json | 3 + .../create-app/template-preact-ts/index.html | 18 ++--- .../create-app/template-preact/index.html | 18 ++--- .../create-app/template-react-ts/index.html | 18 ++--- packages/create-app/template-react/index.html | 18 ++--- .../create-app/template-vanilla/index.html | 18 ++--- .../create-app/template-vue-ts/index.html | 20 +++--- packages/create-app/template-vue/index.html | 20 +++--- packages/playground/define/index.html | 25 ++++--- packages/playground/env/index.html | 69 +++++++++---------- packages/playground/hmr/index.html | 2 +- packages/playground/html/index.html | 4 +- packages/playground/html/nested/index.html | 4 +- packages/playground/legacy/index.html | 2 +- packages/playground/lib/index.html | 6 +- packages/playground/lib/public/index.html | 8 +-- packages/playground/resolve/index.html | 15 ++-- packages/playground/vue-jsx/index.html | 2 +- packages/playground/wasm/index.html | 15 ++-- 19 files changed, 150 insertions(+), 135 deletions(-) diff --git a/package.json b/package.json index 67bdffab6701f8..8e90c254ce5d48 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,9 @@ "*.ts": [ "eslint", "prettier --parser=typescript --write" + ], + "*.html": [ + "prettier --write" ] } } diff --git a/packages/create-app/template-preact-ts/index.html b/packages/create-app/template-preact-ts/index.html index 1c6e2a4173159b..92317c5fa8b87b 100644 --- a/packages/create-app/template-preact-ts/index.html +++ b/packages/create-app/template-preact-ts/index.html @@ -1,12 +1,12 @@ - - - - Vite App - - -
- - + + + + Vite App + + +
+ + diff --git a/packages/create-app/template-preact/index.html b/packages/create-app/template-preact/index.html index 4afc194c17f59a..3eae0d88a7e737 100644 --- a/packages/create-app/template-preact/index.html +++ b/packages/create-app/template-preact/index.html @@ -1,12 +1,12 @@ - - - - Vite App - - -
- - + + + + Vite App + + +
+ + diff --git a/packages/create-app/template-react-ts/index.html b/packages/create-app/template-react-ts/index.html index f3cb3615318c9a..ec41bbddb0108e 100644 --- a/packages/create-app/template-react-ts/index.html +++ b/packages/create-app/template-react-ts/index.html @@ -1,12 +1,12 @@ - - - - Vite App - - -
- - + + + + Vite App + + +
+ + diff --git a/packages/create-app/template-react/index.html b/packages/create-app/template-react/index.html index a380e811bf0564..09eb0007953fb6 100644 --- a/packages/create-app/template-react/index.html +++ b/packages/create-app/template-react/index.html @@ -1,12 +1,12 @@ - - - - Vite App - - -
- - + + + + Vite App + + +
+ + diff --git a/packages/create-app/template-vanilla/index.html b/packages/create-app/template-vanilla/index.html index 60fd73fa5ae2d7..f75ee97ef1d308 100644 --- a/packages/create-app/template-vanilla/index.html +++ b/packages/create-app/template-vanilla/index.html @@ -1,12 +1,12 @@ - - - - Vite App - - -
- - + + + + Vite App + + +
+ + diff --git a/packages/create-app/template-vue-ts/index.html b/packages/create-app/template-vue-ts/index.html index a508f2037dec8e..11603f878f1226 100644 --- a/packages/create-app/template-vue-ts/index.html +++ b/packages/create-app/template-vue-ts/index.html @@ -1,13 +1,13 @@ - - - - - Vite App - - -
- - + + + + + Vite App + + +
+ + diff --git a/packages/create-app/template-vue/index.html b/packages/create-app/template-vue/index.html index d49c18c6fb142f..030a6ff51bfc6f 100644 --- a/packages/create-app/template-vue/index.html +++ b/packages/create-app/template-vue/index.html @@ -1,13 +1,13 @@ - - - - - Vite App - - -
- - + + + + + Vite App + + +
+ + diff --git a/packages/playground/define/index.html b/packages/playground/define/index.html index 0d8c878a15b3f6..85bad547abc5b1 100644 --- a/packages/playground/define/index.html +++ b/packages/playground/define/index.html @@ -3,15 +3,24 @@

Define

String

Number

Boolean

-

Object

+

Object

+ + diff --git a/packages/playground/env/index.html b/packages/playground/env/index.html index 9489635deda8ad..202a0fae9a3624 100644 --- a/packages/playground/env/index.html +++ b/packages/playground/env/index.html @@ -1,44 +1,37 @@

Environment Variables

+

import.meta.env.BASE_URL:

+

import.meta.env.MODE:

+

import.meta.env.DEV:

+

import.meta.env.PROD:

+

import.meta.env.VITE_CUSTOM_ENV_VARIABLE:

- import.meta.env.BASE_URL: -

-

- import.meta.env.MODE: -

-

- import.meta.env.DEV: -

-

- import.meta.env.PROD: -

-

- import.meta.env.VITE_CUSTOM_ENV_VARIABLE: -

-

- import.meta.env.VITE_EFFECTIVE_MODE_FILE_NAME: -

-

- import.meta.env.VITE_INLINE: -

-

- process.env.NODE_ENV: -

-

- import.meta.env:


+  import.meta.env.VITE_EFFECTIVE_MODE_FILE_NAME: 
 

+

import.meta.env.VITE_INLINE:

+

process.env.NODE_ENV:

+

import.meta.env:

-function text(el, text) { - document.querySelector(el).textContent = text -} - \ No newline at end of file + diff --git a/packages/playground/hmr/index.html b/packages/playground/hmr/index.html index 835b4a145d0694..2b060949d38af0 100644 --- a/packages/playground/hmr/index.html +++ b/packages/playground/hmr/index.html @@ -3,4 +3,4 @@
-
\ No newline at end of file +
diff --git a/packages/playground/html/index.html b/packages/playground/html/index.html index b947033587e2d0..391521a34bb28e 100644 --- a/packages/playground/html/index.html +++ b/packages/playground/html/index.html @@ -1,7 +1,7 @@ - +

Hello

- \ No newline at end of file + diff --git a/packages/playground/html/nested/index.html b/packages/playground/html/nested/index.html index 54dd231a1b9f82..4fb855b783c890 100644 --- a/packages/playground/html/nested/index.html +++ b/packages/playground/html/nested/index.html @@ -1,3 +1,3 @@ - +

Nested

- \ No newline at end of file + diff --git a/packages/playground/legacy/index.html b/packages/playground/legacy/index.html index 44e56f5663ecab..26cb9f4685e81d 100644 --- a/packages/playground/legacy/index.html +++ b/packages/playground/legacy/index.html @@ -1,2 +1,2 @@

- \ No newline at end of file + diff --git a/packages/playground/lib/index.html b/packages/playground/lib/index.html index 87e0039ba64050..3fd11da4e8a829 100644 --- a/packages/playground/lib/index.html +++ b/packages/playground/lib/index.html @@ -3,7 +3,7 @@
\ No newline at end of file + myLib('.demo') + diff --git a/packages/playground/lib/public/index.html b/packages/playground/lib/public/index.html index f205800eebd3e3..3416c1f3952fa9 100644 --- a/packages/playground/lib/public/index.html +++ b/packages/playground/lib/public/index.html @@ -4,12 +4,12 @@
\ No newline at end of file + MyLib('.umd') + diff --git a/packages/playground/resolve/index.html b/packages/playground/resolve/index.html index 5340254e94aed7..1ddfb90704c511 100644 --- a/packages/playground/resolve/index.html +++ b/packages/playground/resolve/index.html @@ -1,7 +1,7 @@

Resolve

Deep import

-

Should show [2,4]:

fail

+

Should show [2,4]:fail

Entry resolving with exports field

fail

@@ -54,9 +54,7 @@

Inline package

yield 8 })() - text('.deep-import', JSON.stringify( - slicedToArray(iterable, 2) - )) + text('.deep-import', JSON.stringify(slicedToArray(iterable, 2))) // exports field import { msg } from 'resolve-exports-path' @@ -108,3 +106,12 @@

Inline package

import { msg as inlineMsg } from './inline-package' text('.inline-pkg', inlineMsg) + + diff --git a/packages/playground/vue-jsx/index.html b/packages/playground/vue-jsx/index.html index aac41137236e7e..a285a008c13a9e 100644 --- a/packages/playground/vue-jsx/index.html +++ b/packages/playground/vue-jsx/index.html @@ -1,2 +1,2 @@
- \ No newline at end of file + diff --git a/packages/playground/wasm/index.html b/packages/playground/wasm/index.html index 0e57ccb0cc6e4b..27bdc8167e064e 100644 --- a/packages/playground/wasm/index.html +++ b/packages/playground/wasm/index.html @@ -19,18 +19,21 @@

When wasm is output, result should be 24

async function testWasm(init, resultElement) { const { exported_func } = await init({ imports: { - imported_func: (res) => resultElement.textContent = res + imported_func: (res) => (resultElement.textContent = res) } }) exported_func() } - document.querySelector('.inline-wasm .run') + document + .querySelector('.inline-wasm .run') .addEventListener('click', async () => - testWasm(light, document.querySelector('.inline-wasm .result'))) + testWasm(light, document.querySelector('.inline-wasm .result')) + ) - document.querySelector('.output-wasm .run') + document + .querySelector('.output-wasm .run') .addEventListener('click', async () => - testWasm(heavy, document.querySelector('.output-wasm .result'))) - + testWasm(heavy, document.querySelector('.output-wasm .result')) + ) From de0ce7e8d0d23e2576efc429c14c6cb17952a09b Mon Sep 17 00:00:00 2001 From: Timo Zander Date: Sun, 17 Jan 2021 20:54:58 +0100 Subject: [PATCH 101/514] chore: fix commit-convention.md RegEx (#1569) [skip ci] --- .github/commit-convention.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/commit-convention.md b/.github/commit-convention.md index 609bbe632e004b..c66c7b9676ab3a 100644 --- a/.github/commit-convention.md +++ b/.github/commit-convention.md @@ -7,7 +7,7 @@ Messages must be matched by the following regex: ``` js -/^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|build|ci|chore|types|wip): .{1,50}/ +/^(revert: )?(feat|fix|docs|dx|refactor|perf|test|workflow|build|ci|chore|types|wip|release|deps)(\(.+\))?: .{1,50}/ ``` #### Examples From 6c4977bfb7c285e9a4b0bb3bd43fd941902d497f Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 18 Jan 2021 09:13:44 -0500 Subject: [PATCH 102/514] release: v2.0.0-beta.31 --- packages/vite/CHANGELOG.md | 10 ++++++++++ packages/vite/package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 03eea084830577..54ab8200db8d29 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,13 @@ +# [2.0.0-beta.31](https://github.com/vitejs/vite/compare/v2.0.0-beta.30...v2.0.0-beta.31) (2021-01-18) + + +### Bug Fixes + +* workaround for ts config + native esm w/ imports ([4a7d2eb](https://github.com/vitejs/vite/commit/4a7d2ebca1719d83c22d7dce5214e61f7906a772)), closes [#1560](https://github.com/vitejs/vite/issues/1560) +* **resolve:** also respect browser mapping of dependencies ([12b706d](https://github.com/vitejs/vite/commit/12b706d6ecd99c98f326deae53f9aa79cd8a81f4)), closes [#1547](https://github.com/vitejs/vite/issues/1547) + + + # [2.0.0-beta.30](https://github.com/vitejs/vite/compare/v2.0.0-beta.29...v2.0.0-beta.30) (2021-01-15) diff --git a/packages/vite/package.json b/packages/vite/package.json index 4220562bc45fd2..0463132c854b44 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.30", + "version": "2.0.0-beta.31", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 54f7889fd0bdeb2025fe6e622a58e5c1b3b359c2 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 14 Jan 2021 10:11:23 -0500 Subject: [PATCH 103/514] wip: save --- packages/vite/package.json | 3 ++ packages/vite/src/node/plugin.ts | 23 +++++++++-- packages/vite/src/node/server/moduleGraph.ts | 4 ++ .../vite/src/node/server/pluginContainer.ts | 35 +++++++++++------ .../vite/src/node/server/ssrModuleLoader.ts | 0 packages/vite/src/node/server/ssrTransform.ts | 39 +++++++++++++++++++ .../vite/src/node/server/transformRequest.ts | 35 ++++++++++++----- packages/vite/types/shims.d.ts | 10 +++++ test.js | 16 ++++++++ yarn.lock | 14 ++++++- 10 files changed, 154 insertions(+), 25 deletions(-) create mode 100644 packages/vite/src/node/server/ssrModuleLoader.ts create mode 100644 packages/vite/src/node/server/ssrTransform.ts create mode 100644 test.js diff --git a/packages/vite/package.json b/packages/vite/package.json index 0463132c854b44..d6c76b24fb6111 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -73,6 +73,8 @@ "@vue/compiler-dom": "^3.0.4", "acorn": "^8.0.4", "acorn-class-fields": "^0.3.7", + "acorn-numeric-separator": "^0.3.6", + "acorn-static-class-features": "^0.2.4", "brotli-size": "^4.0.0", "cac": "^6.6.1", "chalk": "^4.1.0", @@ -87,6 +89,7 @@ "dotenv-expand": "^5.1.0", "enquirer": "^2.3.6", "es-module-lexer": "^0.3.26", + "estree-walker": "^2.0.2", "etag": "^1.8.1", "execa": "^5.0.0", "fast-glob": "^3.2.4", diff --git a/packages/vite/src/node/plugin.ts b/packages/vite/src/node/plugin.ts index a0a0b8ad1b9461..1c71efac969e9e 100644 --- a/packages/vite/src/node/plugin.ts +++ b/packages/vite/src/node/plugin.ts @@ -1,5 +1,10 @@ import { UserConfig } from './config' -import { Plugin as RollupPlugin } from 'rollup' +import { + LoadResult, + Plugin as RollupPlugin, + TransformPluginContext, + TransformResult +} from 'rollup' import { ServerHook } from './server' import { IndexHtmlTransform } from './plugins/html' import { ModuleNode } from './server/moduleGraph' @@ -99,7 +104,19 @@ export interface Plugin extends RollupPlugin { * - If the hook doesn't return a value, the hmr update will be performed as * normal. */ - handleHotUpdate?: ( + handleHotUpdate?( ctx: HmrContext - ) => Array | void | Promise | void> + ): Array | void | Promise | void> + + /** + * SSR-specific load/transform hooks called during SSR module loads. If these + * are not provided, then the normal load/transform hooks will be called if + * present. + */ + ssrLoad?(id: string): Promise | LoadResult + ssrTransform?( + this: TransformPluginContext, + code: string, + id: string + ): Promise | TransformResult } diff --git a/packages/vite/src/node/server/moduleGraph.ts b/packages/vite/src/node/server/moduleGraph.ts index 3f5cdd92293fda..ab8f12ac76dddd 100644 --- a/packages/vite/src/node/server/moduleGraph.ts +++ b/packages/vite/src/node/server/moduleGraph.ts @@ -26,6 +26,8 @@ export class ModuleNode { acceptedHmrDeps = new Set() isSelfAccepting = false transformResult: TransformResult | null = null + ssrTransformResult: TransformResult | null = null + ssrModule: Record | null = null lastHMRTimestamp = 0 constructor(url: string) { @@ -63,6 +65,8 @@ export class ModuleGraph { if (mods) { mods.forEach((mod) => { mod.transformResult = null + mod.ssrTransformResult = null + mod.ssrModule = null }) } } diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index 72f60bc3085356..2cb110f2a7a349 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -51,6 +51,8 @@ import { } from 'rollup' import * as acorn from 'acorn' import acornClassFields from 'acorn-class-fields' +import acornNumericSeparator from 'acorn-numeric-separator' +import acornStaticClassFeatures from 'acorn-static-class-features' import merge from 'merge-source-map' import MagicString from 'magic-string' import { FSWatcher } from 'chokidar' @@ -87,9 +89,10 @@ export interface PluginContainer { transform( code: string, id: string, - inMap?: SourceDescription['map'] + inMap?: SourceDescription['map'], + ssr?: boolean ): Promise - load(id: string): Promise + load(id: string, ssr?: boolean): Promise resolveFileUrl(referenceId: string): string | null close(): Promise } @@ -108,6 +111,12 @@ type PluginContext = Omit< | 'resolveId' > +export let parser = acorn.Parser.extend( + acornClassFields, + acornStaticClassFeatures, + acornNumericSeparator +) + export async function createPluginContainer( { plugins, logger, root, build: { rollupOptions } }: ResolvedConfig, watcher?: FSWatcher @@ -127,7 +136,6 @@ export async function createPluginContainer( // counter for generating unique emitted asset IDs let ids = 0 - let parser = acorn.Parser const MODULES = new Map() const files = new Map() @@ -161,7 +169,6 @@ export async function createPluginContainer( sourceType: 'module', ecmaVersion: 2020, locations: true, - onComment: [], ...opts }) } @@ -371,7 +378,11 @@ export async function createPluginContainer( } if (options.acornInjectPlugins) { parser = acorn.Parser.extend( - ...[acornClassFields].concat(options.acornInjectPlugins) + ...[ + acornClassFields, + acornStaticClassFeatures, + acornNumericSeparator + ].concat(options.acornInjectPlugins) ) } return { @@ -468,12 +479,13 @@ export async function createPluginContainer( } }, - async load(id) { + async load(id, ssr = false) { const ctx = new Context() for (const plugin of plugins) { - if (!plugin.load) continue + const load = (ssr && plugin.ssrLoad) || plugin.load + if (!load) continue ctx._activePlugin = plugin - const result = await plugin.load.call(ctx as any, id) + const result = await load.call(ctx as any, id) if (result != null) { return result } @@ -481,17 +493,18 @@ export async function createPluginContainer( return null }, - async transform(code, id, inMap) { + async transform(code, id, inMap, ssr = false) { const ctx = new TransformContext(id, code, inMap as SourceMap) for (const plugin of plugins) { - if (!plugin.transform) continue + const transform = (ssr && plugin.ssrTransform) || plugin.transform + if (!transform) continue ctx._activePlugin = plugin ctx._activeId = id ctx._activeCode = code const start = Date.now() let result try { - result = await plugin.transform.call(ctx as any, code, id) + result = await transform.call(ctx as any, code, id) } catch (e) { ctx.error(e) } diff --git a/packages/vite/src/node/server/ssrModuleLoader.ts b/packages/vite/src/node/server/ssrModuleLoader.ts new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/packages/vite/src/node/server/ssrTransform.ts b/packages/vite/src/node/server/ssrTransform.ts new file mode 100644 index 00000000000000..84a7a63b81ca89 --- /dev/null +++ b/packages/vite/src/node/server/ssrTransform.ts @@ -0,0 +1,39 @@ +import MagicString from 'magic-string' +import { SourceMap } from 'rollup' +import { TransformResult } from './transformRequest' +import { parser } from './pluginContainer' +import { Node } from 'estree' + +export async function transformForSSR( + code: string, + map: SourceMap | null +): Promise { + const s = new MagicString(code) + + const ast = parser.parse(code, { + sourceType: 'module', + ecmaVersion: 2020, + locations: true + }) as any + + for (const node of ast.body as Node[]) { + // import foo from 'foo' --> foo -> __import_foo__.default + // import { baz } from 'foo' --> baz -> __import_foo__.baz + // import * as ok from 'foo' --> ok -> __import_foo__ + if (node.type === 'ImportDeclaration') { + if (node.specifiers.length) { + } + } + if (node.type === 'ExportNamedDeclaration') { + } + if (node.type === 'ExportDefaultDeclaration') { + } + if (node.type === 'ExportAllDeclaration') { + } + } + + return { + code, + map + } +} diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index cb5e7808a179c9..0a6fe1fc97c777 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -13,6 +13,7 @@ import { timeFrom } from '../utils' import { checkPublicFile } from '../plugins/asset' +import { transformForSSR } from './ssrTransform' const debugLoad = createDebugger('vite:load') const debugTransform = createDebugger('vite:transform') @@ -22,7 +23,11 @@ const isDebug = !!process.env.DEBUG export interface TransformResult { code: string map: SourceMap | null - etag: string + etag?: string +} + +export interface TransformOptions { + ssr?: boolean } export async function transformRequest( @@ -32,13 +37,16 @@ export async function transformRequest( pluginContainer, moduleGraph, watcher - }: ViteDevServer + }: ViteDevServer, + { ssr }: TransformOptions = {} ): Promise { url = removeTimestampQuery(url) const prettyUrl = isDebug ? prettifyUrl(url, root) : '' // check if we have a fresh cache - const cached = (await moduleGraph.getModuleByUrl(url))?.transformResult + const module = await moduleGraph.getModuleByUrl(url) + const cached = + module && (ssr ? module.ssrTransformResult : module.transformResult) if (cached) { isDebug && debugCache(`[memory] ${prettyUrl}`) return cached @@ -53,7 +61,7 @@ export async function transformRequest( // load const loadStart = Date.now() - const loadResult = await pluginContainer.load(id) + const loadResult = await pluginContainer.load(id, ssr) if (loadResult == null) { // try fallback loading it from fs as string // if the file is a binary, there should be a plugin that already loaded it @@ -110,7 +118,7 @@ export async function transformRequest( // transform const transformStart = Date.now() - const transformResult = await pluginContainer.transform(code, id, map) + const transformResult = await pluginContainer.transform(code, id, map, ssr) if ( transformResult == null || (typeof transformResult === 'object' && transformResult.code == null) @@ -130,9 +138,16 @@ export async function transformRequest( } } - return (mod.transformResult = { - code, - map, - etag: getEtag(code, { weak: true }) - } as TransformResult) + if (ssr) { + return (mod.ssrTransformResult = await transformForSSR( + code, + map as SourceMap + )) + } else { + return (mod.transformResult = { + code, + map, + etag: getEtag(code, { weak: true }) + } as TransformResult) + } } diff --git a/packages/vite/types/shims.d.ts b/packages/vite/types/shims.d.ts index 5f4b61afaf104c..90ffcab496aaab 100644 --- a/packages/vite/types/shims.d.ts +++ b/packages/vite/types/shims.d.ts @@ -22,6 +22,16 @@ declare module 'acorn-class-fields' { export = plugin } +declare module 'acorn-static-class-features' { + const plugin: any + export default plugin +} + +declare module 'acorn-numeric-separator' { + const plugin: any + export default plugin +} + declare module 'connect-history-api-fallback' { const plugin: any export = plugin diff --git a/test.js b/test.js new file mode 100644 index 00000000000000..88d8a486d841fc --- /dev/null +++ b/test.js @@ -0,0 +1,16 @@ +const { + transformForSSR +} = require('./packages/vite/dist/node/server/ssrTransform') + +;(async () => { + const { code } = await transformForSSR(` + import { createApp as _createApp } from 'vue' + import App from './App.vue' + + export function createApp() { + return _createApp(App) + } + `) + + console.log(code) +})() diff --git a/yarn.lock b/yarn.lock index b191321db6304e..512e8351a04bbc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1348,11 +1348,23 @@ acorn-jsx@^5.3.1: resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.1.tgz#fc8661e11b7ac1539c47dbfea2e72b3af34d267b" integrity sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng== +acorn-numeric-separator@^0.3.6: + version "0.3.6" + resolved "https://registry.yarnpkg.com/acorn-numeric-separator/-/acorn-numeric-separator-0.3.6.tgz#af7f0abaf8e74bd9ca1117602954d0a3b75804f3" + integrity sha512-jUr5esgChu4k7VzesH/Nww3EysuyGJJcTEEiXqILUFKpO96PNyEXmK21M6nE0TSqGA1PeEg1MzgqJaoFsn9JMw== + acorn-private-class-elements@^0.2.7: version "0.2.7" resolved "https://registry.yarnpkg.com/acorn-private-class-elements/-/acorn-private-class-elements-0.2.7.tgz#b14902c705bcff267adede1c9f61c1a317ef95d2" integrity sha512-+GZH2wOKNZOBI4OOPmzpo4cs6mW297sn6fgIk1dUI08jGjhAaEwvC39mN2gJAg2lmAQJ1rBkFqKWonL3Zz6PVA== +acorn-static-class-features@^0.2.4: + version "0.2.4" + resolved "https://registry.yarnpkg.com/acorn-static-class-features/-/acorn-static-class-features-0.2.4.tgz#a0f5261dd483f25196716854f2d7652a1deb39ee" + integrity sha512-5X4mpYq5J3pdndLmIB0+WtFd/mKWnNYpuTlTzj32wUu/PMmEGOiayQ5UrqgwdBNiaZBtDDh5kddpP7Yg2QaQYA== + dependencies: + acorn-private-class-elements "^0.2.7" + acorn-walk@^7.1.1: version "7.2.0" resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-7.2.0.tgz#0de889a601203909b0fbe07b8938dc21d2e967bc" @@ -2909,7 +2921,7 @@ estree-walker@^1.0.1: resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700" integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg== -estree-walker@^2.0.1: +estree-walker@^2.0.1, estree-walker@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac" integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w== From 10c1e15b8b3e23ba32f61965397b2da9c7bfcd6c Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 14 Jan 2021 18:21:47 -0500 Subject: [PATCH 104/514] wip: save --- packages/vite/src/node/server/index.ts | 26 ++++++++--- packages/vite/src/node/server/moduleGraph.ts | 12 +++-- .../vite/src/node/server/ssrModuleLoader.ts | 34 ++++++++++++++ packages/vite/src/node/server/ssrTransform.ts | 45 ++++++++++++++++--- .../vite/src/node/server/transformRequest.ts | 8 ++-- 5 files changed, 103 insertions(+), 22 deletions(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 0bfa736e8f8267..4f6c1203bf17c3 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -34,13 +34,14 @@ import { handleHMRUpdate, HmrOptions } from './hmr' import { openBrowser } from './openBrowser' import launchEditorMiddleware from 'launch-editor-middleware' import { TransformResult } from 'rollup' -import { transformRequest } from './transformRequest' +import { TransformOptions, transformRequest } from './transformRequest' import { transformWithEsbuild, EsbuildTransformResult } from '../plugins/esbuild' import { TransformOptions as EsbuildTransformOptions } from 'esbuild' import { DepOptimizationMetadata, optimizeDeps } from '../optimizer' +import { ssrLoadModule } from './ssrModuleLoader' export interface ServerOptions { host?: string @@ -167,7 +168,10 @@ export interface ViteDevServer { * Programmatically resolve, load and transform a URL and get the result * without going through the http request pipeline. */ - transformRequest(url: string): Promise + transformRequest( + url: string, + options?: TransformOptions + ): Promise /** * Util for transforming a file with esbuild. * Can be useful for certain plugins. @@ -178,6 +182,10 @@ export interface ViteDevServer { options?: EsbuildTransformOptions, inMap?: object ): Promise + /** + * Load a given URL as an instantiated module for SSR. + */ + ssrLoadModule(url: string): Promise> /** * Start the server. */ @@ -198,9 +206,10 @@ export async function createServer( const config = await resolveConfig(inlineConfig, 'serve', 'development') const root = config.root const serverConfig = config.server || {} + const middlewareMode = !!serverConfig.middlewareMode const app = connect() as Connect.Server - const httpServer = serverConfig.middlewareMode + const httpServer = middlewareMode ? null : await resolveHttpServer(serverConfig, app) const ws = createWebSocketServer(httpServer, config) @@ -232,8 +241,11 @@ export async function createServer( moduleGraph, optimizeDepsMetadata: null, transformWithEsbuild, - transformRequest(url) { - return transformRequest(url, server) + transformRequest(url, options) { + return transformRequest(url, server, options) + }, + ssrLoadModule(url) { + return ssrLoadModule(url, server) }, listen(port?: number) { return startServer(server, port) @@ -344,7 +356,7 @@ export async function createServer( app.use(indexHtmlMiddleware(server, plugins)) // handle 404s - if (!serverConfig.middlewareMode) { + if (!middlewareMode) { app.use((_, res) => { res.statusCode = 404 res.end() @@ -352,7 +364,7 @@ export async function createServer( } // error handler - app.use(errorMiddleware(server, serverConfig.middlewareMode)) + app.use(errorMiddleware(server, middlewareMode)) if (httpServer) { // overwrite listen to run optimizer before server start diff --git a/packages/vite/src/node/server/moduleGraph.ts b/packages/vite/src/node/server/moduleGraph.ts index ab8f12ac76dddd..94a85f0dd8cdb6 100644 --- a/packages/vite/src/node/server/moduleGraph.ts +++ b/packages/vite/src/node/server/moduleGraph.ts @@ -36,11 +36,15 @@ export class ModuleNode { } } +function invalidateSSRModule(mod: ModuleNode) { + mod.ssrModule = null + mod.importers.forEach(invalidateSSRModule) +} export class ModuleGraph { - private urlToModuleMap = new Map() - private idToModuleMap = new Map() + urlToModuleMap = new Map() + idToModuleMap = new Map() // a single file may corresponds to multiple modules with different queries - private fileToModulesMap = new Map>() + fileToModulesMap = new Map>() container: PluginContainer constructor(container: PluginContainer) { @@ -66,7 +70,7 @@ export class ModuleGraph { mods.forEach((mod) => { mod.transformResult = null mod.ssrTransformResult = null - mod.ssrModule = null + invalidateSSRModule(mod) }) } } diff --git a/packages/vite/src/node/server/ssrModuleLoader.ts b/packages/vite/src/node/server/ssrModuleLoader.ts index e69de29bb2d1d6..6a301344941634 100644 --- a/packages/vite/src/node/server/ssrModuleLoader.ts +++ b/packages/vite/src/node/server/ssrModuleLoader.ts @@ -0,0 +1,34 @@ +import { ViteDevServer } from '..' +import { transformRequest } from './transformRequest' + +export async function ssrLoadModule( + url: string, + server: ViteDevServer +): Promise> { + const { moduleGraph } = server + const mod = await moduleGraph.ensureEntryFromUrl(url) + if (mod.ssrModule) { + return mod.ssrModule + } + + const result = await transformRequest(url, server, { ssr: true }) + if (!result) { + // TODO more info? is this even necessary? + throw new Error(`failed to load module for ssr: $${url}`) + } + + await Promise.all(result.deps!.map((dep) => ssrLoadModule(dep, server))) + + const __import__ = (dep: string) => { + return moduleGraph.urlToModuleMap.get(dep)?.ssrModule + } + const __exports__ = {} + + new Function(`__import__`, `__exports__`, result.code)( + __import__, + __exports__ + ) + + mod.ssrModule = __exports__ + return __exports__ +} diff --git a/packages/vite/src/node/server/ssrTransform.ts b/packages/vite/src/node/server/ssrTransform.ts index 84a7a63b81ca89..87f5580ed97020 100644 --- a/packages/vite/src/node/server/ssrTransform.ts +++ b/packages/vite/src/node/server/ssrTransform.ts @@ -2,11 +2,16 @@ import MagicString from 'magic-string' import { SourceMap } from 'rollup' import { TransformResult } from './transformRequest' import { parser } from './pluginContainer' -import { Node } from 'estree' +import { Node as _Node } from 'estree' -export async function transformForSSR( +type Node = _Node & { + start: number + end: number +} + +export async function ssrTransform( code: string, - map: SourceMap | null + inMap: SourceMap | null ): Promise { const s = new MagicString(code) @@ -16,15 +21,41 @@ export async function transformForSSR( locations: true }) as any + let uid = 0 + const deps = new Set() + for (const node of ast.body as Node[]) { // import foo from 'foo' --> foo -> __import_foo__.default // import { baz } from 'foo' --> baz -> __import_foo__.baz // import * as ok from 'foo' --> ok -> __import_foo__ if (node.type === 'ImportDeclaration') { - if (node.specifiers.length) { + const importId = `__vite_import_${uid++}__` + deps.add(node.source.value as string) + s.appendLeft( + node.start, + `const ${importId} = __import__(${JSON.stringify(node.source.value)})\n` + ) + for (const spec of node.specifiers) { + if (spec.type === 'ImportSpecifier') { + s.appendLeft( + node.start, + `const ${spec.local.name} = ${importId}.${spec.imported.name}\n` + ) + } } + s.remove(node.start, node.end) } if (node.type === 'ExportNamedDeclaration') { + if (node.declaration) { + if (node.declaration.type === 'FunctionDeclaration') { + s.overwrite( + node.start, + node.start + 7, + `__exports__.${node.declaration.id!.name} = ` + ) + } + // TODO Class / Var + } } if (node.type === 'ExportDefaultDeclaration') { } @@ -33,7 +64,9 @@ export async function transformForSSR( } return { - code, - map + code: s.toString(), + // TODO handle inMap + map: s.generateMap({ hires: true }), + deps: [...deps] } } diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index 0a6fe1fc97c777..c7366701df35b3 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -13,7 +13,7 @@ import { timeFrom } from '../utils' import { checkPublicFile } from '../plugins/asset' -import { transformForSSR } from './ssrTransform' +import { ssrTransform } from './ssrTransform' const debugLoad = createDebugger('vite:load') const debugTransform = createDebugger('vite:transform') @@ -24,6 +24,7 @@ export interface TransformResult { code: string map: SourceMap | null etag?: string + deps?: string[] } export interface TransformOptions { @@ -139,10 +140,7 @@ export async function transformRequest( } if (ssr) { - return (mod.ssrTransformResult = await transformForSSR( - code, - map as SourceMap - )) + return (mod.ssrTransformResult = await ssrTransform(code, map as SourceMap)) } else { return (mod.transformResult = { code, From 7a15ada7ee2a58205af110e2d24e980883438470 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 15 Jan 2021 12:35:09 -0500 Subject: [PATCH 105/514] wip: basic SSR support --- packages/vite/src/node/build.ts | 49 ++++++++++++++++++- packages/vite/src/node/config.ts | 5 ++ packages/vite/src/node/optimizer/index.ts | 18 +------ packages/vite/src/node/plugin.ts | 16 +++--- .../vite/src/node/plugins/importAnalysis.ts | 14 ++++-- packages/vite/src/node/plugins/resolve.ts | 4 -- packages/vite/src/node/server/index.ts | 30 +++++++----- .../vite/src/node/server/pluginContainer.ts | 10 ++-- .../vite/src/node/server/ssrModuleLoader.ts | 36 +++++++++++--- packages/vite/src/node/server/ssrTransform.ts | 11 +++++ 10 files changed, 135 insertions(+), 58 deletions(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 2f0b1c285a8ebf..39c7354ca52445 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -9,7 +9,8 @@ import Rollup, { RollupWarning, WarningHandler, OutputOptions, - RollupOutput + RollupOutput, + ExternalOption } from 'rollup' import { buildReporterPlugin } from './plugins/reporter' import { buildDefinePlugin } from './plugins/define' @@ -282,6 +283,18 @@ async function doBuild( const outDir = resolve(options.outDir) const publicDir = resolve('public') + // inject ssr arg to plugin load/transform hooks + const plugins = (options.ssr + ? config.plugins.map((p) => injectSsrFlagToHooks(p)) + : config.plugins) as Plugin[] + + // inject ssrExternal if present + const userExternal = options.rollupOptions?.external + const external = + options.ssr && config.ssrExternal + ? resolveExternal(config.ssrExternal, userExternal) + : userExternal + const rollup = require('rollup') as typeof Rollup try { @@ -289,7 +302,8 @@ async function doBuild( input, preserveEntrySignatures: libOptions ? 'strict' : false, ...options.rollupOptions, - plugins: config.plugins as Plugin[], + plugins, + external, onwarn(warning, warn) { onRollupWarning(warning, warn, config) } @@ -459,3 +473,34 @@ export function onRollupWarning( } } } + +export function resolveExternal( + existing: string[], + user: ExternalOption | undefined +): ExternalOption { + if (!user) return existing + if (typeof user !== 'function') { + return existing.concat(user as any[]) + } + return ((id, parentId, isResolved) => { + if (existing.includes(id)) return true + return user(id, parentId, isResolved) + }) as ExternalOption +} + +function injectSsrFlagToHooks(p: Plugin): Plugin { + const { resolveId, load, transform } = p + return { + ...p, + resolveId: wrapSsrHook(resolveId), + load: wrapSsrHook(load), + transform: wrapSsrHook(transform) + } +} + +function wrapSsrHook(fn: Function | undefined) { + if (!fn) return + return function (this: any, ...args: any[]) { + return fn.call(this, ...args, true) + } +} diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 6eed677aa9638f..a7d77b8bdd90dd 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -107,6 +107,11 @@ export interface UserConfig { * Default: true */ clearScreen?: boolean + /** + * Externalize deps for SSR. These deps must provide a CommonJS build that + * can be `required()` and has the same module signature as its ESM build. + */ + ssrExternal?: string[] } export interface InlineConfig extends UserConfig { diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index eb7f9fea868ab7..b38a32e1a0ea3a 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -1,12 +1,12 @@ import fs from 'fs' import path from 'path' import chalk from 'chalk' -import Rollup, { ExternalOption } from 'rollup' +import Rollup from 'rollup' import { createHash } from 'crypto' import { ResolvedConfig, sortUserPlugins } from '../config' import { SUPPORTED_EXTS } from '../constants' import { init, parse } from 'es-module-lexer' -import { onRollupWarning } from '../build' +import { onRollupWarning, resolveExternal } from '../build' import { createDebugger, emptyDir, @@ -444,20 +444,6 @@ async function resolveLinkedDeps( }) } -function resolveExternal( - existing: string[], - user: ExternalOption | undefined -): ExternalOption { - if (!user) return existing - if (typeof user !== 'function') { - return existing.concat(user as any[]) - } - return ((id, parentId, isResolved) => { - if (existing.includes(id)) return true - return user(id, parentId, isResolved) - }) as ExternalOption -} - const lockfileFormats = ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml'] let cachedHash: string | undefined diff --git a/packages/vite/src/node/plugin.ts b/packages/vite/src/node/plugin.ts index 1c71efac969e9e..e2c75067052e0f 100644 --- a/packages/vite/src/node/plugin.ts +++ b/packages/vite/src/node/plugin.ts @@ -2,6 +2,7 @@ import { UserConfig } from './config' import { LoadResult, Plugin as RollupPlugin, + PluginContext, TransformPluginContext, TransformResult } from 'rollup' @@ -109,14 +110,17 @@ export interface Plugin extends RollupPlugin { ): Array | void | Promise | void> /** - * SSR-specific load/transform hooks called during SSR module loads. If these - * are not provided, then the normal load/transform hooks will be called if - * present. + * extend hooks with ssr flag */ - ssrLoad?(id: string): Promise | LoadResult - ssrTransform?( + load?( + this: PluginContext, + id: string, + ssr?: boolean + ): Promise | LoadResult + transform?( this: TransformPluginContext, code: string, - id: string + id: string, + ssr?: boolean ): Promise | TransformResult } diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 88e0202f255f65..54bb34464a0f68 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -92,7 +92,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { server = _server }, - async transform(source, importer) { + async transform(source, importer, ssr) { const prettyImporter = prettifyUrl(importer, config.root) if (canSkip(importer)) { @@ -237,10 +237,6 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { const rawUrl = source.slice(start, end) let url = rawUrl - if (isExternalUrl(url) || isDataUrl(url)) { - continue - } - // check import.meta usage if (url === 'import.meta') { const prop = source.slice(end, end + 4) @@ -293,6 +289,14 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { // If resolvable, let's resolve it if (dynamicIndex === -1 || isLiteralDynamicId) { + // skip external / data uri + if (isExternalUrl(url) || isDataUrl(url)) { + continue + } + // skip ssr external + if (ssr && config.ssrExternal?.includes(url)) { + continue + } // skip client if (url === CLIENT_PUBLIC_PATH) { continue diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index ae5bf89e268135..b649066eded9d2 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -71,10 +71,6 @@ export function resolvePlugin( server = _server }, - configResolved(_config) { - config = _config - }, - resolveId(id, importer) { if (id === browserExternalId) { return id diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 4f6c1203bf17c3..17689893ebdba1 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -366,24 +366,26 @@ export async function createServer( // error handler app.use(errorMiddleware(server, middlewareMode)) + const runOptimize = async () => { + if (config.optimizeCacheDir) { + // run optimizer + await optimizeDeps(config) + // after optimization, read updated optimization metadata + const dataPath = path.resolve(config.optimizeCacheDir, 'metadata.json') + if (fs.existsSync(dataPath)) { + server.optimizeDepsMetadata = JSON.parse( + fs.readFileSync(dataPath, 'utf-8') + ) + } + } + } + if (httpServer) { // overwrite listen to run optimizer before server start const listen = httpServer.listen.bind(httpServer) httpServer.listen = (async (port: number, ...args: any[]) => { await container.buildStart({}) - - if (config.optimizeCacheDir) { - // run optimizer - await optimizeDeps(config) - // after optimization, read updated optimization metadata - const dataPath = path.resolve(config.optimizeCacheDir, 'metadata.json') - if (fs.existsSync(dataPath)) { - server.optimizeDepsMetadata = JSON.parse( - fs.readFileSync(dataPath, 'utf-8') - ) - } - } - + await runOptimize() return listen(port, ...args) }) as any @@ -391,6 +393,8 @@ export async function createServer( // update actual port since this may be different from initial value serverConfig.port = (httpServer.address() as AddressInfo).port }) + } else { + await runOptimize() } return server diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index 2cb110f2a7a349..f4a5a2193274e1 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -482,10 +482,9 @@ export async function createPluginContainer( async load(id, ssr = false) { const ctx = new Context() for (const plugin of plugins) { - const load = (ssr && plugin.ssrLoad) || plugin.load - if (!load) continue + if (!plugin.load) continue ctx._activePlugin = plugin - const result = await load.call(ctx as any, id) + const result = await plugin.load.call(ctx as any, id, ssr) if (result != null) { return result } @@ -496,15 +495,14 @@ export async function createPluginContainer( async transform(code, id, inMap, ssr = false) { const ctx = new TransformContext(id, code, inMap as SourceMap) for (const plugin of plugins) { - const transform = (ssr && plugin.ssrTransform) || plugin.transform - if (!transform) continue + if (!plugin.transform) continue ctx._activePlugin = plugin ctx._activeId = id ctx._activeCode = code const start = Date.now() let result try { - result = await transform.call(ctx as any, code, id) + result = await plugin.transform.call(ctx as any, code, id, ssr) } catch (e) { ctx.error(e) } diff --git a/packages/vite/src/node/server/ssrModuleLoader.ts b/packages/vite/src/node/server/ssrModuleLoader.ts index 6a301344941634..7566473dffb337 100644 --- a/packages/vite/src/node/server/ssrModuleLoader.ts +++ b/packages/vite/src/node/server/ssrModuleLoader.ts @@ -1,4 +1,6 @@ +import path from 'path' import { ViteDevServer } from '..' +import { resolveFrom } from '../utils' import { transformRequest } from './transformRequest' export async function ssrLoadModule( @@ -17,17 +19,39 @@ export async function ssrLoadModule( throw new Error(`failed to load module for ssr: $${url}`) } - await Promise.all(result.deps!.map((dep) => ssrLoadModule(dep, server))) + const external = server.config.ssrExternal + + await Promise.all( + result.deps!.map((dep) => { + if (!external?.includes(dep)) { + return ssrLoadModule(dep, server) + } + }) + ) const __import__ = (dep: string) => { - return moduleGraph.urlToModuleMap.get(dep)?.ssrModule + if (external?.includes(dep)) { + if (mod.file) { + return require(resolveFrom(dep, path.dirname(mod.file))) + } else { + return require(dep) + } + } else { + return moduleGraph.urlToModuleMap.get(dep)?.ssrModule + } } const __exports__ = {} - new Function(`__import__`, `__exports__`, result.code)( - __import__, - __exports__ - ) + try { + new Function(`__import__`, `__exports__`, result.code)( + __import__, + __exports__ + ) + } catch (e) { + // console.log(e.message) + // console.log(result.code) + // TODO + } mod.ssrModule = __exports__ return __exports__ diff --git a/packages/vite/src/node/server/ssrTransform.ts b/packages/vite/src/node/server/ssrTransform.ts index 87f5580ed97020..f5743945b088bc 100644 --- a/packages/vite/src/node/server/ssrTransform.ts +++ b/packages/vite/src/node/server/ssrTransform.ts @@ -41,6 +41,11 @@ export async function ssrTransform( node.start, `const ${spec.local.name} = ${importId}.${spec.imported.name}\n` ) + } else if (spec.type === 'ImportDefaultSpecifier') { + s.appendLeft( + node.start, + `const ${spec.local.name} = ${importId}.default\n` + ) } } s.remove(node.start, node.end) @@ -55,9 +60,15 @@ export async function ssrTransform( ) } // TODO Class / Var + } else { + for (const spec of node.specifiers) { + s.append(`\n__exports__.${spec.exported.name} = ${spec.local.name}`) + } + s.remove(node.start, node.end) } } if (node.type === 'ExportDefaultDeclaration') { + s.overwrite(node.start, node.start + 14, '__exports__.default =') } if (node.type === 'ExportAllDeclaration') { } From a93ab23491ee9fee78345ddc20567e1b0ceec2a7 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 15 Jan 2021 12:35:31 -0500 Subject: [PATCH 106/514] feat(plugin-vue): support for vite core new ssr impl --- packages/plugin-vue/src/handleHotUpdate.ts | 6 ++++- packages/plugin-vue/src/index.ts | 23 +++++++++---------- packages/plugin-vue/src/main.ts | 26 +++++++++++++--------- packages/plugin-vue/src/script.ts | 15 +++++++------ packages/plugin-vue/src/template.ts | 24 +++++++++++--------- 5 files changed, 54 insertions(+), 40 deletions(-) diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index be131824da3bcd..734c6d4a8d604d 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -55,7 +55,11 @@ export async function handleHotUpdate({ // metadata will not be available since the script part isn't loaded. // in this case, reuse the compiled script from previous descriptor. if (mainModule && !affectedModules.has(mainModule)) { - setResolvedScript(descriptor, getResolvedScript(prevDescriptor)!) + setResolvedScript( + descriptor, + getResolvedScript(prevDescriptor, false)!, + false + ) } affectedModules.add(templateModule) needRerender = true diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index d7155d525d86e9..240d49a064537a 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -37,7 +37,6 @@ export interface Options { include?: string | RegExp | (string | RegExp)[] exclude?: string | RegExp | (string | RegExp)[] - ssr?: boolean isProduction?: boolean // options to pass on to @vue/compiler-sfc @@ -53,7 +52,6 @@ export interface ResolvedOptions extends Options { export default function vuePlugin(rawOptions: Options = {}): Plugin { let options: ResolvedOptions = { - ssr: false, isProduction: process.env.NODE_ENV === 'production', ...rawOptions, root: process.cwd() @@ -75,11 +73,12 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { }, config(config) { - // provide default values for vue runtime esm defines - config.define = { - __VUE_OPTIONS_API__: true, - __VUE_PROD_DEVTOOLS__: false, - ...config.define + return { + define: { + __VUE_OPTIONS_API__: true, + __VUE_PROD_DEVTOOLS__: false + }, + ssrExternal: ['vue', '@vue/server-renderer'] } }, @@ -102,7 +101,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { } }, - load(id) { + load(id, ssr = false) { const { filename, query } = parseVueRequest(id) // select corresponding block for subpart virtual modules if (query.vue) { @@ -113,7 +112,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { let block: SFCBlock | null | undefined if (query.type === 'script') { // handle + diff --git a/packages/playground/ssr/package.json b/packages/playground/ssr/package.json new file mode 100644 index 00000000000000..a21f7c382cf2a7 --- /dev/null +++ b/packages/playground/ssr/package.json @@ -0,0 +1,28 @@ +{ + "name": "test-ssr", + "private": true, + "version": "0.0.0", + "scripts": { + "dev": "node server", + "build": "yarn build:client && yarn build:server", + "build:client": "vite build --ssrManifest --outDir dist/client", + "build:server": "vite build --ssr src/entry-server.ts --outDir dist/server", + "serve": "NODE_ENV=production node server", + "debug": "node --inspect-brk server" + }, + "dependencies": { + "react": "^17.0.1", + "react-dom": "^17.0.1", + "vue": "^3.0.5" + }, + "devDependencies": { + "@types/react": "^17.0.0", + "@types/react-dom": "^17.0.0", + "@vitejs/plugin-vue": "^1.0.0", + "@vue/compiler-sfc": "^3.0.5", + "compression": "^1.7.4", + "cross-env": "^7.0.3", + "express": "^4.17.1", + "serve-static": "^1.14.1" + } +} diff --git a/packages/playground/ssr/server.js b/packages/playground/ssr/server.js new file mode 100644 index 00000000000000..a46ca7b5eb96ac --- /dev/null +++ b/packages/playground/ssr/server.js @@ -0,0 +1,71 @@ +// @ts-check +const fs = require('fs') +const express = require('express') +const { createServer } = require('vite') + +const isProd = process.env.NODE_ENV === 'production' + +const indexTemplateProd = isProd + ? fs.readFileSync('dist/client/index.html', 'utf-8') + : '' + +const manifest = isProd + ? // @ts-ignore + require('./dist/client/ssr-manifest.json') + : {} + +function getIndexTemplate() { + return isProd + ? indexTemplateProd + : `` + + fs.readFileSync('index.html', 'utf-8') +} + +async function startServer() { + const app = express() + + /** + * @type {import('vite').ViteDevServer} + */ + let vite + if (!isProd) { + vite = await createServer({ + server: { + middlewareMode: true + } + }) + // use vite's connect instance as middleware + app.use(vite.middlewares) + } else { + app.use(require('compression')()) + app.use(require('serve-static')('dist/client', { index: false })) + } + + app.use('*', async (req, res, next) => { + try { + const { render } = isProd + ? // @ts-ignore + require('./dist/server/entry-server.js') + : await vite.ssrLoadModule('/src/entry-server.ts') + + const [appHtml, preloadLinks] = await render(req.originalUrl, manifest) + + const html = ` + ${preloadLinks} + ${getIndexTemplate().replace(``, appHtml)} + ` + + res.status(200).set({ 'Content-Type': 'text/html' }).end(html) + } catch (e) { + !isProd && vite.ssrFixStacktrace(e) + console.log(e.stack) + next(e) + } + }) + + app.listen(3000, () => { + console.log('http://localhost:3000') + }) +} + +startServer() diff --git a/packages/playground/ssr/src/entry-client.ts b/packages/playground/ssr/src/entry-client.ts new file mode 100644 index 00000000000000..6ef2ef6d4effc2 --- /dev/null +++ b/packages/playground/ssr/src/entry-client.ts @@ -0,0 +1,11 @@ +import { createVueApp, createReactApp } from './main' + +if (location.pathname.startsWith('/vue')) { + createVueApp().then((app) => app.mount('#app')) +} else if (location.pathname.startsWith('/react')) { + Promise.all([import('react-dom'), createReactApp()]).then( + ([ReactDOM, app]) => { + ReactDOM.hydrate(app, document.getElementById('app')) + } + ) +} diff --git a/packages/playground/ssr/src/entry-server.ts b/packages/playground/ssr/src/entry-server.ts new file mode 100644 index 00000000000000..d06ce49bb06ca3 --- /dev/null +++ b/packages/playground/ssr/src/entry-server.ts @@ -0,0 +1,61 @@ +import { createVueApp, createReactApp } from './main' +import { renderToString } from '@vue/server-renderer' +import ReacDOMServer from 'react-dom/server' + +interface Manifest { + [key: string]: string[] +} + +export async function render( + url: string, + manifest: Manifest +): Promise<[string, string]> { + if (url.startsWith('/vue')) { + return renderVue(manifest) + } else if (url.startsWith('/react')) { + return renderReact() + } else { + return [`Vue React`, ``] + } +} + +async function renderReact(): Promise<[string, string]> { + const app = await createReactApp() + return [ReacDOMServer.renderToString(app), ``] +} + +async function renderVue(manifest: Manifest): Promise<[string, string]> { + const ctx: any = {} + const app = await createVueApp() + const html = await renderToString(app, ctx) + const preloadLinks = renderPreloadLinks(ctx.modules, manifest) + return [html, preloadLinks] +} + +function renderPreloadLinks(modules: Set, manifest: Manifest): string { + let links = '' + const seen = new Set() + modules.forEach((id) => { + const files = manifest[id] + if (files) { + files.forEach((file) => { + if (!seen.has(file)) { + seen.add(file) + links += renderPreloadLink(file) + } + }) + } + }) + return links +} + +function renderPreloadLink(file: string): string { + if (file.endsWith('.js')) { + return `` + } else if (file.endsWith('.css')) { + return `` + } else { + // TODO + return '' + } +} diff --git a/packages/playground/ssr/src/main.ts b/packages/playground/ssr/src/main.ts new file mode 100644 index 00000000000000..bf291c11832914 --- /dev/null +++ b/packages/playground/ssr/src/main.ts @@ -0,0 +1,7 @@ +export function createVueApp() { + return import('./vue/index').then(({ createVueApp }) => createVueApp()) +} + +export function createReactApp() { + return import('./react/index').then(({ createReactApp }) => createReactApp()) +} diff --git a/packages/playground/ssr/src/react/App.jsx b/packages/playground/ssr/src/react/App.jsx new file mode 100644 index 00000000000000..3481369d327f9f --- /dev/null +++ b/packages/playground/ssr/src/react/App.jsx @@ -0,0 +1,6 @@ +import React from 'react' +import Child from './Child' + +export default function App() { + return +} diff --git a/packages/playground/ssr/src/react/Child.jsx b/packages/playground/ssr/src/react/Child.jsx new file mode 100644 index 00000000000000..9360b64ba44269 --- /dev/null +++ b/packages/playground/ssr/src/react/Child.jsx @@ -0,0 +1,5 @@ +import React from 'react' + +export default function Child() { + return

Hello from React

+} diff --git a/packages/playground/ssr/src/react/index.ts b/packages/playground/ssr/src/react/index.ts new file mode 100644 index 00000000000000..1146613af99cb4 --- /dev/null +++ b/packages/playground/ssr/src/react/index.ts @@ -0,0 +1,6 @@ +import React from 'react' +import ReactApp from './App' + +export function createReactApp() { + return React.createElement(ReactApp) +} diff --git a/packages/playground/ssr/src/vue/App.vue b/packages/playground/ssr/src/vue/App.vue new file mode 100644 index 00000000000000..1355a2987a0bf5 --- /dev/null +++ b/packages/playground/ssr/src/vue/App.vue @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/packages/playground/ssr/src/vue/Async.vue b/packages/playground/ssr/src/vue/Async.vue new file mode 100644 index 00000000000000..db20a6532008fd --- /dev/null +++ b/packages/playground/ssr/src/vue/Async.vue @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/packages/playground/ssr/src/vue/index.ts b/packages/playground/ssr/src/vue/index.ts new file mode 100644 index 00000000000000..c0840adcce8b90 --- /dev/null +++ b/packages/playground/ssr/src/vue/index.ts @@ -0,0 +1,6 @@ +import VueApp from './App.vue' +import { createSSRApp } from 'vue' + +export function createVueApp() { + return createSSRApp(VueApp) +} diff --git a/packages/playground/ssr/vite.config.js b/packages/playground/ssr/vite.config.js new file mode 100644 index 00000000000000..2d78161809f73a --- /dev/null +++ b/packages/playground/ssr/vite.config.js @@ -0,0 +1,5 @@ +import vuePlugin from '@vitejs/plugin-vue' + +export default { + plugins: [vuePlugin()] +} diff --git a/packages/playground/vue/package.json b/packages/playground/vue/package.json index 2f8bedf648c9da..b9afe797d66a5a 100644 --- a/packages/playground/vue/package.json +++ b/packages/playground/vue/package.json @@ -8,11 +8,11 @@ "debug": "node --inspect-brk ../../vite/bin/vite" }, "dependencies": { - "vue": "^3.0.4" + "vue": "^3.0.5" }, "devDependencies": { "@vitejs/plugin-vue": "^1.0.0", - "@vue/compiler-sfc": "^3.0.4", + "@vue/compiler-sfc": "^3.0.5", "js-yaml": "^3.14.1", "less": "^3.13.0", "pug": "^3.0.0", diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 39d521fa4483c7..ef07c228a7427b 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -296,7 +296,11 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { } // skip ssr external if (ssr) { - if (server._ssrExternals?.includes(url)) { + if ( + server._ssrExternals?.some((id) => { + return url === id || url.startsWith(id + '/') + }) + ) { continue } if (isBuiltin(url)) { diff --git a/packages/vite/src/node/plugins/reporter.ts b/packages/vite/src/node/plugins/reporter.ts index f9e72130c08ad4..bd0b2800c81338 100644 --- a/packages/vite/src/node/plugins/reporter.ts +++ b/packages/vite/src/node/plugins/reporter.ts @@ -29,7 +29,10 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin { maxLength: number ) { const needCompression = - type === WriteType.JS || type === WriteType.CSS || type === WriteType.HTML + !config.build.ssr && + (type === WriteType.JS || + type === WriteType.CSS || + type === WriteType.HTML) const compressed = needCompression ? ` / brotli: ${( diff --git a/yarn.lock b/yarn.lock index 5ffb290caf737b..3269e1ad530361 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1035,6 +1035,26 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.1.5.tgz#b6ab3bba29e16b821d84e09ecfaded462b816b00" integrity sha512-UEyp8LwZ4Dg30kVU2Q3amHHyTn1jEdhCIE59ANed76GaT1Vp76DD3ZWSAxgCrw6wJ0TqeoBpqmfUHiUDPs//HQ== +"@types/prop-types@*": + version "15.7.3" + resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7" + integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw== + +"@types/react-dom@^17.0.0": + version "17.0.0" + resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.0.tgz#b3b691eb956c4b3401777ee67b900cb28415d95a" + integrity sha512-lUqY7OlkF/RbNtD5nIq7ot8NquXrdFrjSOR6+w9a9RFQevGi1oZO1dcJbXMeONAPKtZ2UrZOEJ5UOCVsxbLk/g== + dependencies: + "@types/react" "*" + +"@types/react@*", "@types/react@^17.0.0": + version "17.0.0" + resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.0.tgz#5af3eb7fad2807092f0046a1302b7823e27919b8" + integrity sha512-aj/L7RIMsRlWML3YB6KZiXB3fV2t41+5RBGYF8z+tAKU43Px8C3cYUZsDvf1/+Bm4FK21QWBrDutu8ZJ/70qOw== + dependencies: + "@types/prop-types" "*" + csstype "^3.0.2" + "@types/resolve@1.17.1", "@types/resolve@^1.17.1": version "1.17.1" resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6" @@ -1241,13 +1261,6 @@ "@vue/compiler-dom" "3.0.5" "@vue/shared" "3.0.5" -"@vue/reactivity@3.0.4": - version "3.0.4" - resolved "https://registry.yarnpkg.com/@vue/reactivity/-/reactivity-3.0.4.tgz#b6599dd8271a745960a03f05744ccf7991ba5d8d" - integrity sha512-AFTABrLhUYZY2on3ea9FxeXal7w3f6qIp9gT+/oG93H7dFTL5LvVnxygCopv7tvkIl/GSGQb/yK1D1gmXx1Pww== - dependencies: - "@vue/shared" "3.0.4" - "@vue/reactivity@3.0.5": version "3.0.5" resolved "https://registry.yarnpkg.com/@vue/reactivity/-/reactivity-3.0.5.tgz#e3789e4d523d845f9ae0b4d770e2b45594742fd2" @@ -1255,14 +1268,6 @@ dependencies: "@vue/shared" "3.0.5" -"@vue/runtime-core@3.0.4": - version "3.0.4" - resolved "https://registry.yarnpkg.com/@vue/runtime-core/-/runtime-core-3.0.4.tgz#a5b9a001560b1fd8c01a43f68b764c555de7836c" - integrity sha512-qH9e4kqU7b3u1JewvLmGmoAGY+mnuBqz7aEKb2mhpEgwa1yFv496BRuUfMXXMCix3+TndUVMJ8jt41FSdNppwg== - dependencies: - "@vue/reactivity" "3.0.4" - "@vue/shared" "3.0.4" - "@vue/runtime-core@3.0.5": version "3.0.5" resolved "https://registry.yarnpkg.com/@vue/runtime-core/-/runtime-core-3.0.5.tgz#da6331d5f300d5794e9e0ebdc8a8bd72a9e19962" @@ -1271,15 +1276,6 @@ "@vue/reactivity" "3.0.5" "@vue/shared" "3.0.5" -"@vue/runtime-dom@3.0.4": - version "3.0.4" - resolved "https://registry.yarnpkg.com/@vue/runtime-dom/-/runtime-dom-3.0.4.tgz#6f81aec545f24511d2c28a315aa3391420b69c68" - integrity sha512-BGIoiTSESzWUhN0Ofi2X/q+HN8f6IUFmUEyyBGKbmx7DTAJNZhFfjqsepfXQrM5IGeTfJLB1ZEVyroDQJNXq3g== - dependencies: - "@vue/runtime-core" "3.0.4" - "@vue/shared" "3.0.4" - csstype "^2.6.8" - "@vue/runtime-dom@3.0.5": version "3.0.5" resolved "https://registry.yarnpkg.com/@vue/runtime-dom/-/runtime-dom-3.0.5.tgz#1ce2c9c449e26ab06963da0064096e882a7a8935" @@ -1320,7 +1316,7 @@ abab@^2.0.3: resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.5.tgz#c0b678fb32d60fc1219c784d6a826fe385aeb79a" integrity sha512-9IK9EadsbHo6jLWIpxpR6pL0sazTXV6+SQv25ZB+F7Bj9mJNaOc4nCRabwd5M/JwmUa8idz6Eci6eKfJryPs6Q== -accepts@~1.3.5: +accepts@~1.3.5, accepts@~1.3.7: version "1.3.7" resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd" integrity sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA== @@ -1514,6 +1510,11 @@ array-find-index@^1.0.1, array-find-index@^1.0.2: resolved "https://registry.yarnpkg.com/array-find-index/-/array-find-index-1.0.2.tgz#df010aa1287e164bbda6f9723b0a96a1ec4187a1" integrity sha1-3wEKoSh+Fku9pvlyOwqWoexBh6E= +array-flatten@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2" + integrity sha1-ml9pkFGx5wczKPKgCJaLZOopVdI= + array-ify@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/array-ify/-/array-ify-1.0.0.tgz#9e528762b4a9066ad163a6962a364418e9626ece" @@ -1720,6 +1721,22 @@ bluebird@^3.7.2: resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== +body-parser@1.19.0: + version "1.19.0" + resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.19.0.tgz#96b2709e57c9c4e09a6fd66a8fd979844f69f08a" + integrity sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw== + dependencies: + bytes "3.1.0" + content-type "~1.0.4" + debug "2.6.9" + depd "~1.1.2" + http-errors "1.7.2" + iconv-lite "0.4.24" + on-finished "~2.3.0" + qs "6.7.0" + raw-body "2.4.0" + type-is "~1.6.17" + brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -1810,6 +1827,11 @@ bytes@3.0.0: resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048" integrity sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg= +bytes@3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6" + integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg== + cac@^6.6.1: version "6.7.1" resolved "https://registry.yarnpkg.com/cac/-/cac-6.7.1.tgz#0609d28a31d887746de4b66a15e3914f106f880c" @@ -2190,6 +2212,18 @@ constantinople@^4.0.1: "@babel/parser" "^7.6.0" "@babel/types" "^7.6.1" +content-disposition@0.5.3: + version "0.5.3" + resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.3.tgz#e130caf7e7279087c5616c2007d0485698984fbd" + integrity sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g== + dependencies: + safe-buffer "5.1.2" + +content-type@~1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b" + integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA== + conventional-changelog-angular@^5.0.12: version "5.0.12" resolved "https://registry.yarnpkg.com/conventional-changelog-angular/-/conventional-changelog-angular-5.0.12.tgz#c979b8b921cbfe26402eb3da5bbfda02d865a2b9" @@ -2355,6 +2389,16 @@ convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0: dependencies: safe-buffer "~5.1.1" +cookie-signature@1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" + integrity sha1-4wOogrNCzD7oylE6eZmXNNqzriw= + +cookie@0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.0.tgz#beb437e7022b3b6d49019d088665303ebe9c14ba" + integrity sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg== + copy-anything@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/copy-anything/-/copy-anything-2.0.1.tgz#2afbce6da684bdfcbec93752fa762819cb480d9a" @@ -2464,6 +2508,11 @@ csstype@^2.6.8: resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.14.tgz#004822a4050345b55ad4dcc00be1d9cf2f4296de" integrity sha512-2mSc+VEpGPblzAxyeR+vZhJKgYg0Og0nnRi7pmRXFYYxSfnOnW8A5wwQb4n4cE2nIOzqKOAzLCaEX6aBmNEv8A== +csstype@^3.0.2: + version "3.0.6" + resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.6.tgz#865d0b5833d7d8d40f4e5b8a6d76aea3de4725ef" + integrity sha512-+ZAmfyWMT7TiIlzdqJgjMb7S4f1beorDbWbsocyK4RaiqA5RTX3K14bnBWmmA9QEM0gRdsjyyrEmcyga8Zsxmw== + currently-unhandled@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea" @@ -2597,6 +2646,16 @@ delegate@^3.1.2: resolved "https://registry.yarnpkg.com/delegate/-/delegate-3.2.0.tgz#b66b71c3158522e8ab5744f720d8ca0c2af59166" integrity sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw== +depd@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" + integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak= + +destroy@~1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" + integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA= + detect-newline@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651" @@ -2931,7 +2990,7 @@ esutils@^2.0.2: resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== -etag@^1.8.1: +etag@^1.8.1, etag@~1.8.1: version "1.8.1" resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887" integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc= @@ -3032,6 +3091,42 @@ expect@^26.6.2: jest-message-util "^26.6.2" jest-regex-util "^26.0.0" +express@^4.17.1: + version "4.17.1" + resolved "https://registry.yarnpkg.com/express/-/express-4.17.1.tgz#4491fc38605cf51f8629d39c2b5d026f98a4c134" + integrity sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g== + dependencies: + accepts "~1.3.7" + array-flatten "1.1.1" + body-parser "1.19.0" + content-disposition "0.5.3" + content-type "~1.0.4" + cookie "0.4.0" + cookie-signature "1.0.6" + debug "2.6.9" + depd "~1.1.2" + encodeurl "~1.0.2" + escape-html "~1.0.3" + etag "~1.8.1" + finalhandler "~1.1.2" + fresh "0.5.2" + merge-descriptors "1.0.1" + methods "~1.1.2" + on-finished "~2.3.0" + parseurl "~1.3.3" + path-to-regexp "0.1.7" + proxy-addr "~2.0.5" + qs "6.7.0" + range-parser "~1.2.1" + safe-buffer "5.1.2" + send "0.17.1" + serve-static "1.14.1" + setprototypeof "1.1.1" + statuses "~1.5.0" + type-is "~1.6.18" + utils-merge "1.0.1" + vary "~1.1.2" + extend-shallow@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f" @@ -3166,7 +3261,7 @@ fill-range@^7.0.1: dependencies: to-regex-range "^5.0.1" -finalhandler@1.1.2: +finalhandler@1.1.2, finalhandler@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.1.2.tgz#b7e7d000ffd11938d0fdb053506f6ebabe9f587d" integrity sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA== @@ -3239,6 +3334,11 @@ form-data@~2.3.2: combined-stream "^1.0.6" mime-types "^2.1.12" +forwarded@~0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84" + integrity sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ= + fragment-cache@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/fragment-cache/-/fragment-cache-0.2.1.tgz#4290fad27f13e89be7f33799c6bc5a0abfff0d19" @@ -3246,6 +3346,11 @@ fragment-cache@^0.2.1: dependencies: map-cache "^0.2.2" +fresh@0.5.2: + version "0.5.2" + resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7" + integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac= + fs-extra@^9.0.0, fs-extra@^9.0.1: version "9.0.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc" @@ -3606,6 +3711,28 @@ html-tags@^3.1.0: resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.1.0.tgz#7b5e6f7e665e9fb41f30007ed9e0d41e97fb2140" integrity sha512-1qYz89hW3lFDEazhjW0yVAV87lw8lVkrJocr72XmBkMKsoSVJCQx3W8BXsC7hO2qAt8BoVjYjtAcZ9perqGnNg== +http-errors@1.7.2: + version "1.7.2" + resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.7.2.tgz#4f5029cf13239f31036e5b2e55292bcfbcc85c8f" + integrity sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg== + dependencies: + depd "~1.1.2" + inherits "2.0.3" + setprototypeof "1.1.1" + statuses ">= 1.5.0 < 2" + toidentifier "1.0.0" + +http-errors@~1.7.2: + version "1.7.3" + resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.7.3.tgz#6c619e4f9c60308c38519498c14fbb10aacebb06" + integrity sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw== + dependencies: + depd "~1.1.2" + inherits "2.0.4" + setprototypeof "1.1.1" + statuses ">= 1.5.0 < 2" + toidentifier "1.0.0" + http-proxy@^1.18.1: version "1.18.1" resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549" @@ -3756,11 +3883,16 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.3: +inherits@2, inherits@2.0.4, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.3: version "2.0.4" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== +inherits@2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4= + ini@^1.3.2: version "1.3.8" resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" @@ -3776,6 +3908,11 @@ ip-regex@^2.1.0: resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9" integrity sha1-+ni/XS5pE8kRzp+BnuUUa7bYROk= +ipaddr.js@1.9.1: + version "1.9.1" + resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz#bff38543eeb8984825079ff3a2a8e6cbd46781b3" + integrity sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g== + is-accessor-descriptor@^0.1.6: version "0.1.6" resolved "https://registry.yarnpkg.com/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz#a9e12cb3ae8d876727eeef3843f8a0897b5c98d6" @@ -5053,6 +5190,11 @@ mdurl@^1.0.1: resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e" integrity sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4= +media-typer@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" + integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g= + memorystream@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/memorystream/-/memorystream-0.3.1.tgz#86d7090b30ce455d63fbae12dda51a47ddcaf9b2" @@ -5106,6 +5248,11 @@ meow@^8.0.0: type-fest "^0.18.0" yargs-parser "^20.2.3" +merge-descriptors@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" + integrity sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E= + merge-source-map@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/merge-source-map/-/merge-source-map-1.1.0.tgz#2fdde7e6020939f70906a68f2d7ae685e4c8c646" @@ -5123,6 +5270,11 @@ merge2@^1.3.0: resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae" integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== +methods@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" + integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4= + micromatch@^3.1.4: version "3.1.10" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23" @@ -5167,7 +5319,7 @@ mime-types@^2.1.12, mime-types@~2.1.19, mime-types@~2.1.24: dependencies: mime-db "1.44.0" -mime@^1.4.1: +mime@1.6.0, mime@^1.4.1: version "1.6.0" resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== @@ -5244,6 +5396,11 @@ ms@2.0.0: resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= +ms@2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a" + integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg== + ms@2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" @@ -5696,6 +5853,11 @@ path-parse@^1.0.6: resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== +path-to-regexp@0.1.7: + version "0.1.7" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" + integrity sha1-32BBeABfUi8V60SQ5yR6G/qmf4w= + path-type@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441" @@ -6046,6 +6208,14 @@ proper-lockfile@^4.1.1: retry "^0.12.0" signal-exit "^3.0.2" +proxy-addr@~2.0.5: + version "2.0.6" + resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.6.tgz#fdc2336505447d3f2f2c638ed272caf614bbb2bf" + integrity sha512-dh/frvCBVmSsDYzw6n926jv974gddhkFPfiN8hPOi30Wax25QZyZEGveluCgliBnqmuM+UJmBErbAUFIoDbjOw== + dependencies: + forwarded "~0.1.2" + ipaddr.js "1.9.1" + proxy-from-env@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" @@ -6187,6 +6357,11 @@ q@^1.5.1: resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7" integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc= +qs@6.7.0: + version "6.7.0" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc" + integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ== + qs@~6.5.2: version "6.5.2" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" @@ -6202,6 +6377,21 @@ quick-lru@^4.0.1: resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-4.0.1.tgz#5b8878f113a58217848c6482026c73e1ba57727f" integrity sha512-ARhCpm70fzdcvNQfPoy49IaanKkTlRWF2JMzqhcJbhSFRZv7nPTvZJdcY7301IPmvW+/p0RgIWnQDLJxifsQ7g== +range-parser@~1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031" + integrity sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg== + +raw-body@2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.4.0.tgz#a1ce6fb9c9bc356ca52e89256ab59059e13d0332" + integrity sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q== + dependencies: + bytes "3.1.0" + http-errors "1.7.2" + iconv-lite "0.4.24" + unpipe "1.0.0" + react-dom@^17.0.1: version "17.0.1" resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.1.tgz#1de2560474ec9f0e334285662ede52dbc5426fc6" @@ -6688,6 +6878,35 @@ semver@^6.0.0, semver@^6.1.0, semver@^6.3.0: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== +send@0.17.1: + version "0.17.1" + resolved "https://registry.yarnpkg.com/send/-/send-0.17.1.tgz#c1d8b059f7900f7466dd4938bdc44e11ddb376c8" + integrity sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg== + dependencies: + debug "2.6.9" + depd "~1.1.2" + destroy "~1.0.4" + encodeurl "~1.0.2" + escape-html "~1.0.3" + etag "~1.8.1" + fresh "0.5.2" + http-errors "~1.7.2" + mime "1.6.0" + ms "2.1.1" + on-finished "~2.3.0" + range-parser "~1.2.1" + statuses "~1.5.0" + +serve-static@1.14.1, serve-static@^1.14.1: + version "1.14.1" + resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.14.1.tgz#666e636dc4f010f7ef29970a88a674320898b2f9" + integrity sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg== + dependencies: + encodeurl "~1.0.2" + escape-html "~1.0.3" + parseurl "~1.3.3" + send "0.17.1" + set-blocking@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" @@ -6703,6 +6922,11 @@ set-value@^2.0.0, set-value@^2.0.1: is-plain-object "^2.0.3" split-string "^3.0.1" +setprototypeof@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.1.tgz#7e95acb24aa92f5885e0abef5ba131330d4ae683" + integrity sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw== + shebang-command@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" @@ -6974,7 +7198,7 @@ static-extend@^0.1.1: define-property "^0.2.5" object-copy "^0.1.0" -statuses@~1.5.0: +"statuses@>= 1.5.0 < 2", statuses@~1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" integrity sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow= @@ -7314,6 +7538,11 @@ to-regex@^3.0.1, to-regex@^3.0.2: regex-not "^1.0.2" safe-regex "^1.1.0" +toidentifier@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553" + integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw== + token-stream@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/token-stream/-/token-stream-1.0.0.tgz#cc200eab2613f4166d27ff9afc7ca56d49df6eb4" @@ -7460,6 +7689,14 @@ type-fest@^0.8.1: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== +type-is@~1.6.17, type-is@~1.6.18: + version "1.6.18" + resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131" + integrity sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g== + dependencies: + media-typer "0.3.0" + mime-types "~2.1.24" + typedarray-to-buffer@^3.1.5: version "3.1.5" resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080" @@ -7521,7 +7758,7 @@ universalify@^2.0.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== -unpipe@~1.0.0: +unpipe@1.0.0, unpipe@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" integrity sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw= @@ -7650,15 +7887,6 @@ void-elements@^3.1.0: resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-3.1.0.tgz#614f7fbf8d801f0bb5f0661f5b2f5785750e4f09" integrity sha1-YU9/v42AHwu18GYfWy9XhXUOTwk= -vue@^3.0.4: - version "3.0.4" - resolved "https://registry.yarnpkg.com/vue/-/vue-3.0.4.tgz#872c65c143f5717bd5387c61613d9f55f4cc0f43" - integrity sha512-2o+AiQF8sAupyhbyl3oxVCl3WCwC/n5NI7VMM+gVQ231qvSB8eI7sCBloloqDJK6yA367EEtmRSeSCf4sxCC+A== - dependencies: - "@vue/compiler-dom" "3.0.4" - "@vue/runtime-dom" "3.0.4" - "@vue/shared" "3.0.4" - vue@^3.0.5: version "3.0.5" resolved "https://registry.yarnpkg.com/vue/-/vue-3.0.5.tgz#de1b82eba24abfe71e0970fc9b8d4b2babdc3fe1" From d1383ed126b37b922a532ff6cb59b32c0a97e1a2 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 18 Jan 2021 18:34:58 -0500 Subject: [PATCH 136/514] fix(plugin-react-refresh): skip during ssr --- packages/playground/ssr/vite.config.js | 3 ++- packages/plugin-react-refresh/index.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/playground/ssr/vite.config.js b/packages/playground/ssr/vite.config.js index 2d78161809f73a..a35166e1720c7d 100644 --- a/packages/playground/ssr/vite.config.js +++ b/packages/playground/ssr/vite.config.js @@ -1,5 +1,6 @@ import vuePlugin from '@vitejs/plugin-vue' +import reactRefresh from '@vitejs/plugin-react-refresh' export default { - plugins: [vuePlugin()] + plugins: [vuePlugin(), reactRefresh()] } diff --git a/packages/plugin-react-refresh/index.js b/packages/plugin-react-refresh/index.js index f8b5c5c67adfcc..3cf6ec9ba800e9 100644 --- a/packages/plugin-react-refresh/index.js +++ b/packages/plugin-react-refresh/index.js @@ -48,8 +48,8 @@ module.exports = function reactRefreshPlugin() { } }, - transform(code, id) { - if (shouldSkip) { + transform(code, id, ssr) { + if (shouldSkip || ssr) { return } From 774ef88e73c7a5cfbc739cd5436bd703500c460d Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 18 Jan 2021 18:50:11 -0500 Subject: [PATCH 137/514] wip: react refresh + ssr --- packages/playground/ssr/server.js | 27 +++++++++++++++++------ packages/playground/ssr/src/vue/Async.vue | 8 ++++++- packages/playground/ssr/vite.config.js | 9 +++++++- packages/plugin-react-refresh/index.d.ts | 4 +++- packages/plugin-react-refresh/index.js | 18 +++++++++------ 5 files changed, 49 insertions(+), 17 deletions(-) diff --git a/packages/playground/ssr/server.js b/packages/playground/ssr/server.js index a46ca7b5eb96ac..ce8a79e2052e02 100644 --- a/packages/playground/ssr/server.js +++ b/packages/playground/ssr/server.js @@ -5,7 +5,7 @@ const { createServer } = require('vite') const isProd = process.env.NODE_ENV === 'production' -const indexTemplateProd = isProd +const indexProd = isProd ? fs.readFileSync('dist/client/index.html', 'utf-8') : '' @@ -14,11 +14,24 @@ const manifest = isProd require('./dist/client/ssr-manifest.json') : {} -function getIndexTemplate() { - return isProd - ? indexTemplateProd - : `` + - fs.readFileSync('index.html', 'utf-8') +function getIndexTemplate(url) { + if (isProd) { + return indexProd + } + + // TODO handle plugin indexHtmlTransforms? + const reactPreamble = url.startsWith('/react') + ? `` + : '' + + // during dev, inject vite client + always read fresh index.html + return ( + `` + + reactPreamble + + fs.readFileSync('index.html', 'utf-8') + ) } async function startServer() { @@ -52,7 +65,7 @@ async function startServer() { const html = ` ${preloadLinks} - ${getIndexTemplate().replace(``, appHtml)} + ${getIndexTemplate(req.originalUrl).replace(``, appHtml)} ` res.status(200).set({ 'Content-Type': 'text/html' }).end(html) diff --git a/packages/playground/ssr/src/vue/Async.vue b/packages/playground/ssr/src/vue/Async.vue index db20a6532008fd..1f77609a1e641e 100644 --- a/packages/playground/ssr/src/vue/Async.vue +++ b/packages/playground/ssr/src/vue/Async.vue @@ -6,4 +6,10 @@ const msg = 'Hello from Vue' console.log('async evaluated') - \ No newline at end of file + + + \ No newline at end of file diff --git a/packages/playground/ssr/vite.config.js b/packages/playground/ssr/vite.config.js index a35166e1720c7d..a4474d696d854c 100644 --- a/packages/playground/ssr/vite.config.js +++ b/packages/playground/ssr/vite.config.js @@ -1,6 +1,13 @@ +// @ts-check import vuePlugin from '@vitejs/plugin-vue' import reactRefresh from '@vitejs/plugin-react-refresh' +/** + * @type {import('vite').UserConfig} + */ export default { - plugins: [vuePlugin(), reactRefresh()] + plugins: [vuePlugin(), reactRefresh()], + build: { + minify: false + } } diff --git a/packages/plugin-react-refresh/index.d.ts b/packages/plugin-react-refresh/index.d.ts index 77dc36bb496444..4a7be38b3d0801 100644 --- a/packages/plugin-react-refresh/index.d.ts +++ b/packages/plugin-react-refresh/index.d.ts @@ -1,5 +1,7 @@ import { Plugin } from 'vite' -declare function createPlugin(): Plugin +type PluginFactory = () => Plugin + +declare const createPlugin: PluginFactory & { preambleCode: string } export = createPlugin diff --git a/packages/plugin-react-refresh/index.js b/packages/plugin-react-refresh/index.js index 3cf6ec9ba800e9..9982ded1df1645 100644 --- a/packages/plugin-react-refresh/index.js +++ b/packages/plugin-react-refresh/index.js @@ -21,6 +21,14 @@ exports.performReactRefresh = debounce(exports.performReactRefresh, 16) export default exports ` +const preambleCode = ` +import RefreshRuntime from "${runtimePublicPath}" +RefreshRuntime.injectIntoGlobalHook(window) +window.$RefreshReg$ = () => {} +window.$RefreshSig$ = () => (type) => type +window.__vite_plugin_react_preamble_installed__ = true +` + /** * Transform plugin for transforming and injecting per-file refresh code. * @@ -134,19 +142,15 @@ module.exports = function reactRefreshPlugin() { { tag: 'script', attrs: { type: 'module' }, - children: ` - import RefreshRuntime from "${runtimePublicPath}" - RefreshRuntime.injectIntoGlobalHook(window) - window.$RefreshReg$ = () => {} - window.$RefreshSig$ = () => (type) => type - window.__vite_plugin_react_preamble_installed__ = true - ` + children: preambleCode } ] } } } +module.exports.preambleCode = preambleCode + /** * @param {import('@babel/core').BabelFileResult['ast']} ast */ From 92cccc4b84d207b438461f8644504a306f69daa5 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 18 Jan 2021 19:15:51 -0500 Subject: [PATCH 138/514] chore: lazy require vite in prod [skip ci] --- packages/playground/ssr/server.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/playground/ssr/server.js b/packages/playground/ssr/server.js index ce8a79e2052e02..2da40818db5d65 100644 --- a/packages/playground/ssr/server.js +++ b/packages/playground/ssr/server.js @@ -1,7 +1,6 @@ // @ts-check const fs = require('fs') const express = require('express') -const { createServer } = require('vite') const isProd = process.env.NODE_ENV === 'production' @@ -42,7 +41,7 @@ async function startServer() { */ let vite if (!isProd) { - vite = await createServer({ + vite = await require('vite').createServer({ server: { middlewareMode: true } From bf4b3e9b416bb0f2a8ee8bfce969d452429a8282 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 19 Jan 2021 10:09:11 -0500 Subject: [PATCH 139/514] fix: ssr transform check valid inMap --- packages/vite/src/node/ssr/ssrTransform.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/ssr/ssrTransform.ts b/packages/vite/src/node/ssr/ssrTransform.ts index faad311b00ef38..6ee39987dbe905 100644 --- a/packages/vite/src/node/ssr/ssrTransform.ts +++ b/packages/vite/src/node/ssr/ssrTransform.ts @@ -159,7 +159,7 @@ export async function ssrTransform( }) let map = s.generateMap({ hires: true }) - if (inMap) { + if (inMap && inMap.mappings) { map = merge(inMap, { ...map, sources: inMap.sources, From a1d1dde70c4626ab603ed07234fe296ef8d5a65f Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 19 Jan 2021 10:12:12 -0500 Subject: [PATCH 140/514] fix: support resolving .json ext to be consistent with Node --- packages/vite/src/node/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/constants.ts b/packages/vite/src/node/constants.ts index 66bec81230a9a1..6a51c407613a97 100644 --- a/packages/vite/src/node/constants.ts +++ b/packages/vite/src/node/constants.ts @@ -1,6 +1,6 @@ import path from 'path' -export const SUPPORTED_EXTS = ['.mjs', '.js', '.ts', '.jsx', '.tsx'] +export const SUPPORTED_EXTS = ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'] export const DEP_CACHE_DIR = `.vite` From 4d8eca979b8efe3f500d0212e7a240a6705d7ffb Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 19 Jan 2021 10:13:38 -0500 Subject: [PATCH 141/514] chore: mark ssr related options/methods alpha --- packages/vite/src/node/config.ts | 1 + packages/vite/src/node/server/index.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 92a8f8b3fc9d27..709b935e527a8a 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -95,6 +95,7 @@ export interface UserConfig { optimizeDeps?: DepOptimizationOptions /** * SSR specific options + * @alpha */ ssr?: SSROptions /** diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index edaf75cb3b50c0..17f8021f6fb6fd 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -193,6 +193,7 @@ export interface ViteDevServer { ): Promise /** * Load a given URL as an instantiated module for SSR. + * @alpha */ ssrLoadModule( url: string, @@ -200,6 +201,7 @@ export interface ViteDevServer { ): Promise> /** * Fix ssr error stacktrace + * @alpha */ ssrFixStacktrace(e: Error): void /** From 34bfe966e74e5da5d75efa837f020042bb88a0c0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 19 Jan 2021 10:21:40 -0500 Subject: [PATCH 142/514] chore(plugin-vue): backwards compat for ssr option --- packages/plugin-vue/src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index 626f0c6df7d426..58da7cc4226ca5 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -43,6 +43,10 @@ export interface Options { script?: Partial template?: Partial style?: Partial + /** + * @deprecated the plugin now auto-detects whether it's being invoked for ssr. + */ + ssr?: boolean } export interface ResolvedOptions extends Options { @@ -103,7 +107,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { } }, - load(id, ssr = false) { + load(id, ssr = !!options.ssr) { const { filename, query } = parseVueRequest(id) // select corresponding block for subpart virtual modules if (query.vue) { @@ -131,7 +135,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { } }, - transform(code, id, ssr = false) { + transform(code, id, ssr = !!options.ssr) { const { filename, query } = parseVueRequest(id) if (!query.vue && !filter(filename)) { return From 65337be5a7838c422a45329971fb967bd9fe97be Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 19 Jan 2021 10:22:20 -0500 Subject: [PATCH 143/514] release: plugin-vue@1.1.0 --- packages/plugin-vue/CHANGELOG.md | 10 ++++++++++ packages/plugin-vue/package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/plugin-vue/CHANGELOG.md b/packages/plugin-vue/CHANGELOG.md index deaa35c4b1db99..a4da0f64a18d88 100644 --- a/packages/plugin-vue/CHANGELOG.md +++ b/packages/plugin-vue/CHANGELOG.md @@ -1,3 +1,13 @@ +# [1.1.0](https://github.com/vitejs/vite/compare/plugin-vue@1.0.6...plugin-vue@1.1.0) (2021-01-19) + + +### Features + +* ssr manifest for preload inference ([107e79e](https://github.com/vitejs/vite/commit/107e79e7b7d422f0d1dbe8b7b435636df7c6281c)) +* **plugin-vue:** support for vite core new ssr impl ([a93ab23](https://github.com/vitejs/vite/commit/a93ab23491ee9fee78345ddc20567e1b0ceec2a7)) + + + ## [1.0.6](https://github.com/vitejs/vite/compare/plugin-vue@1.0.5...plugin-vue@1.0.6) (2021-01-15) diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index b7463a1f20bf7d..f77a415005e589 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-vue", - "version": "1.0.6", + "version": "1.1.0", "license": "MIT", "author": "Evan You", "files": [ From 9fc2a30fe14f363a8ea2e024643138338a4c57db Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 19 Jan 2021 10:23:28 -0500 Subject: [PATCH 144/514] release: plugin-react-refresh@1.1.2 --- packages/plugin-react-refresh/CHANGELOG.md | 9 +++++++++ packages/plugin-react-refresh/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/plugin-react-refresh/CHANGELOG.md b/packages/plugin-react-refresh/CHANGELOG.md index e704efc36bb0de..53903bdd76b8ef 100644 --- a/packages/plugin-react-refresh/CHANGELOG.md +++ b/packages/plugin-react-refresh/CHANGELOG.md @@ -1,3 +1,12 @@ +## [1.1.2](https://github.com/vitejs/vite/compare/plugin-react-refresh@1.1.1...plugin-react-refresh@1.1.2) (2021-01-19) + + +### Bug Fixes + +* **plugin-react-refresh:** skip during ssr ([d1383ed](https://github.com/vitejs/vite/commit/d1383ed126b37b922a532ff6cb59b32c0a97e1a2)) + + + ## [1.1.1](https://github.com/vitejs/vite/compare/plugin-react-refresh@1.1.0...plugin-react-refresh@1.1.1) (2021-01-06) diff --git a/packages/plugin-react-refresh/package.json b/packages/plugin-react-refresh/package.json index 61a7bc46bd62f2..712e644d9e8899 100644 --- a/packages/plugin-react-refresh/package.json +++ b/packages/plugin-react-refresh/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-react-refresh", - "version": "1.1.1", + "version": "1.1.2", "license": "MIT", "author": "Evan You", "files": [ From 56fb4cad04d3cad2bbf18f112b7a68abfc5f34a5 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 19 Jan 2021 10:24:12 -0500 Subject: [PATCH 145/514] release: v2.0.0-beta.32 --- packages/vite/CHANGELOG.md | 32 ++++++++++++++++++++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 54ab8200db8d29..e8686c2b30bf5d 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,35 @@ +# [2.0.0-beta.32](https://github.com/vitejs/vite/compare/v2.0.0-beta.31...v2.0.0-beta.32) (2021-01-19) + + +### Bug Fixes + +* avoid preloading owner chunk ([61969d7](https://github.com/vitejs/vite/commit/61969d787200ab0b03179ecf2855c5b4aff3baa6)) +* ssr transform check valid inMap ([bf4b3e9](https://github.com/vitejs/vite/commit/bf4b3e9b416bb0f2a8ee8bfce969d452429a8282)) +* support resolving .json ext to be consistent with Node ([a1d1dde](https://github.com/vitejs/vite/commit/a1d1dde70c4626ab603ed07234fe296ef8d5a65f)) + + +### Code Refactoring + +* rename ViteDevServer.app -> ViteDevServer.middlewares ([394390a](https://github.com/vitejs/vite/commit/394390a983deccd8cbca101066db93f60577b810)) + + +### Features + +* import.meta.env.SSR ([fe7396d](https://github.com/vitejs/vite/commit/fe7396d3896d04db17f73ea265eebe0397414e65)) +* ssr manifest for preload inference ([107e79e](https://github.com/vitejs/vite/commit/107e79e7b7d422f0d1dbe8b7b435636df7c6281c)) +* **ssr:** isolated mode ([e954ed2](https://github.com/vitejs/vite/commit/e954ed25099d9217d30a5a4d38e5dfee5acee0fd)) +* ssr sourcemap + stacktrace fix ([6cb04fa](https://github.com/vitejs/vite/commit/6cb04fa3b3a7a4ac4676a7b1c41d9d5068fae5de)) + + +### BREAKING CHANGES + +* `ViteDevServer.app` is now `ViteDevServer.middlewares`. +In addition, Vite no longer serves `index.html` in middleware mode. The +server using Vite as middleware is responsible for serving HTML with +`/@vite/client` injected. + + + # [2.0.0-beta.31](https://github.com/vitejs/vite/compare/v2.0.0-beta.30...v2.0.0-beta.31) (2021-01-18) diff --git a/packages/vite/package.json b/packages/vite/package.json index a538113117cdd7..82eacf11ab9fd3 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.31", + "version": "2.0.0-beta.32", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From de52f2890e2dce23911e77d41209f08b0fd870b9 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 19 Jan 2021 10:28:17 -0500 Subject: [PATCH 146/514] chore: remove stale changelog [skip ci] --- CHANGELOG.md | 1646 -------------------------------------------------- 1 file changed, 1646 deletions(-) delete mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index ff84a7e48a0b56..00000000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,1646 +0,0 @@ -# [1.0.0-rc.13](https://github.com/vitejs/vite/compare/v1.0.0-rc.12...v1.0.0-rc.13) (2020-11-25) - - - -# [1.0.0-rc.11](https://github.com/vitejs/vite/compare/v1.0.0-rc.10...v1.0.0-rc.11) (2020-11-25) - - -### Bug Fixes - -* move https-proxy types to dependencies ([2753658](https://github.com/vitejs/vite/commit/275365862a1a94976686d5d5f8f1775f8a724b6d)) - - - -# [1.0.0-rc.10](https://github.com/vitejs/vite/compare/v1.0.0-rc.9...v1.0.0-rc.10) (2020-11-25) - - -### Bug Fixes - -* multiple builds share esbuild process ([#1125](https://github.com/vitejs/vite/issues/1125)) ([f270440](https://github.com/vitejs/vite/commit/f27044054e7a7a28239a7fcdb601913f0aacd5ac)), closes [#1098](https://github.com/vitejs/vite/issues/1098) -* **build:** always pass `namespaceToStringTag`, let output module has… ([#1057](https://github.com/vitejs/vite/issues/1057)) ([8cd3e85](https://github.com/vitejs/vite/commit/8cd3e85871bd25992c6c8113a61b3df3a6a98f52)), closes [#1048](https://github.com/vitejs/vite/issues/1048) -* **cli:** specify correct arguments to options ([6b98b73](https://github.com/vitejs/vite/commit/6b98b7392af7761def2011aff83116efb5ab8a82)) -* **config:** avoid overwriting defined .env values ([f0e50bd](https://github.com/vitejs/vite/commit/f0e50bd7ff708f56669a9b46aaff913b3526f58c)) -* **config:** move `dotenvExpand` back into `resolveConfig` ([dd03c62](https://github.com/vitejs/vite/commit/dd03c6255f0ac62b72daa523ed8ba6a4f09a4be2)) -* **dev:** chokidar `ignored` ([ce332d1](https://github.com/vitejs/vite/commit/ce332d1415ce50760ed993c7a65042888c25c5cd)), closes [#1132](https://github.com/vitejs/vite/issues/1132) -* **dev:** respect `[@vite-ignore](https://github.com/vite-ignore)` inside module rewrite ([#1011](https://github.com/vitejs/vite/issues/1011)) ([6fbae67](https://github.com/vitejs/vite/commit/6fbae678683d3be358b7270497fd9cbd03c39e9a)), closes [#1007](https://github.com/vitejs/vite/issues/1007) -* **dev:** respect sourceRoot when rewriting source map ([#1073](https://github.com/vitejs/vite/issues/1073)) ([b4afcf1](https://github.com/vitejs/vite/commit/b4afcf1507cf313beb9ecca245be9e6ceb2b126c)) -* **dev:** transform import for commonjs dependencies ([#837](https://github.com/vitejs/vite/issues/837)) ([51aead4](https://github.com/vitejs/vite/commit/51aead44ffb22c7d0c29a489f67b7eb7b9bba4f1)) -* **docs:** README es-dev-server broken link ([#1081](https://github.com/vitejs/vite/issues/1081)) ([0d2768d](https://github.com/vitejs/vite/commit/0d2768d9e53be8c685fb69416ab9dd7df63207cc)) -* `env` key in `UserConfig` should not be required ([#1097](https://github.com/vitejs/vite/issues/1097)) ([f33e89d](https://github.com/vitejs/vite/commit/f33e89db2c944933b52524eff0263cc9546aa0dd)) -* always set NODE_ENV for build ([effc159](https://github.com/vitejs/vite/commit/effc159822c08178825fcdfa99f9c8e672ba653c)) -* cac argv keys are in camel case ([#1092](https://github.com/vitejs/vite/issues/1092)) ([8520e76](https://github.com/vitejs/vite/commit/8520e76cdc15654f0c197cf63539428875aff2c7)) -* indexHtmlPath can be an absolute path ([#1032](https://github.com/vitejs/vite/issues/1032)) ([bc1a8ee](https://github.com/vitejs/vite/commit/bc1a8eeef725de57d0e74d7eb43803f3ea929ac8)) -* target ES2018 instead of ESNEXT ([#1110](https://github.com/vitejs/vite/issues/1110)) ([ce633f4](https://github.com/vitejs/vite/commit/ce633f48602f0e1c6c0d922d03477bdc4143aef0)) -* **types:** buildPluginHtml does not need `config.env` to exist ([#1091](https://github.com/vitejs/vite/issues/1091)) ([29f20e5](https://github.com/vitejs/vite/commit/29f20e50d10c8d1f8be59d249f6cb3538c24a5b5)) -* indentation for injected html tags ([#1068](https://github.com/vitejs/vite/issues/1068)) ([ac5ee6f](https://github.com/vitejs/vite/commit/ac5ee6f5e7024aa69c6e07149885f0b6e00a4f38)) -* only pass valid rollup options to avoid warning ([#1034](https://github.com/vitejs/vite/issues/1034)) ([128d5ff](https://github.com/vitejs/vite/commit/128d5ff7bbb113bcf05bf595201e7dfdec1a147a)) -* **types:** ws should be optional ([#1010](https://github.com/vitejs/vite/issues/1010)) ([5b16cf9](https://github.com/vitejs/vite/commit/5b16cf9f5c627327e53e89c49defe853d358b383)) - - -### Features - -* support new versions of experimental features in `@vue/compiler-sfc` ([#1121](https://github.com/vitejs/vite/issues/1121)) ([a928d74](https://github.com/vitejs/vite/commit/a928d74ae4be9e054bfdab35f2a85a774e81ecb0)) -* **build:** make `rollupOutputOptions` and `rollupPluginVueOptions` overridable ([#1117](https://github.com/vitejs/vite/issues/1117)) ([39bdd45](https://github.com/vitejs/vite/commit/39bdd45290a6fdab31aa8b02caa7d8465d12633c)) -* expose `loadEnv` in public api ([f3e4017](https://github.com/vitejs/vite/commit/f3e4017b96b2839d349e34b249966a3f6be11315)) -* use cac for argv parsing and cli help ([#971](https://github.com/vitejs/vite/issues/971)) ([88bb4ff](https://github.com/vitejs/vite/commit/88bb4ff7d7b70d5668c889188cd95a61d2dc3c1e)) -* **types:** include http-proxy options in ProxiesOptions type ([#1037](https://github.com/vitejs/vite/issues/1037)) ([261c8c8](https://github.com/vitejs/vite/commit/261c8c82f689a7a004670bca06097263e6983a1d)) - - -### Performance Improvements - -* remove empty chunk from css extraction ([963614b](https://github.com/vitejs/vite/commit/963614bff7039207c0b2d9e8c2c5780b74ee176a)) - - - -# [1.0.0-rc.9](https://github.com/vitejs/vite/compare/v1.0.0-rc.8...v1.0.0-rc.9) (2020-11-02) - - -### Bug Fixes - -* **dev:** remove comment for dynamic import inside server rewrite ([#1001](https://github.com/vitejs/vite/issues/1001)) ([4ccff7a](https://github.com/vitejs/vite/commit/4ccff7a109c4c339d3a688bc5d091defe274e927)), closes [#998](https://github.com/vitejs/vite/issues/998) -* **hmr:** infer hmr hostname on client ([#980](https://github.com/vitejs/vite/issues/980)) ([858b2bf](https://github.com/vitejs/vite/commit/858b2bfe530495afcc0540c710e7edafd0e06d03)) -* always emit assets virtually + ensure correct asset paths in ssrBuild ([b8e80ba](https://github.com/vitejs/vite/commit/b8e80ba7142dbddd7dd7f37ca74037bc9dd193f2)) -* **build:** add `write` condition ([e5fdc7e](https://github.com/vitejs/vite/commit/e5fdc7e35e3b009a1ef45c97ae9744f8669105ad)) -* **build:** always render the index.html ([5e7c309](https://github.com/vitejs/vite/commit/5e7c309baa16b78fbfdfbf3fffff7af775c26047)) -* **build:** remove `outDir` before build ([d1599f9](https://github.com/vitejs/vite/commit/d1599f94fb6c0fc7fdeb67ae54ad18407ce16a10)) -* **build:** resolve rollup warning when using pluginsPreBuild ([40e1d87](https://github.com/vitejs/vite/commit/40e1d8721631031fd1c05a6a793e36dd85506e4f)) -* **dev:** always proxy http request even `ws` option is truly ([32be77b](https://github.com/vitejs/vite/commit/32be77bce0257967c4234b822fecd6dbd8571931)), closes [#978](https://github.com/vitejs/vite/issues/978) - - -### Features - -* allow suppressing dynamic import warning with [@vite-ignore](https://github.com/vite-ignore) ([7ac483c](https://github.com/vitejs/vite/commit/7ac483ceacdbedb99cbcffbfc4d70ae7451dc018)) -* **build:** add "vite:emit" output plugin ([#977](https://github.com/vitejs/vite/issues/977)) ([9c2d435](https://github.com/vitejs/vite/commit/9c2d43530406c73d350efba804af8a8ea7718ae7)) -* **types:** add `ImportMetaEnv` global type ([03acecd](https://github.com/vitejs/vite/commit/03acecd797d8393e38c8a78f920c8e0927762018)) - - - -# [1.0.0-rc.8](https://github.com/vitejs/vite/compare/v1.0.0-rc.7...v1.0.0-rc.8) (2020-10-26) - - - -# [1.0.0-rc.7](https://github.com/vitejs/vite/compare/v1.0.0-rc.6...v1.0.0-rc.7) (2020-10-26) - - -### Bug Fixes - -* **build:** add `Symbol.toStringTag` when ssr build es module into cjs chunk ([#951](https://github.com/vitejs/vite/issues/951)) ([344a86a](https://github.com/vitejs/vite/commit/344a86a7f02727eaf34bef2eacef48099ffc686a)), closes [#764](https://github.com/vitejs/vite/issues/764) -* **dev:** resolve sub-package inside node module, let `module` filed inside `package.json` can be take first. ([76fcfa7](https://github.com/vitejs/vite/commit/76fcfa71e9fe8ee69f0bbb35cdfeeede6fe3bfe0)), closes [#829](https://github.com/vitejs/vite/issues/829) -* **hmr:** register component on import ([95e3342](https://github.com/vitejs/vite/commit/95e334296b2883b1deae5983042b089efe946f98)), closes [#959](https://github.com/vitejs/vite/issues/959) -* **hmr:** sniff hmr protocol on client when not specifically configured ([e1c7500](https://github.com/vitejs/vite/commit/e1c75003644868afaaaedd939eae5972f7ef40de)), closes [#956](https://github.com/vitejs/vite/issues/956) -* **html:** avoid mutating outer scope in `renderIndex` function ([f2da029](https://github.com/vitejs/vite/commit/f2da0293e7738bb6e579c934c3c1c35fcddc5b5d)) -* always resolve `outDir` relative to `root` ([f5dee86](https://github.com/vitejs/vite/commit/f5dee8611194cb81dcdd44787c83777c92fddefc)) -* update rollup-pluginutils import ([#954](https://github.com/vitejs/vite/issues/954)) ([dcf1eaa](https://github.com/vitejs/vite/commit/dcf1eaa74ad53d63af5605f1be1224c019c7533d)) - - -### Features - -* add `configureBuild` hook ([1c2a9b9](https://github.com/vitejs/vite/commit/1c2a9b981c70ead236b4d91460ed23e3f619f41c)) -* let `configureBuild` hooks inject Rollup bundles ([03ef2ed](https://github.com/vitejs/vite/commit/03ef2ed00e4e1f519ce5aabf36700b2ac404f99d)) -* let build plugins return post-build hook ([ec47ab8](https://github.com/vitejs/vite/commit/ec47ab82f8127bbc174200267a93d1c8918c0ba2)) -* transforms for index.html ([#793](https://github.com/vitejs/vite/issues/793)) ([ebb964e](https://github.com/vitejs/vite/commit/ebb964e58568b818160ae8b2aa3168197d16720d)) -* **build:** emitManifest ([75d7679](https://github.com/vitejs/vite/commit/75d7679a8348f2df2cda21f805dc6df562fdb996)) -* **build:** support alternative entry for build ([6c66e31](https://github.com/vitejs/vite/commit/6c66e316c33105a894eff33343f0527139b06bd9)) -* **config:** add pluginsPreBuild, etc. for rollup ([#953](https://github.com/vitejs/vite/issues/953)) ([cd3666a](https://github.com/vitejs/vite/commit/cd3666ac6175344d7c0d88450ffdb824794e1e58)) -* **dev:** support configuring CORS ([f416f9f](https://github.com/vitejs/vite/commit/f416f9f32e80e7e6be508391053d155a3a5189d4)) - - -### Reverts - -* Revert "refactor: resolve relative path request inside unoptimized package wh… (#867)" ([ec8f46d](https://github.com/vitejs/vite/commit/ec8f46dd09ac3b2b7e6ffc709227af09addaef59)), closes [#867](https://github.com/vitejs/vite/issues/867) - - - -# [1.0.0-rc.6](https://github.com/vitejs/vite/compare/v1.0.0-rc.5...v1.0.0-rc.6) (2020-10-23) - - -### Bug Fixes - -* apply user rollup plugins last ([#855](https://github.com/vitejs/vite/issues/855)) ([1760658](https://github.com/vitejs/vite/commit/1760658de19e9df6ab67677993fc4defb329354a)) -* ensure source maps can be traced by debugger ([#886](https://github.com/vitejs/vite/issues/886)) ([ba7442f](https://github.com/vitejs/vite/commit/ba7442fffd1f4787bd542f09dae93bc3197e33f9)), closes [#675](https://github.com/vitejs/vite/issues/675) -* **build:** do not merge non-module inline scripts into bundle ([edf0886](https://github.com/vitejs/vite/commit/edf088686794869d3fa92c9cb4a6a15b04187d06)), closes [#719](https://github.com/vitejs/vite/issues/719) -* **build:** relative `sources` in production bundle sourcemap ([#934](https://github.com/vitejs/vite/issues/934)) ([8264fa8](https://github.com/vitejs/vite/commit/8264fa85904ef8f89065d76fc10b488a636306bf)) -* **config:** do not throw when user speicifies type: "module" in package.json ([8acd49e](https://github.com/vitejs/vite/commit/8acd49ee931e315b9b506e816972beb7e4786b59)), closes [#917](https://github.com/vitejs/vite/issues/917) -* **dev:** remove unnecessary warning ([#722](https://github.com/vitejs/vite/issues/722)) ([a2c4b24](https://github.com/vitejs/vite/commit/a2c4b24d4034242e6cf24a84fcc2cad94ae7aff4)), closes [#721](https://github.com/vitejs/vite/issues/721) -* **optimizer:** ignore `@types/*` packages inside optimizer ([#812](https://github.com/vitejs/vite/issues/812)) ([aa81eb3](https://github.com/vitejs/vite/commit/aa81eb34c19f55d6617de25a5aa9ad7adbe2eb8c)), closes [#804](https://github.com/vitejs/vite/issues/804) -* **optimizer:** remove `?commonjs-proxy` injected by `rollup-plugin-commonjs` for assets ([#908](https://github.com/vitejs/vite/issues/908)) ([e3e7059](https://github.com/vitejs/vite/commit/e3e7059e9403138c63198f2269056e0db1139d0e)), closes [#903](https://github.com/vitejs/vite/issues/903) -* **server:** only rewrite module script tags ([c18f387](https://github.com/vitejs/vite/commit/c18f3872a48cbcd493a83ee97c1441a92ac40e77)) -* **server:** read server port only after listening ([#943](https://github.com/vitejs/vite/issues/943)) ([eb039f9](https://github.com/vitejs/vite/commit/eb039f9821d96f7d3ec3ed839ba65a0fdcb8ceeb)) - - -### Features - -* Configurable asset inclusion ([#811](https://github.com/vitejs/vite/issues/811)) ([8378f1a](https://github.com/vitejs/vite/commit/8378f1a736eafa5d3eda856aaac0406ef430a9ae)), closes [#810](https://github.com/vitejs/vite/issues/810) -* inject module scripts into head instead of body ([#882](https://github.com/vitejs/vite/issues/882)) ([28678a9](https://github.com/vitejs/vite/commit/28678a96055839a7b3c6320fd486ae04f58d4dc3)), closes [#881](https://github.com/vitejs/vite/issues/881) -* let user config be a function ([#836](https://github.com/vitejs/vite/issues/836)) ([e06b73e](https://github.com/vitejs/vite/commit/e06b73e98c16decb79801293cb63076dc7bd4eee)) -* **hmr:** handle hmr when editing tailwind config ([#408](https://github.com/vitejs/vite/issues/408)) ([1d33ef3](https://github.com/vitejs/vite/commit/1d33ef38596c46a2e9ac96debb59c665e83614eb)) - - - -# [1.0.0-rc.5](https://github.com/vitejs/vite/compare/v1.0.0-rc.4...v1.0.0-rc.5) (2020-10-23) - - -### Bug Fixes - -* **build:** adjust allowed script tag types ([8b8f357](https://github.com/vitejs/vite/commit/8b8f3571558831c24a7b9b671dc8a1de427df51e)), closes [#724](https://github.com/vitejs/vite/issues/724) -* **build:** correct replace `define` ([e24133e](https://github.com/vitejs/vite/commit/e24133e51cb9d2fc4a338a6efd44a455978e5020)) -* **build:** create at most one `esbuildService` ([#694](https://github.com/vitejs/vite/issues/694)) ([2acae21](https://github.com/vitejs/vite/commit/2acae21b197ccbfc332651247ebe2f9b25fde238)), closes [#693](https://github.com/vitejs/vite/issues/693) -* **build:** css not be tree shake ([#803](https://github.com/vitejs/vite/issues/803)) ([34649b5](https://github.com/vitejs/vite/commit/34649b5fc3b8bef2e51e4fc0dc173a29df4a3b63)), closes [#795](https://github.com/vitejs/vite/issues/795) -* **build:** inject css to dynamic chunk only if it is not empty ([#805](https://github.com/vitejs/vite/issues/805)) ([038a053](https://github.com/vitejs/vite/commit/038a053477029d799b57f0d3242005a951486a61)) -* **build:** normalize `vueTransformAssetUrls` if not pass through plugins ([#668](https://github.com/vitejs/vite/issues/668)) ([47eb448](https://github.com/vitejs/vite/commit/47eb448709fa09f8bd02e1d4159d68e467ed68a7)), closes [#661](https://github.com/vitejs/vite/issues/661) -* **build:** only extract js module script tag in html ([#724](https://github.com/vitejs/vite/issues/724)) ([ef60d55](https://github.com/vitejs/vite/commit/ef60d55b67cf25508fe28a0c6cd2b9745b7f282a)), closes [#670](https://github.com/vitejs/vite/issues/670) -* **build:** resolve external url ([#807](https://github.com/vitejs/vite/issues/807)) ([df2e388](https://github.com/vitejs/vite/commit/df2e3884ee65dfc717b3c24d06da074c3fa9bca3)), closes [#799](https://github.com/vitejs/vite/issues/799) -* **build:** stop spinner on rollup error ([#835](https://github.com/vitejs/vite/issues/835)) ([78489b8](https://github.com/vitejs/vite/commit/78489b87c4b95ff8db86679b2f4a379591c0affa)) -* **config:** typo ([#935](https://github.com/vitejs/vite/issues/935)) ([08213b4](https://github.com/vitejs/vite/commit/08213b44ad79b8fc9b754115e416597326af5696)) -* **dev:** correctly normalize entry path on windows ([#736](https://github.com/vitejs/vite/issues/736)) ([49689e5](https://github.com/vitejs/vite/commit/49689e5d9ccb1e119951951e773d8826ec2221be)), closes [#735](https://github.com/vitejs/vite/issues/735) -* **dev:** decode for `publicPath` ([#924](https://github.com/vitejs/vite/issues/924)) ([0ea245c](https://github.com/vitejs/vite/commit/0ea245c69ec9c7baef7b755e497e15e171695859)), closes [#920](https://github.com/vitejs/vite/issues/920) -* **dev:** don't rewrite files inside public ([#602](https://github.com/vitejs/vite/issues/602)) ([2b544f3](https://github.com/vitejs/vite/commit/2b544f31bf8526b9f5ddee865c6c086f3edce756)) -* **dev:** hand file write end when change event emit in chokidar ([#824](https://github.com/vitejs/vite/issues/824)) ([a8f9595](https://github.com/vitejs/vite/commit/a8f95952650df7507c959478f2fa7048e6b7657b)), closes [#610](https://github.com/vitejs/vite/issues/610) -* **dev:** ignore .git file with hmr ([#664](https://github.com/vitejs/vite/issues/664)) ([c9a2764](https://github.com/vitejs/vite/commit/c9a27643f4ca612c8280c4485a6feadbc973c1ca)), closes [#663](https://github.com/vitejs/vite/issues/663) -* **dev:** strip utf-8 bom ([#814](https://github.com/vitejs/vite/issues/814)) ([ed2afe6](https://github.com/vitejs/vite/commit/ed2afe61c90847fba0191ce8633b41ecde20c73b)) -* **docs:** typo ([#843](https://github.com/vitejs/vite/issues/843)) ([2893a41](https://github.com/vitejs/vite/commit/2893a4149bbf2baf8a895a12ee6548148481a7bf)) -* add `@rollup/plugin-commonjs` before user plugin, let it correct… ([#746](https://github.com/vitejs/vite/issues/746)) ([f005c67](https://github.com/vitejs/vite/commit/f005c67f9865c8ec14a1c752d98962beb9decef5)), closes [#728](https://github.com/vitejs/vite/issues/728) -* avoid overwriting the prorcess global ([#609](https://github.com/vitejs/vite/issues/609)) ([36422c2](https://github.com/vitejs/vite/commit/36422c2d5e0e0e59ef969d0b5287d98bfe7cc3ee)) -* bump `rollup-plugin-terser` + update `esbuild` target to `es2020… ([#723](https://github.com/vitejs/vite/issues/723)) ([5266b74](https://github.com/vitejs/vite/commit/5266b74218a7a080e5b0eeb63383543a932dd5de)), closes [#718](https://github.com/vitejs/vite/issues/718) -* don't mutate plugins array in postcss config ([#791](https://github.com/vitejs/vite/issues/791)) ([3328076](https://github.com/vitejs/vite/commit/3328076261a8bdded73a25c73b509f140cc1ab6e)) -* notModified with transform ([#682](https://github.com/vitejs/vite/issues/682)) ([c6426e9](https://github.com/vitejs/vite/commit/c6426e9f5ae33fdde7ef6093a02960ca0374cecd)), closes [#662](https://github.com/vitejs/vite/issues/662) -* **dev:** omit "?t=" query from esbuild sourcemap source path ([#783](https://github.com/vitejs/vite/issues/783)) ([ec295aa](https://github.com/vitejs/vite/commit/ec295aaf75b48b554cd0aa339b99a8d4b4ec1a47)) -* **dev:** warn unknown dynamic import inside module rewrite ([#776](https://github.com/vitejs/vite/issues/776)) ([304f321](https://github.com/vitejs/vite/commit/304f321c6160ea8c97acb0b6ee1f6022ac873431)), closes [#772](https://github.com/vitejs/vite/issues/772) -* make vite.config support es2020 syntax ([#658](https://github.com/vitejs/vite/issues/658)) ([760cbac](https://github.com/vitejs/vite/commit/760cbacc963e4df37779ff49c8c14f68487dea81)) -* README.md type/grammar ([#625](https://github.com/vitejs/vite/issues/625)) ([2560a45](https://github.com/vitejs/vite/commit/2560a45897e5c608056743352a9dc90cf5ec0877)) -* strip "public/" prefix in `defaultFileToRequest` ([#681](https://github.com/vitejs/vite/issues/681)) ([5d98994](https://github.com/vitejs/vite/commit/5d98994d2c0fb790458a30d4badb7bf83c48691f)) -* use `index.js` as default entry point ([#665](https://github.com/vitejs/vite/issues/665)) ([5969c97](https://github.com/vitejs/vite/commit/5969c97ab5d0da56be72083d88b583db109fd3d3)) -* **dev:** Support passing "0" as port ([#590](https://github.com/vitejs/vite/issues/590)) ([ba9dda2](https://github.com/vitejs/vite/commit/ba9dda22ca89118f39fbbad7afb79c1898892e63)) -* **hmr:** correct hmr for sfc has setup script when it template change ([#763](https://github.com/vitejs/vite/issues/763)) ([9bea946](https://github.com/vitejs/vite/commit/9bea946397e2f63d1580e3f2c6410495f6e05e19)), closes [#748](https://github.com/vitejs/vite/issues/748) - - -### Features - -* **dev:** add hmr config for websocket connection ([#677](https://github.com/vitejs/vite/issues/677)) ([b753478](https://github.com/vitejs/vite/commit/b753478dfe96bd318b39552781e480ea068b6ead)) -* **dev:** proxy ws ([#865](https://github.com/vitejs/vite/issues/865)) ([c3ef4f6](https://github.com/vitejs/vite/commit/c3ef4f64ec09c6916f4e6b9764362a23843b98b6)), closes [#864](https://github.com/vitejs/vite/issues/864) -* set NODE_ENV if not present ([#732](https://github.com/vitejs/vite/issues/732)) ([0455b91](https://github.com/vitejs/vite/commit/0455b9191b9e497a80de6c11190d863e4e4c636a)), closes [#696](https://github.com/vitejs/vite/issues/696) -* suppot CSS modules named exports ([#750](https://github.com/vitejs/vite/issues/750)) ([d2ac431](https://github.com/vitejs/vite/commit/d2ac431e03a9eb91bd819b37100493edd4949530)) -* **build:** add option for `terser` ([#734](https://github.com/vitejs/vite/issues/734)) ([fb85cb2](https://github.com/vitejs/vite/commit/fb85cb2a75dd49bfe6df1a8a1038411b3744a4a2)), closes [#733](https://github.com/vitejs/vite/issues/733) -* **build:** use `fs.emptyDir` instead of `fs.remove` ([#744](https://github.com/vitejs/vite/issues/744)) ([e52e5ed](https://github.com/vitejs/vite/commit/e52e5ed1c5cf74c34cf6a35b7c1d507a3ce66373)), closes [#709](https://github.com/vitejs/vite/issues/709) - - -### Performance Improvements - -* improve regex performance ([#834](https://github.com/vitejs/vite/issues/834)) ([96531fc](https://github.com/vitejs/vite/commit/96531fc859c2f83a5ef66d36fc18f67528e600a6)) - - - -# [1.0.0-rc.4](https://github.com/vuejs/vite/compare/v1.0.0-rc.3...v1.0.0-rc.4) (2020-07-30) - - -### Bug Fixes - -* **hmr:** module rewrite should not cache hmr requests ([e386575](https://github.com/vuejs/vite/commit/e3865756bfb26065b0866be91d03d4b06e4e86dc)), closes [#603](https://github.com/vuejs/vite/issues/603) [#598](https://github.com/vuejs/vite/issues/598) -* support options for template block preprocessor render ([#641](https://github.com/vuejs/vite/issues/641)) ([540ae24](https://github.com/vuejs/vite/commit/540ae24b0d645a4f20bd71037edd716690452ce0)), closes [#634](https://github.com/vuejs/vite/issues/634) -* **build/css:** ensure consistent build css hash ([4fba48b](https://github.com/vuejs/vite/commit/4fba48be081e1d336368812ab23c9d5a74b98c06)), closes [#596](https://github.com/vuejs/vite/issues/596) -* **dev:** don't unregister user service worker ([#622](https://github.com/vuejs/vite/issues/622)) ([ab5d6f6](https://github.com/vuejs/vite/commit/ab5d6f6864f059ea88b5328f97bfdaa4b5146c6a)), closes [#615](https://github.com/vuejs/vite/issues/615) -* **dev:** fix path with query + ignore `?import` query with hmr ([#619](https://github.com/vuejs/vite/issues/619)) ([dd92f4f](https://github.com/vuejs/vite/commit/dd92f4f910553f8d8aaab0e587cb7788e643a24d)), closes [#617](https://github.com/vuejs/vite/issues/617) -* **dev:** use `path` + `content` as rewrite cache key ([#631](https://github.com/vuejs/vite/issues/631)) ([60c7424](https://github.com/vuejs/vite/commit/60c7424f101d52b4542f75c0c9fac1f617097dcd)), closes [#627](https://github.com/vuejs/vite/issues/627) -* handle ` - ``` - - - -# [1.0.0-rc.1](https://github.com/vuejs/vite/compare/v1.0.0-beta.12...v1.0.0-rc.1) (2020-07-17) - - - -# [1.0.0-beta.12](https://github.com/vuejs/vite/compare/v1.0.0-beta.11...v1.0.0-beta.12) (2020-07-16) - - -### Bug Fixes - -* **build:** external base url ([#515](https://github.com/vuejs/vite/issues/515)) ([b16548f](https://github.com/vuejs/vite/commit/b16548fde61f5192f3a9153d99c3785a623e8a12)), closes [#507](https://github.com/vuejs/vite/issues/507) -* **build:** link href used data url ([#516](https://github.com/vuejs/vite/issues/516)) ([8ae073e](https://github.com/vuejs/vite/commit/8ae073e59c77a092cbe505415f59a76e1cadffd4)), closes [#508](https://github.com/vuejs/vite/issues/508) -* **config:** merge array values in rollup config options ([abfe6f8](https://github.com/vuejs/vite/commit/abfe6f8732b057b256f152e71e2e450861636e30)), closes [#526](https://github.com/vuejs/vite/issues/526) -* **css:** fix lazy loaded css injection (fix [#530](https://github.com/vuejs/vite/issues/530)) ([a502399](https://github.com/vuejs/vite/commit/a50239988e57958c7e56e10bb7f24b4e5c8ed234)) -* **optimize:** resolve bare assets import inside node module ([#552](https://github.com/vuejs/vite/issues/552)) ([5801f66](https://github.com/vuejs/vite/commit/5801f6687d4e546ca70b1afbfe80569d90cca072)), closes [#551](https://github.com/vuejs/vite/issues/551) -* **resolve:** properly resolve optimized deps with name ending in .js ([c953f0d](https://github.com/vuejs/vite/commit/c953f0dacc97a557ac79ad73a8a69cd0c72c95b0)), closes [#540](https://github.com/vuejs/vite/issues/540) -* **transform:** keep path/id on transform context consistent between dev/build ([#519](https://github.com/vuejs/vite/issues/519)) ([6388e69](https://github.com/vuejs/vite/commit/6388e699617f7c72e753f9d961278b46a468da60)), closes [#518](https://github.com/vuejs/vite/issues/518) -* change `esbuild` compiler target to `es2020` + bump esbuild + bu… ([#525](https://github.com/vuejs/vite/issues/525)) ([893eeff](https://github.com/vuejs/vite/commit/893eeff4f6ef2134bd75f4e8623347ceab7ce229)), closes [#503](https://github.com/vuejs/vite/issues/503) -* fallback to http1 when proxy is required ([02cc24f](https://github.com/vuejs/vite/commit/02cc24f5e7c3219eb0dd77480f9df8208e81c09c)), closes [#484](https://github.com/vuejs/vite/issues/484) -* fix resolve optimize module + cache hit ([#500](https://github.com/vuejs/vite/issues/500)) ([3766767](https://github.com/vuejs/vite/commit/37667678e462748162d74d0107e619e837bf783c)), closes [#490](https://github.com/vuejs/vite/issues/490) -* inject web worker rollup plugin before node-resolve ([458a4bb](https://github.com/vuejs/vite/commit/458a4bbcb578d79041a91ea364ca53a6053d3ebf)) - - -### Features - -* **build:** add option for disable `rollup-plugin-vue` ([#517](https://github.com/vuejs/vite/issues/517)) ([5d06b0c](https://github.com/vuejs/vite/commit/5d06b0c018259a6ee2a2e0ae75f49951934cf8c1)) -* **transform:** expose notModified flag in transform context ([#510](https://github.com/vuejs/vite/issues/510)) ([2da41f1](https://github.com/vuejs/vite/commit/2da41f1011cc6f33fc8ee4dc279dcbb9214f0bca)) -* ` +``` + ## `InlineConfig` The `InlineConfig` interface extends `UserConfig` with additional properties: From 6d06ec07ae5ce7c62a6ac6e4d87a36d52a8b5fed Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 20 Jan 2021 15:58:12 -0500 Subject: [PATCH 181/514] release: v2.0.0-beta.35 --- packages/vite/CHANGELOG.md | 23 +++++++++++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index cb0f47e44c5939..5a3ba2881211a5 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,26 @@ +# [2.0.0-beta.35](https://github.com/vitejs/vite/compare/v2.0.0-beta.34...v2.0.0-beta.35) (2021-01-20) + + +### Bug Fixes + +* allow direct inspection of static file via browser ([a3c334f](https://github.com/vitejs/vite/commit/a3c334f66dbe1e5c49c4e5d77381aa0098c4a8a9)), closes [#1612](https://github.com/vitejs/vite/issues/1612) +* also resolve for module condition ([3a3029e](https://github.com/vitejs/vite/commit/3a3029effa0b83775f02fbd9469ef104eb6adb33)), closes [#1583](https://github.com/vitejs/vite/issues/1583) +* do not apply jsxInject on ts files ([a72a59c](https://github.com/vitejs/vite/commit/a72a59c55355a2a247b84178e63ce8c7cc1d7564)) +* inline async css for legacy builds ([940d483](https://github.com/vitejs/vite/commit/940d48333f6572314576da9312f36018fd70bdc8)) +* manually test global regex codeframeRE index ([#1608](https://github.com/vitejs/vite/issues/1608)) ([20d6c0f](https://github.com/vitejs/vite/commit/20d6c0fae160e25ab6cb76484baf910388dccdc6)) +* properly format css pre-processor errors from [@imported](https://github.com/imported) files ([ec18bde](https://github.com/vitejs/vite/commit/ec18bde7ee4045a47362240a6f5ff4997657c7ba)), closes [#1600](https://github.com/vitejs/vite/issues/1600) [#1601](https://github.com/vitejs/vite/issues/1601) +* **asset:** use stricter asset url marker and regex ([e6c8478](https://github.com/vitejs/vite/commit/e6c8478dd765e63f56e2c4559daf03f976f60b4c)), closes [#1602](https://github.com/vitejs/vite/issues/1602) +* **plugin-dynamic-import:** include assetDir in dynamic import polyfill module path ([#1610](https://github.com/vitejs/vite/issues/1610)) ([47ff0f4](https://github.com/vitejs/vite/commit/47ff0f4307da6a90db2fc43fcf0aaffdb9e36643)) +* **resolve:** get pkg from importer for relative id ([#1599](https://github.com/vitejs/vite/issues/1599)) ([c821f09](https://github.com/vitejs/vite/commit/c821f094c25a7acde87b868dced265aa6e792a57)) + + +### Features + +* **manifest:** include dynamic entries and dynamic imports ([#1609](https://github.com/vitejs/vite/issues/1609)) ([9ed4908](https://github.com/vitejs/vite/commit/9ed49085ae860fb96d51ac50845f96ceb9fa649f)) +* detect and warn against imports to transitively optimized deps ([3841e70](https://github.com/vitejs/vite/commit/3841e702213efac178aa90ab01825a813d3b4819)), closes [#1543](https://github.com/vitejs/vite/issues/1543) + + + # [2.0.0-beta.34](https://github.com/vitejs/vite/compare/v2.0.0-beta.33...v2.0.0-beta.34) (2021-01-20) diff --git a/packages/vite/package.json b/packages/vite/package.json index 7015dfb5fd2fc2..35c20dc40cd6a4 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.34", + "version": "2.0.0-beta.35", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 0633dabaf3afc99d551796640adb3aee0adee6e8 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 20 Jan 2021 16:19:30 -0500 Subject: [PATCH 182/514] docs: document library external globals --- docs/guide/build.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/guide/build.md b/docs/guide/build.md index deff04cbc6b59f..aefd258bf6b490 100644 --- a/docs/guide/build.md +++ b/docs/guide/build.md @@ -97,7 +97,16 @@ module.exports = { name: 'MyLib' }, rollupOptions: { - external: ['vue'] + // make sure to externalize deps that shouldn't be bundled + // into your library + external: ['vue'], + output: { + // Provide global variables to use in the UMD build + // for externalized deps + globals: { + vue: 'Vue' + } + } } } } From 0c0e2af3598391f178c39ca436bca5fd7b5b17fb Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 20 Jan 2021 16:40:19 -0500 Subject: [PATCH 183/514] chore: bump jest timeout --- jest.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 34d503fe84e3a9..ad5def4e9542b6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,7 @@ module.exports = { preset: 'ts-jest', testMatch: ['**/*.spec.[jt]s?(x)'], - testTimeout: process.env.CI ? 25000 : 5000, + testTimeout: process.env.CI ? 25000 : 10000, globalSetup: './scripts/jestGlobalSetup.js', globalTeardown: './scripts/jestGlobalTeardown.js', testEnvironment: './scripts/jestEnv.js', From 6bd21402a9e5955433656024f5548f12b12ea2fa Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 20 Jan 2021 16:44:31 -0500 Subject: [PATCH 184/514] feat: allow inline postcss config close #1061 --- docs/config/index.md | 8 +++++++ packages/vite/src/node/plugins/css.ts | 30 ++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 1c62c7f84a9a96..89ba6508cc1e15 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -128,6 +128,14 @@ export default ({ command, mode }) => { Configure CSS modules behavior. The options are passed on to [postcss-modules](https://github.com/css-modules/postcss-modules). +### css.postcss + +- **Type:** `string | (postcss.ProcessOptions & { plugins?: postcss.Plugin[] })` + + Inline PostCSS config (expects the same format as `postcss.config.js`), or a custom path to search PostCSS config from (default is project root). The search is done using [postcss-load-config](https://github.com/postcss/postcss-load-config). + + Note if an inline config is provided, Vite will not search for other PostCSS config sources. + ### css.preprocessorOptions - **Type:** `Record` diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 1969014391b8ba..f70d99510f7fc1 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -4,7 +4,8 @@ import { asyncReplace, cleanUrl, generateCodeFrame, - isDataUrl + isDataUrl, + isObject } from '../utils' import path from 'path' import { Plugin } from '../plugin' @@ -33,6 +34,11 @@ export interface CSSOptions { */ modules?: CSSModulesOptions | false preprocessorOptions?: Record + postcss?: + | string + | (ProcessOptions & { + plugins?: PostcssPlugin[] + }) } export interface CSSModulesOptions { @@ -311,7 +317,7 @@ async function compileCSS( // although at serve time it can work without processing, we do need to // crawl them in order to register watch dependencies. const needInlineImport = code.includes('@import') - const postcssConfig = await loadPostcssConfig(config.root) + const postcssConfig = await resolvePostcssConfig(config) const lang = id.match(cssLangRE)?.[1] // 1. plain css that needs no processing @@ -437,14 +443,28 @@ interface PostCSSConfigResult { let cachedPostcssConfig: PostCSSConfigResult | null | undefined -async function loadPostcssConfig( - root: string +async function resolvePostcssConfig( + config: ResolvedConfig ): Promise { if (cachedPostcssConfig !== undefined) { return cachedPostcssConfig } + + // inline postcss config via vite config + const inlineOptions = config.css?.postcss + if (isObject(inlineOptions)) { + const result = { + options: { ...inlineOptions }, + plugins: inlineOptions.plugins || [] + } + delete result.options.plugins + return (cachedPostcssConfig = result) + } + try { - return (cachedPostcssConfig = await postcssrc({}, root)) + const searchPath = + typeof inlineOptions === 'string' ? inlineOptions : config.root + return (cachedPostcssConfig = await postcssrc({}, searchPath)) } catch (e) { if (!/No PostCSS Config found/.test(e.message)) { throw e From edd2fd9de904a194f25e18136dfe298c7bcbbd8d Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 20 Jan 2021 17:45:41 -0500 Subject: [PATCH 185/514] feat: hmr for glob import --- .../glob-import/__tests__/glob-import.spec.ts | 47 ++++- packages/playground/testUtils.ts | 8 + packages/vite/package.json | 1 + packages/vite/src/node/importGlob.ts | 158 +++++++++++++++++ .../vite/src/node/plugins/importAnalysis.ts | 19 +- .../src/node/plugins/importAnaysisBuild.ts | 162 ++---------------- packages/vite/src/node/server/hmr.ts | 47 ++++- packages/vite/src/node/server/index.ts | 25 ++- packages/vite/types/shims.d.ts | 5 + 9 files changed, 309 insertions(+), 163 deletions(-) create mode 100644 packages/vite/src/node/importGlob.ts diff --git a/packages/playground/glob-import/__tests__/glob-import.spec.ts b/packages/playground/glob-import/__tests__/glob-import.spec.ts index f4e37ec46b7d0f..987218d48bab43 100644 --- a/packages/playground/glob-import/__tests__/glob-import.spec.ts +++ b/packages/playground/glob-import/__tests__/glob-import.spec.ts @@ -1,4 +1,10 @@ -import { isBuild } from '../../testUtils' +import { + addFile, + editFile, + isBuild, + removeFile, + untilUpdated +} from '../../testUtils' const filteredResult = { './foo.js': { @@ -44,3 +50,42 @@ test('should work', async () => { JSON.stringify(allResult, null, 2) ) }) + +if (!isBuild) { + test('hmr for adding/removing files', async () => { + addFile('dir/a.js', '') + await untilUpdated( + () => page.textContent('.result'), + JSON.stringify( + { + './dir/a.js': {}, + ...allResult + }, + null, + 2 + ) + ) + + // edit the added file + editFile('dir/a.js', () => 'export const msg ="a"') + await untilUpdated( + () => page.textContent('.result'), + JSON.stringify( + { + './dir/a.js': { + msg: 'a' + }, + ...allResult + }, + null, + 2 + ) + ) + + removeFile('dir/a.js') + await untilUpdated( + () => page.textContent('.result'), + JSON.stringify(allResult, null, 2) + ) + }) +} diff --git a/packages/playground/testUtils.ts b/packages/playground/testUtils.ts index 59fa0af8080a56..cc69d528f828f9 100644 --- a/packages/playground/testUtils.ts +++ b/packages/playground/testUtils.ts @@ -67,6 +67,14 @@ export function editFile(filename: string, replacer: (str: string) => string) { fs.writeFileSync(filename, modified) } +export function addFile(filename: string, content: string) { + fs.writeFileSync(path.resolve(testDir, filename), content) +} + +export function removeFile(filename: string) { + fs.unlinkSync(path.resolve(testDir, filename)) +} + export function findAssetFile(match: string | RegExp, base = '') { const assetsDir = path.join(testDir, 'dist', base, 'assets') const files = fs.readdirSync(assetsDir) diff --git a/packages/vite/package.json b/packages/vite/package.json index 35c20dc40cd6a4..f048701e727b2f 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -99,6 +99,7 @@ "magic-string": "^0.25.7", "merge-source-map": "^1.1.0", "mime": "^2.4.7", + "minimatch": "^3.0.4", "okie": "^1.0.1", "open": "^7.3.0", "open-in-editor": "^2.2.0", diff --git a/packages/vite/src/node/importGlob.ts b/packages/vite/src/node/importGlob.ts new file mode 100644 index 00000000000000..24bec27742ea4c --- /dev/null +++ b/packages/vite/src/node/importGlob.ts @@ -0,0 +1,158 @@ +import path from 'path' +import glob from 'fast-glob' +import { + isModernFlag, + preloadMethod, + preloadMarker +} from './plugins/importAnaysisBuild' +import { cleanUrl } from './utils' +import { RollupError } from 'rollup' + +export async function transformImportGlob( + source: string, + pos: number, + importer: string, + importIndex: number, + normalizeUrl?: (url: string, pos: number) => Promise<[string, string]> +): Promise<{ + importsString: string + imports: string[] + exp: string + endIndex: number + isEager: boolean + pattern: string + base: string +}> { + const isEager = source.slice(pos, pos + 21) === 'import.meta.globEager' + + const err = (msg: string) => { + const e = new Error(`Invalid glob import syntax: ${msg}`) + ;(e as any).pos = pos + return e + } + + importer = cleanUrl(importer) + const importerBasename = path.basename(importer) + + let [pattern, endIndex] = lexGlobPattern(source, pos) + if (!pattern.startsWith('.')) { + throw err(`pattern must start with "."`) + } + let base = path.dirname(importer) + let parentDepth = 0 + while (pattern.startsWith('../')) { + pattern = pattern.slice(3) + base = path.resolve(base, '../') + parentDepth++ + } + if (pattern.startsWith('./')) { + pattern = pattern.slice(2) + } + + const files = glob.sync(pattern, { cwd: base }) + const imports: string[] = [] + let importsString = `` + let entries = `` + for (let i = 0; i < files.length; i++) { + // skip importer itself + if (files[i] === importerBasename) continue + const file = parentDepth + ? `${'../'.repeat(parentDepth)}${files[i]}` + : `./${files[i]}` + let importee = file + if (normalizeUrl) { + ;[importee] = await normalizeUrl(file, pos) + } + imports.push(importee) + const identifier = `__glob_${importIndex}_${i}` + if (isEager) { + importsString += `import * as ${identifier} from ${JSON.stringify( + importee + )};` + entries += ` ${JSON.stringify(file)}: ${identifier},` + } else { + let imp = `import(${JSON.stringify(importee)})` + if (!normalizeUrl) { + imp = + `(${isModernFlag}` + + `? ${preloadMethod}(()=>${imp},"${preloadMarker}")` + + `: ${imp})` + } + entries += ` ${JSON.stringify(file)}: () => ${imp},` + } + } + + return { + imports, + importsString, + exp: `{${entries}}`, + endIndex, + isEager, + pattern, + base + } +} + +const enum LexerState { + inCall, + inSingleQuoteString, + inDoubleQuoteString, + inTemplateString +} + +function lexGlobPattern(code: string, pos: number): [string, number] { + let state = LexerState.inCall + let pattern = '' + + let i = code.indexOf(`(`, pos) + 1 + outer: for (; i < code.length; i++) { + const char = code.charAt(i) + switch (state) { + case LexerState.inCall: + if (char === `'`) { + state = LexerState.inSingleQuoteString + } else if (char === `"`) { + state = LexerState.inDoubleQuoteString + } else if (char === '`') { + state = LexerState.inTemplateString + } else if (/\s/.test(char)) { + continue + } else { + error(i) + } + break + case LexerState.inSingleQuoteString: + if (char === `'`) { + break outer + } else { + pattern += char + } + break + case LexerState.inDoubleQuoteString: + if (char === `"`) { + break outer + } else { + pattern += char + } + break + case LexerState.inTemplateString: + if (char === '`') { + break outer + } else { + pattern += char + } + break + default: + throw new Error('unknown import.meta.glob lexer state') + } + } + return [pattern, code.indexOf(`)`, i) + 1] +} + +function error(pos: number) { + const err = new Error( + `import.meta.glob() can only accept string literals.` + ) as RollupError + err.pos = pos + throw err +} diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index ef07c228a7427b..9c6000f2ad3b86 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -36,7 +36,7 @@ import { checkPublicFile } from './asset' import { parse as parseJS } from 'acorn' import type { Node } from 'estree' import { makeLegalIdentifier } from '@rollup/pluginutils' -import { transformImportGlob } from './importAnaysisBuild' +import { transformImportGlob } from '../importGlob' import isBuiltin from 'isbuiltin' const isDebug = !!process.env.DEBUG @@ -260,15 +260,28 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { } else if (prop === '.glo' && source[end + 4] === 'b') { // transform import.meta.glob() // e.g. `import.meta.glob('glob:./dir/*.js')` - const { imports, exp, endIndex } = await transformImportGlob( + const { + imports, + importsString, + exp, + endIndex, + base, + pattern + } = await transformImportGlob( source, start, importer, index, normalizeUrl ) - str().prepend(imports) + str().prepend(importsString) str().overwrite(expStart, endIndex, exp) + imports.forEach((url) => importedUrls.add(url)) + server._globImporters[importerModule.file!] = { + module: importerModule, + base, + pattern + } } continue } diff --git a/packages/vite/src/node/plugins/importAnaysisBuild.ts b/packages/vite/src/node/plugins/importAnaysisBuild.ts index b9ea70a543f2ca..654a99bdc76c51 100644 --- a/packages/vite/src/node/plugins/importAnaysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnaysisBuild.ts @@ -1,12 +1,11 @@ import path from 'path' -import glob from 'fast-glob' import { ResolvedConfig } from '../config' import { Plugin } from '../plugin' -import { cleanUrl } from '../utils' import MagicString from 'magic-string' import { ImportSpecifier, init, parse as parseImports } from 'es-module-lexer' -import { RollupError, OutputChunk } from 'rollup' +import { OutputChunk } from 'rollup' import { chunkToEmittedCssFileMap } from './css' +import { transformImportGlob } from '../importGlob' /** * A flag for injected helpers. This flag will be set to `false` if the output @@ -14,11 +13,11 @@ import { chunkToEmittedCssFileMap } from './css' * dropped. */ export const isModernFlag = `__VITE_IS_MODERN__` +export const preloadMethod = `__vitePreload` +export const preloadMarker = `__VITE_PRELOAD__` const preloadHelperId = 'vite/preload-helper' -const preloadMethod = `__vitePreload` const preloadCode = `const seen = {};export const ${preloadMethod} = ${preload.toString()}` -const preloadMarker = `__VITE_PRELOAD__` const preloadMarkerRE = new RegExp(`,?"${preloadMarker}"`, 'g') /** @@ -120,13 +119,13 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { // import.meta.glob if (isGlob) { - const { imports, exp, endIndex, isEager } = await transformImportGlob( - source, - start, - importer, - index - ) - str().prepend(imports) + const { + importsString, + exp, + endIndex, + isEager + } = await transformImportGlob(source, start, importer, index) + str().prepend(importsString) str().overwrite(expStart, endIndex, exp) if (!isEager) { needPreloadHelper = true @@ -241,142 +240,3 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { } } } - -export async function transformImportGlob( - source: string, - pos: number, - importer: string, - importIndex: number, - normalizeUrl?: (url: string, pos: number) => Promise<[string, string]> -): Promise<{ - imports: string - exp: string - endIndex: number - isEager: boolean -}> { - const isEager = source.slice(pos, pos + 21) === 'import.meta.globEager' - - const err = (msg: string) => { - const e = new Error(`Invalid glob import syntax: ${msg}`) - ;(e as any).pos = pos - return e - } - - importer = cleanUrl(importer) - const importerBasename = path.basename(importer) - - let [pattern, endIndex] = lexGlobPattern(source, pos) - if (!pattern.startsWith('.')) { - throw err(`pattern must start with "."`) - } - let base = path.dirname(importer) - let parentDepth = 0 - while (pattern.startsWith('../')) { - pattern = pattern.slice(3) - base = path.resolve(base, '../') - parentDepth++ - } - if (pattern.startsWith('./')) { - pattern = pattern.slice(2) - } - - const files = glob.sync(pattern, { cwd: base }) - let imports = `` - let entries = `` - for (let i = 0; i < files.length; i++) { - // skip importer itself - if (files[i] === importerBasename) continue - const file = parentDepth - ? `${'../'.repeat(parentDepth)}${files[i]}` - : `./${files[i]}` - let importee = file - if (normalizeUrl) { - ;[importee] = await normalizeUrl(file, pos) - } - const identifier = `__glob_${importIndex}_${i}` - if (isEager) { - imports += `import * as ${identifier} from ${JSON.stringify(importee)};` - entries += ` ${JSON.stringify(file)}: ${identifier},` - } else { - let imp = `import(${JSON.stringify(importee)})` - if (!normalizeUrl) { - imp = - `(${isModernFlag}` + - `? ${preloadMethod}(()=>${imp},"${preloadMarker}")` + - `: ${imp})` - } - entries += ` ${JSON.stringify(file)}: () => ${imp},` - } - } - - return { - imports, - exp: `{${entries}}`, - endIndex, - isEager - } -} - -const enum LexerState { - inCall, - inSingleQuoteString, - inDoubleQuoteString, - inTemplateString -} - -function lexGlobPattern(code: string, pos: number): [string, number] { - let state = LexerState.inCall - let pattern = '' - - let i = code.indexOf(`(`, pos) + 1 - outer: for (; i < code.length; i++) { - const char = code.charAt(i) - switch (state) { - case LexerState.inCall: - if (char === `'`) { - state = LexerState.inSingleQuoteString - } else if (char === `"`) { - state = LexerState.inDoubleQuoteString - } else if (char === '`') { - state = LexerState.inTemplateString - } else if (/\s/.test(char)) { - continue - } else { - error(i) - } - break - case LexerState.inSingleQuoteString: - if (char === `'`) { - break outer - } else { - pattern += char - } - break - case LexerState.inDoubleQuoteString: - if (char === `"`) { - break outer - } else { - pattern += char - } - break - case LexerState.inTemplateString: - if (char === '`') { - break outer - } else { - pattern += char - } - break - default: - throw new Error('unknown import.meta.glob lexer state') - } - } - return [pattern, code.indexOf(`)`, i) + 1] -} - -function error(pos: number) { - const err = new Error( - `import.meta.glob() can only accept string literals.` - ) as RollupError - err.pos = pos - throw err -} diff --git a/packages/vite/src/node/server/hmr.ts b/packages/vite/src/node/server/hmr.ts index 27701d2ffe0e66..9e6e4185c1d45a 100644 --- a/packages/vite/src/node/server/hmr.ts +++ b/packages/vite/src/node/server/hmr.ts @@ -8,6 +8,7 @@ import slash from 'slash' import { Update } from 'types/hmrPayload' import { CLIENT_DIR } from '../constants' import { RollupError } from 'rollup' +import match from 'minimatch' export const debugHmr = createDebugger('vite:hmr') @@ -30,14 +31,16 @@ export interface HmrContext { server: ViteDevServer } +function getShortName(file: string, root: string) { + return file.startsWith(root + '/') ? path.posix.relative(root, file) : file +} + export async function handleHMRUpdate( file: string, server: ViteDevServer ): Promise { const { ws, config, moduleGraph } = server - const shortFile = file.startsWith(config.root + '/') - ? path.posix.relative(config.root, file) - : file + const shortFile = getShortName(file, config.root) if (file === config.configFile || file.endsWith('.env')) { // TODO auto restart server @@ -118,10 +121,19 @@ export async function handleHMRUpdate( return } + updateModules(shortFile, hmrContext.modules, timestamp, server) +} + +function updateModules( + file: string, + modules: ModuleNode[], + timestamp: number, + { config, ws }: ViteDevServer +) { const updates: Update[] = [] const invalidatedModules = new Set() - for (const mod of hmrContext.modules) { + for (const mod of modules) { const boundaries = new Set<{ boundary: ModuleNode acceptedVia: ModuleNode @@ -129,7 +141,7 @@ export async function handleHMRUpdate( invalidate(mod, timestamp, invalidatedModules) const hasDeadEnd = propagateUpdate(mod, timestamp, boundaries) if (hasDeadEnd) { - config.logger.info(chalk.green(`page reload `) + chalk.dim(shortFile), { + config.logger.info(chalk.green(`page reload `) + chalk.dim(file), { clear: true, timestamp: true }) @@ -162,6 +174,31 @@ export async function handleHMRUpdate( }) } +export async function handleFileAddUnlink( + file: string, + server: ViteDevServer, + isUnlink = false +) { + if (isUnlink && file in server._globImporters) { + delete server._globImporters[file] + } else { + const modules = [] + for (const i in server._globImporters) { + const { module, base, pattern } = server._globImporters[i] + const relative = path.relative(base, file) + if (match(relative, pattern)) { + modules.push(module) + } + } + updateModules( + getShortName(file, server.config.root), + modules, + Date.now(), + server + ) + } +} + function propagateUpdate( node: ModuleNode, timestamp: number, diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 3a3437c26819ad..1be0908589f2f6 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -27,11 +27,11 @@ import { serveStaticMiddleware } from './middlewares/static' import { timeMiddleware } from './middlewares/time' -import { ModuleGraph } from './moduleGraph' +import { ModuleGraph, ModuleNode } from './moduleGraph' import { Connect } from 'types/connect' import { createDebugger, normalizePath } from '../utils' import { errorMiddleware, prepareError } from './middlewares/error' -import { handleHMRUpdate, HmrOptions } from './hmr' +import { handleHMRUpdate, HmrOptions, handleFileAddUnlink } from './hmr' import { openBrowser } from './openBrowser' import launchEditorMiddleware from 'launch-editor-middleware' import { TransformResult } from 'rollup' @@ -222,6 +222,16 @@ export interface ViteDevServer { * @internal */ _ssrExternals: string[] | null + /** + * @internal + */ + _globImporters: Record +} + +interface GlobImporter { + base: string + pattern: string + module: ModuleNode } export async function createServer( @@ -296,7 +306,8 @@ export async function createServer( ]) }, _optimizeDepsMetadata: null, - _ssrExternals: null + _ssrExternals: null, + _globImporters: {} } process.once('SIGTERM', async () => { @@ -323,6 +334,14 @@ export async function createServer( } }) + watcher.on('add', (file) => { + handleFileAddUnlink(normalizePath(file), server) + }) + + watcher.on('unlink', (file) => { + handleFileAddUnlink(normalizePath(file), server, true) + }) + // apply server configuration hooks from plugins const postHooks: ((() => void) | void)[] = [] for (const plugin of plugins) { diff --git a/packages/vite/types/shims.d.ts b/packages/vite/types/shims.d.ts index 90ffcab496aaab..15952f07ecb3a0 100644 --- a/packages/vite/types/shims.d.ts +++ b/packages/vite/types/shims.d.ts @@ -102,3 +102,8 @@ declare module 'isbuiltin' { function isBuiltin(moduleName: string): boolean export default isBuiltin } + +declare module 'minimatch' { + function match(path: string, pattern: string): boolean + export default match +} From 57c03435256b97857700e3df0e45e89fc324ed2c Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 20 Jan 2021 17:55:24 -0500 Subject: [PATCH 186/514] types: fix export, use public trimmed dts --- packages/vite/api-extractor.json | 3 ++- packages/vite/src/node/server/index.ts | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/vite/api-extractor.json b/packages/vite/api-extractor.json index b468b4c55b6ee3..0b5b4178c2bd90 100644 --- a/packages/vite/api-extractor.json +++ b/packages/vite/api-extractor.json @@ -7,7 +7,8 @@ "dtsRollup": { "enabled": true, - "untrimmedFilePath": "./dist/node/index.d.ts" + "untrimmedFilePath": "", + "publicTrimmedFilePath": "./dist/node/index.d.ts" }, "apiReport": { diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 1be0908589f2f6..b39b59866b1834 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -225,13 +225,14 @@ export interface ViteDevServer { /** * @internal */ - _globImporters: Record -} - -interface GlobImporter { - base: string - pattern: string - module: ModuleNode + _globImporters: Record< + string, + { + base: string + pattern: string + module: ModuleNode + } + > } export async function createServer( From d9afa8dc4a1e987a53c99ea6f876fe76aa653aed Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 20 Jan 2021 18:10:30 -0500 Subject: [PATCH 187/514] docs: clarify virtual file plugin example --- docs/guide/api-plugin.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/guide/api-plugin.md b/docs/guide/api-plugin.md index 07b032da1b47cc..85b7e31b35d639 100644 --- a/docs/guide/api-plugin.md +++ b/docs/guide/api-plugin.md @@ -10,7 +10,7 @@ Vite plugins extends Rollup's well-designed plugin interface with a few extra vi It is common convention to author a Vite/Rollup plugin as a factory function that returns the actual plugin object. The function can accept options which allows users to customize the behavior of the plugin. ::: -### Serving a Virtual File +### Importing a Virtual File ```js export default function myPlugin() { @@ -32,6 +32,14 @@ export default function myPlugin() { } ``` +Which allows importing the file in JavaScript: + +```js +import { msg } from '@my-virtual-file' + +console.log(msg) +``` + ### Transforming Custom File Types ```js From 85c89bea9807090d928942a72b972183ebf8483a Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 20 Jan 2021 18:28:19 -0500 Subject: [PATCH 188/514] fix: always reload when html is edited in middleware mode --- packages/vite/src/node/server/hmr.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/hmr.ts b/packages/vite/src/node/server/hmr.ts index 9e6e4185c1d45a..3da7f925a6345d 100644 --- a/packages/vite/src/node/server/hmr.ts +++ b/packages/vite/src/node/server/hmr.ts @@ -112,7 +112,9 @@ export async function handleHMRUpdate( }) ws.send({ type: 'full-reload', - path: '/' + slash(path.relative(config.root, file)) + path: config.server.middlewareMode + ? '*' + : '/' + slash(path.relative(config.root, file)) }) } else { // loaded but not in the module graph, probably not js From 259d6be9666732d39e2789d99520e794a1f82fc3 Mon Sep 17 00:00:00 2001 From: Domantas Date: Thu, 21 Jan 2021 01:29:34 +0200 Subject: [PATCH 189/514] docs: clear css pre-processor install instructions (#1616) --- docs/guide/features.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/guide/features.md b/docs/guide/features.md index 63f3e1573df296..64e0d9c83c4b6a 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -119,11 +119,18 @@ CSS modules behavior can be configured via the [`css.modules` option](/config/#c Because Vite targets modern browsers only, it is recommended to use native CSS variables with PostCSS plugins that implement CSSWG drafts (e.g. [postcss-nesting](https://github.com/jonathantneal/postcss-nesting)) and author plain, future-standards-compliant CSS. -That said, Vite does provide built-in support for `.scss`, `.sass`, `.less`, `.styl` and `.stylus` files. There is no need to install Vite-specific plugins for them, but the corresponding pre-processor itself must be installed as a peer dependency: +That said, Vite does provide built-in support for `.scss`, `.sass`, `.less`, `.styl` and `.stylus` files. There is no need to install Vite-specific plugins for them, but the corresponding pre-processor itself must be installed: -- `.scss` and `.sass`: [sass](https://www.npmjs.com/package/sass) -- `.less`: [less](https://www.npmjs.com/package/less) -- `.styl` and `.stylus`: [stylus](https://www.npmjs.com/package/stylus) +```bash +# .scss and .sass +npm install -D sass + +# .less +npm install -D less + +# .styl and .stylus +npm install -D stylus +``` You can also use CSS modules combined with pre-processors by prepending `.module` to the file extension, for example `style.module.scss`. From 2a179672564d3fe54a4c50717b127af6cd67fd8c Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 20 Jan 2021 22:42:24 -0500 Subject: [PATCH 190/514] refactor: improve bare import regex --- packages/vite/src/node/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 098d108e99606d..5d290a9cc1e94b 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -8,7 +8,7 @@ import slash from 'slash' import { FS_PREFIX, SUPPORTED_EXTS } from './constants' import resolve from 'resolve' -export const bareImportRE = /^[\w@]/ +export const bareImportRE = /^[\w@](?!.*:\/\/)/ export const deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\// let isRunningWithYarnPnp: boolean From 4e0cd7384e850e4b7f23b68e5b591bb717650b79 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 20 Jan 2021 23:16:32 -0500 Subject: [PATCH 191/514] fix: still resolve jsnext fields --- packages/vite/src/node/plugins/resolve.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 676634d359c2a4..e48ad1a7a95266 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -25,7 +25,12 @@ import isBuiltin from 'isbuiltin' import { isCSSRequest } from './css' import { resolve as _resolveExports } from 'resolve.exports' -const mainFields = ['module', 'main'] +const mainFields = [ + 'module', + 'jsnext:main', // moment still uses this... + 'jsnext', + 'main' +] function resolveExports( pkg: PackageData['data'], From 30f06d9a13324f9fd984395d54f755a620466e69 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 21 Jan 2021 11:02:41 -0500 Subject: [PATCH 192/514] release: v2.0.0-beta.36 --- packages/vite/CHANGELOG.md | 16 ++++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 5a3ba2881211a5..9a0cdfcf3e1c7d 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,19 @@ +# [2.0.0-beta.36](https://github.com/vitejs/vite/compare/v2.0.0-beta.35...v2.0.0-beta.36) (2021-01-21) + + +### Bug Fixes + +* always reload when html is edited in middleware mode ([85c89be](https://github.com/vitejs/vite/commit/85c89bea9807090d928942a72b972183ebf8483a)) +* still resolve jsnext fields ([6e06108](https://github.com/vitejs/vite/commit/6e061089c62898086c07fad7154b178446a18da5)) + + +### Features + +* allow inline postcss config ([6bd2140](https://github.com/vitejs/vite/commit/6bd21402a9e5955433656024f5548f12b12ea2fa)), closes [#1061](https://github.com/vitejs/vite/issues/1061) +* hmr for glob import ([edd2fd9](https://github.com/vitejs/vite/commit/edd2fd9de904a194f25e18136dfe298c7bcbbd8d)) + + + # [2.0.0-beta.35](https://github.com/vitejs/vite/compare/v2.0.0-beta.34...v2.0.0-beta.35) (2021-01-20) diff --git a/packages/vite/package.json b/packages/vite/package.json index f048701e727b2f..87f1471f615d0f 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.35", + "version": "2.0.0-beta.36", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 6cf893dca5cf20b2d2062a296c53023b95d39cce Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 21 Jan 2021 11:07:25 -0500 Subject: [PATCH 193/514] chore: note link to changelog [skip ci] --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 395af493b2e07a..675ce82325aa10 100644 --- a/README.md +++ b/README.md @@ -30,14 +30,14 @@ Vite is now in 2.0 beta. Check out the [Migration Guide](https://vitejs.dev/guid ## Packages -| Package | Version | -|---------------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------| +| Package | Version (click for changelogs) | +| ------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- | | [vite](packages/vite) | [![vite version](https://img.shields.io/npm/v/vite.svg?label=%20)](packages/vite/CHANGELOG.md) | | [@vitejs/plugin-vue](packages/plugin-vue) | [![plugin-vue version](https://img.shields.io/npm/v/@vitejs/plugin-vue.svg?label=%20)](packages/plugin-vue/CHANGELOG.md) | | [@vitejs/plugin-vue-jsx](packages/plugin-vue-jsx) | [![plugin-vue-jsx version](https://img.shields.io/npm/v/@vitejs/plugin-vue-jsx.svg?label=%20)](packages/plugin-vue-jsx/CHANGELOG.md) | | [@vitejs/plugin-react-refresh](packages/plugin-react-refresh) | [![plugin-react-refresh version](https://img.shields.io/npm/v/@vitejs/plugin-react-refresh.svg?label=%20)](packages/plugin-react-refresh/CHANGELOG.md) | | [@vitejs/plugin-legacy](packages/plugin-legacy) | [![plugin-legacy version](https://img.shields.io/npm/v/@vitejs/plugin-legacy.svg?label=%20)](packages/plugin-legacy/CHANGELOG.md) | -| [@vitejs/create-app](packages/create-app) | [![create-app version](https://img.shields.io/npm/v/@vitejs/create-app.svg?label=%20)](packages/create-app/CHANGELOG.md) +| [@vitejs/create-app](packages/create-app) | [![create-app version](https://img.shields.io/npm/v/@vitejs/create-app.svg?label=%20)](packages/create-app/CHANGELOG.md) | ## Contribution From 037e1e536fe2144bbfe2e24fff9956dc67ece7ae Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 22 Jan 2021 06:06:15 -0800 Subject: [PATCH 194/514] docs: fix typo (#1633) [skip ci] --- docs/guide/dep-pre-bundling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/dep-pre-bundling.md b/docs/guide/dep-pre-bundling.md index a574e3772ead8e..c32edf637ae5cf 100644 --- a/docs/guide/dep-pre-bundling.md +++ b/docs/guide/dep-pre-bundling.md @@ -13,7 +13,7 @@ Pre-bundling them to speed up dev server page load... This is Vite performing what we call "dependency pre-bundling". This process serves two purposes: -1. **CommonJS and UMD comaptibility:** During development, Vite's dev serves all code as native ESM. Therefore, Vite must convert dependencies that are shipped as CommonJS or UMD into ESM first. +1. **CommonJS and UMD compatibility:** During development, Vite's dev serves all code as native ESM. Therefore, Vite must convert dependencies that are shipped as CommonJS or UMD into ESM first. When converting CommonJS dependencies, Vite performs smart import analysis so that named imports to CommonJS modules will work as expected even if the exports are dynamically assigned (e.g. React): From 20cf718ac77abfce5656ee9836f8c06ddbbc440d Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 09:10:33 -0500 Subject: [PATCH 195/514] fix: handle esm config syntax error in Node 12 close #1635 --- packages/vite/src/node/config.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 709b935e527a8a..396415e5223d7a 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -457,7 +457,14 @@ export async function loadConfigFromFile( userConfig = require(resolvedPath) debug(`cjs config loaded in ${Date.now() - start}ms`) } catch (e) { - const ignored = /Cannot use import statement|Unexpected token 'export'|Must use import to load ES Module/ + const ignored = new RegExp( + [ + `Cannot use import statement`, + `Unexpected token 'export'`, + `Must use import to load ES Module`, + `Unexpected identifier` // #1635 Node <= 12.4 has no esm detection + ].join('|') + ) if (!ignored.test(e.message)) { throw e } From b462e33ce3d31df49ada436324a9c32cd5c9053a Mon Sep 17 00:00:00 2001 From: zdw <252675163@qq.com> Date: Fri, 22 Jan 2021 22:22:03 +0800 Subject: [PATCH 196/514] fix: normalize paths for cjs optimized deps on windows (#1631) --- packages/vite/src/node/plugins/importAnalysis.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 9c6000f2ad3b86..6ef3e423da7e83 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -493,7 +493,9 @@ function isOptimizedCjs( }: ViteDevServer ): boolean { if (optimizeDepsMetadata && optimizeCacheDir) { - const relative = path.relative(optimizeCacheDir, cleanUrl(id)) + const relative = normalizePath( + path.relative(optimizeCacheDir, cleanUrl(id)) + ) return relative in optimizeDepsMetadata.cjsEntries } return false From 5d77665def42ffafc699a0006e4527536dfd1114 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 09:32:17 -0500 Subject: [PATCH 197/514] fix(ssr): do not inject inlined css in ssr build fix #1643 --- packages/vite/src/node/plugins/css.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index f70d99510f7fc1..92fd9c13b3dfab 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -236,7 +236,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { source: chunkCSS }) chunkToEmittedCssFileMap.set(chunk, fileHandle) - } else { + } else if (!config.build.ssr) { // legacy build, inline css const style = `__vite_style__` const injectCode = From cf81aa399b2df1ee8441a1b8922908f4e36358d6 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 10:14:42 -0500 Subject: [PATCH 198/514] fix(manifest): avoid chunks with same name overwriting one another close #1632 --- packages/vite/src/node/plugins/manifest.ts | 50 +++++++++++++++++----- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/packages/vite/src/node/plugins/manifest.ts b/packages/vite/src/node/plugins/manifest.ts index 33bde59f8b6e55..7a1141f378c4dc 100644 --- a/packages/vite/src/node/plugins/manifest.ts +++ b/packages/vite/src/node/plugins/manifest.ts @@ -1,15 +1,20 @@ +import path from 'path' import { ResolvedConfig } from '..' import { Plugin } from '../plugin' +type Manifest = Record + +interface ManifestEntry { + file: string + facadeModuleId?: string + isEntry?: boolean + isDynamicEntry?: boolean + imports?: string[] + dynamicImports?: string[] +} + export function manifestPlugin(config: ResolvedConfig): Plugin { - const manifest: Record< - string, - { - file: string - imports?: string[], - dynamicImports?: string[] - } - > = {} + const manifest: Manifest = {} let outputCount = 0 @@ -20,18 +25,41 @@ export function manifestPlugin(config: ResolvedConfig): Plugin { const chunk = bundle[file] if (chunk.type === 'chunk') { if (chunk.isEntry || chunk.isDynamicEntry) { - const name = + let name = format === 'system' && !chunk.name.includes('-legacy') ? chunk.name + '-legacy' : chunk.name - manifest[name + '.js'] = { + let dedupeIndex = 0 + while (name + '.js' in manifest) { + name = `${name}-${++dedupeIndex}` + } + const entry: ManifestEntry = { + isEntry: chunk.isEntry, + isDynamicEntry: chunk.isDynamicEntry, file: chunk.fileName, imports: chunk.imports, dynamicImports: chunk.dynamicImports } + + if ( + chunk.facadeModuleId && + chunk.facadeModuleId.startsWith(config.root) + ) { + entry.facadeModuleId = chunk.facadeModuleId.slice( + config.root.length + 1 + ) + } + + manifest[name + '.js'] = entry } } else if (chunk.name) { - manifest[chunk.name] = { file: chunk.fileName } + const ext = path.extname(chunk.name) || '' + let name = chunk.name.slice(0, -ext.length) + let dedupeIndex = 0 + while (name + ext in manifest) { + name = `${name}-${++dedupeIndex}` + } + manifest[name + ext] = { file: chunk.fileName } } } From 52ae44fe97b53ce82633268030bb46594f385860 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 11:50:01 -0500 Subject: [PATCH 199/514] fix(css): fix url rewriting in @imported css fix #1629 --- .../assets/__tests__/assets.spec.ts | 4 + packages/playground/assets/css/css-url.css | 4 +- .../assets/css/nested/at-imported-css-url.css | 4 + packages/playground/assets/index.html | 5 + packages/vite/src/node/plugins/css.ts | 114 +++++++++++++----- 5 files changed, 102 insertions(+), 29 deletions(-) create mode 100644 packages/playground/assets/css/nested/at-imported-css-url.css diff --git a/packages/playground/assets/__tests__/assets.spec.ts b/packages/playground/assets/__tests__/assets.spec.ts index c7250c43b8c23d..eae3552fbb7101 100644 --- a/packages/playground/assets/__tests__/assets.spec.ts +++ b/packages/playground/assets/__tests__/assets.spec.ts @@ -57,6 +57,10 @@ describe('css url() references', () => { expect(await getBg('.css-url-relative')).toMatch(assetMatch) }) + test('relative in @import', async () => { + expect(await getBg('.css-url-relative-at-imported')).toMatch(assetMatch) + }) + test('absolute', async () => { expect(await getBg('.css-url-absolute')).toMatch(assetMatch) }) diff --git a/packages/playground/assets/css/css-url.css b/packages/playground/assets/css/css-url.css index 1774b4860f61d2..5caf72cf8be2e3 100644 --- a/packages/playground/assets/css/css-url.css +++ b/packages/playground/assets/css/css-url.css @@ -1,3 +1,5 @@ +@import './nested/at-imported-css-url.css'; + .css-url-absolute { background: url(/nested/asset.png); background-size: 10px; @@ -9,7 +11,7 @@ } .css-url-public { - background: url("/icon.png"); + background: url('/icon.png'); background-size: 10px; } diff --git a/packages/playground/assets/css/nested/at-imported-css-url.css b/packages/playground/assets/css/nested/at-imported-css-url.css new file mode 100644 index 00000000000000..cc436dc7d8666a --- /dev/null +++ b/packages/playground/assets/css/nested/at-imported-css-url.css @@ -0,0 +1,4 @@ +.css-url-relative-at-imported { + background: url(../../nested/asset.png); + background-size: 10px; +} diff --git a/packages/playground/assets/index.html b/packages/playground/assets/index.html index bcdee697f0a3b7..a8bd4fb4b198ea 100644 --- a/packages/playground/assets/index.html +++ b/packages/playground/assets/index.html @@ -28,6 +28,11 @@

CSS url references

CSS background (relative)
+
+ CSS background (relative from @imported file in different dir) +
CSS background (public)
diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 92fd9c13b3dfab..8349749f2b255e 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -5,7 +5,8 @@ import { cleanUrl, generateCodeFrame, isDataUrl, - isObject + isObject, + normalizePath } from '../utils' import path from 'path' import { Plugin } from '../plugin' @@ -20,8 +21,13 @@ import { } from 'rollup' import { dataToEsm } from '@rollup/pluginutils' import chalk from 'chalk' -import { CLIENT_PUBLIC_PATH } from '../constants' -import { ProcessOptions, Result, Plugin as PostcssPlugin } from 'postcss' +import { CLIENT_PUBLIC_PATH, FS_PREFIX } from '../constants' +import { + ProcessOptions, + Result, + Plugin as PostcssPlugin, + PluginCreator +} from 'postcss' import { ViteDevServer } from '../' import { assetUrlRE, urlToBuiltUrl } from './asset' import MagicString from 'magic-string' @@ -92,15 +98,38 @@ export function cssPlugin(config: ResolvedConfig): Plugin { return } - let { code: css, modules, deps } = await compileCSS(id, raw, config) + const urlReplacer: CssUrlReplacer = server + ? (url, importer) => { + if (url.startsWith('/')) return url + const filePath = normalizePath( + path.resolve(path.dirname(importer || id), url) + ) + if (filePath.startsWith(config.root)) { + return filePath.slice(config.root.length) + } else { + return `${FS_PREFIX}${filePath}` + } + } + : (url, importer) => { + return urlToBuiltUrl(url, importer || id, config, this) + } + + const { code: css, modules, deps } = await compileCSS( + id, + raw, + config, + urlReplacer + ) if (modules) { moduleCache.set(id, modules) } + // dev if (server) { // server only logic for handling CSS @import dependency hmr const { moduleGraph } = server const thisModule = moduleGraph.getModuleById(id)! + // CSS modules cannot self-accept since it exports values const isSelfAccepting = !modules if (deps) { @@ -123,18 +152,8 @@ export function cssPlugin(config: ResolvedConfig): Plugin { } else { thisModule.isSelfAccepting = isSelfAccepting } - // rewrite urls using current module's url as base - css = await rewriteCssUrls(css, thisModule.url) - } else { - // if build, analyze url() asset reference - // account for comments https://github.com/vitejs/vite/issues/426 - css = css.replace(/\/\*[\s\S]*?\*\//gm, '') - if (cssUrlRE.test(css)) { - css = await rewriteCssUrls(css, async (url) => - urlToBuiltUrl(url, id, config, this) - ) - } } + return css } } @@ -304,7 +323,8 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { async function compileCSS( id: string, code: string, - config: ResolvedConfig + config: ResolvedConfig, + urlReplacer: CssUrlReplacer ): Promise<{ code: string map?: SourceMap @@ -317,11 +337,18 @@ async function compileCSS( // although at serve time it can work without processing, we do need to // crawl them in order to register watch dependencies. const needInlineImport = code.includes('@import') + const hasUrl = cssUrlRE.test(code) const postcssConfig = await resolvePostcssConfig(config) const lang = id.match(cssLangRE)?.[1] // 1. plain css that needs no processing - if (lang === 'css' && !postcssConfig && !isModule && !needInlineImport) { + if ( + lang === 'css' && + !postcssConfig && + !isModule && + !needInlineImport && + !hasUrl + ) { return { code } } @@ -377,6 +404,11 @@ async function compileCSS( if (needInlineImport) { postcssPlugins.unshift((await import('postcss-import')).default()) } + postcssPlugins.push( + UrlRewritePostcssPlugin({ + replacer: urlReplacer + }) as PostcssPlugin + ) if (isModule) { postcssPlugins.unshift( @@ -645,22 +677,48 @@ const preProcessors = { stylus: styl } -type Replacer = (url: string) => string | Promise +type CssUrlReplacer = ( + url: string, + importer?: string +) => string | Promise const cssUrlRE = /url\(\s*('[^']+'|"[^"]+"|[^'")]+)\s*\)/ -function rewriteCssUrls( - css: string, - replacerOrBase: string | Replacer -): Promise { - let replacer: Replacer - if (typeof replacerOrBase === 'string') { - replacer = (rawUrl) => { - return path.posix.resolve(path.posix.dirname(replacerOrBase), rawUrl) +const UrlRewritePostcssPlugin: PluginCreator<{ + replacer: CssUrlReplacer +}> = (opts) => { + if (!opts) { + throw new Error('base or replace is required') + } + + return { + postcssPlugin: 'vite-url-rewrite', + Once(root) { + const promises: Promise[] = [] + root.walkDecls((decl) => { + if (cssUrlRE.test(decl.value)) { + const replacerForDecl = (rawUrl: string) => { + const importer = decl.source?.input.file + return opts.replacer(rawUrl, importer) + } + promises.push( + rewriteCssUrls(decl.value, replacerForDecl).then((url) => { + decl.value = url + }) + ) + } + }) + if (promises.length) { + return Promise.all(promises) as any + } } - } else { - replacer = replacerOrBase } +} +UrlRewritePostcssPlugin.postcss = true +function rewriteCssUrls( + css: string, + replacer: CssUrlReplacer +): Promise { return asyncReplace(css, cssUrlRE, async (match) => { let [matched, rawUrl] = match let wrap = '' From 76c4bad142a93ba471ba8b42fe17fc32058f377c Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 11:51:34 -0500 Subject: [PATCH 200/514] release: v2.0.0-beta.37 --- packages/vite/CHANGELOG.md | 21 +++++++++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 9a0cdfcf3e1c7d..a676a312b14fd1 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,24 @@ +# [2.0.0-beta.37](https://github.com/vitejs/vite/compare/v2.0.0-beta.35...v2.0.0-beta.37) (2021-01-22) + + +### Bug Fixes + +* **css:** fix url rewriting in [@imported](https://github.com/imported) css ([52ae44f](https://github.com/vitejs/vite/commit/52ae44fe97b53ce82633268030bb46594f385860)), closes [#1629](https://github.com/vitejs/vite/issues/1629) +* **manifest:** avoid chunks with same name overwriting one another ([cf81aa3](https://github.com/vitejs/vite/commit/cf81aa399b2df1ee8441a1b8922908f4e36358d6)), closes [#1632](https://github.com/vitejs/vite/issues/1632) +* **ssr:** do not inject inlined css in ssr build ([5d77665](https://github.com/vitejs/vite/commit/5d77665def42ffafc699a0006e4527536dfd1114)), closes [#1643](https://github.com/vitejs/vite/issues/1643) +* always reload when html is edited in middleware mode ([85c89be](https://github.com/vitejs/vite/commit/85c89bea9807090d928942a72b972183ebf8483a)) +* handle esm config syntax error in Node 12 ([20cf718](https://github.com/vitejs/vite/commit/20cf718ac77abfce5656ee9836f8c06ddbbc440d)), closes [#1635](https://github.com/vitejs/vite/issues/1635) +* normalize paths for cjs optimized deps on windows ([#1631](https://github.com/vitejs/vite/issues/1631)) ([b462e33](https://github.com/vitejs/vite/commit/b462e33ce3d31df49ada436324a9c32cd5c9053a)) +* still resolve jsnext fields ([4e0cd73](https://github.com/vitejs/vite/commit/4e0cd7384e850e4b7f23b68e5b591bb717650b79)) + + +### Features + +* allow inline postcss config ([6bd2140](https://github.com/vitejs/vite/commit/6bd21402a9e5955433656024f5548f12b12ea2fa)), closes [#1061](https://github.com/vitejs/vite/issues/1061) +* hmr for glob import ([edd2fd9](https://github.com/vitejs/vite/commit/edd2fd9de904a194f25e18136dfe298c7bcbbd8d)) + + + # [2.0.0-beta.36](https://github.com/vitejs/vite/compare/v2.0.0-beta.35...v2.0.0-beta.36) (2021-01-21) diff --git a/packages/vite/package.json b/packages/vite/package.json index 87f1471f615d0f..8b5e19a112d520 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.36", + "version": "2.0.0-beta.37", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 843c87915082b36f7d1ffeb81515b45d5d65aabb Mon Sep 17 00:00:00 2001 From: Kevin Hazy <0x142857@gmail.com> Date: Sat, 23 Jan 2021 04:22:37 +0800 Subject: [PATCH 201/514] fix: exclude spa-fallback middleware in middlewareMode (#1645) --- packages/vite/src/node/server/index.ts | 36 ++++++++++++++------------ 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index b39b59866b1834..129188a4b40d16 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -386,25 +386,27 @@ export async function createServer( middlewares.use(serveStaticMiddleware(root, config)) // spa fallback - middlewares.use( - history({ - logger: createDebugger('vite:spa-fallback'), - // support /dir/ without explicit index.html - rewrites: [ - { - from: /\/$/, - to({ parsedUrl }: any) { - const rewritten = parsedUrl.pathname + 'index.html' - if (fs.existsSync(path.join(root, rewritten))) { - return rewritten - } else { - return `/index.html` + if (!middlewareMode) { + middlewares.use( + history({ + logger: createDebugger('vite:spa-fallback'), + // support /dir/ without explicit index.html + rewrites: [ + { + from: /\/$/, + to({ parsedUrl }: any) { + const rewritten = parsedUrl.pathname + 'index.html' + if (fs.existsSync(path.join(root, rewritten))) { + return rewritten + } else { + return `/index.html` + } } } - } - ] - }) - ) + ] + }) + ) + } // run post config hooks // This is applied before the html middleware so that user middleware can From fa37456584a09b52b39a61760a6d130e261886ff Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 21 Jan 2021 15:51:29 -0500 Subject: [PATCH 202/514] fix: avoid eager hmr api access --- packages/plugin-vue/src/main.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index e59fcfe0c2752f..c5c40279d5827d 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -105,7 +105,8 @@ export async function transformMain( if (devServer && !ssr && !isProduction) { output.push(`_sfc_main.__hmrId = ${JSON.stringify(descriptor.id)}`) output.push( - `__VUE_HMR_RUNTIME__.createRecord(_sfc_main.__hmrId, _sfc_main)` + `typeof __VUE_HMR_RUNTIME__ !== 'undefined' && ` + + `__VUE_HMR_RUNTIME__.createRecord(_sfc_main.__hmrId, _sfc_main)` ) // check if the template is the only thing that changed if (prevDescriptor && isOnlyTemplateChanged(prevDescriptor, descriptor)) { From 6e7f652d89dde43806a2323560486c9b4b771a35 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 15:51:48 -0500 Subject: [PATCH 203/514] feat: esbuild based dep pre-bundling --- .../__tests__/optimize-deps.spec.ts | 4 + packages/playground/optimize-deps/index.html | 11 + packages/vite/package.json | 4 +- packages/vite/src/node/constants.ts | 5 +- .../vite/src/node/optimizer/depAssetPlugin.ts | 86 -------- .../src/node/optimizer/depMetadataPlugin.ts | 38 ---- .../src/node/optimizer/esbuildDepPlugin.ts | 95 ++++++++ packages/vite/src/node/optimizer/index.ts | 204 +++++++++--------- .../vite/src/node/plugins/importAnalysis.ts | 183 ++++++++++------ packages/vite/src/node/plugins/resolve.ts | 14 +- packages/vite/src/node/utils.ts | 5 + packages/vite/types/shims.d.ts | 5 - yarn.lock | 25 +-- 13 files changed, 352 insertions(+), 327 deletions(-) delete mode 100644 packages/vite/src/node/optimizer/depAssetPlugin.ts delete mode 100644 packages/vite/src/node/optimizer/depMetadataPlugin.ts create mode 100644 packages/vite/src/node/optimizer/esbuildDepPlugin.ts diff --git a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts b/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts index 9b65f11e8ffd4a..65d9a04323299f 100644 --- a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts +++ b/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts @@ -30,6 +30,10 @@ test('forced include', async () => { expect(await page.textContent('.force-include')).toMatch(`[success]`) }) +test('import * from optimized dep', async () => { + expect(await page.textContent('.import-star')).toMatch(`[success]`) +}) + test('dep with css import', async () => { expect(await getColor('h1')).toBe('red') }) diff --git a/packages/playground/optimize-deps/index.html b/packages/playground/optimize-deps/index.html index 9b239a1df74395..ade0515ab11010 100644 --- a/packages/playground/optimize-deps/index.html +++ b/packages/playground/optimize-deps/index.html @@ -21,6 +21,9 @@

Detecting linked src package and optimizing its deps (lodash-es)

Optimizing force included dep even when it's linked

+

import * as ...

+
+

Dep w/ special file format supported via plugins

@@ -37,4 +40,12 @@

Dep w/ special file format supported via plugins

import { msg, VueSFC } from 'optimize-deps-linked-include' document.querySelector('.force-include').textContent = msg document.querySelector('.plugin').textContent = VueSFC.render() + + import * as linked from 'optimize-deps-linked-include' + const keys = Object.keys(linked) + if (keys.length) { + document.querySelector('.import-star').textContent = `[success] ${keys.join( + ', ' + )}` + } diff --git a/packages/vite/package.json b/packages/vite/package.json index 8b5e19a112d520..b6f648cd892c9f 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -44,7 +44,7 @@ }, "//": "READ .github/contributing.md to understand what to put under deps vs. devDeps!", "dependencies": { - "esbuild": "^0.8.26", + "esbuild": "^0.8.34", "postcss": "^8.2.1", "resolve": "^1.19.0", "rollup": "^2.35.1" @@ -76,6 +76,7 @@ "acorn-numeric-separator": "^0.3.6", "acorn-static-class-features": "^0.2.4", "brotli-size": "^4.0.0", + "builtin-modules": "^3.2.0", "cac": "^6.6.1", "chalk": "^4.1.0", "chokidar": "^3.4.3", @@ -94,7 +95,6 @@ "execa": "^5.0.0", "fast-glob": "^3.2.4", "http-proxy": "^1.18.1", - "isbuiltin": "^1.0.0", "launch-editor-middleware": "^2.2.1", "magic-string": "^0.25.7", "merge-source-map": "^1.1.0", diff --git a/packages/vite/src/node/constants.ts b/packages/vite/src/node/constants.ts index 6a51c407613a97..1e54f696466631 100644 --- a/packages/vite/src/node/constants.ts +++ b/packages/vite/src/node/constants.ts @@ -13,6 +13,9 @@ export const FS_PREFIX = `/@fs/` * Prefix for resolved Ids that are not valid browser import specifiers */ export const VALID_ID_PREFIX = `/@id/` + +export const OPTIMIZED_PREFIX = `/@optimized/` + /** * Some Rollup plugins use ids that starts with the null byte \0 to avoid * collisions, but it is not permitted in import URLs so we have to replace @@ -25,7 +28,7 @@ export const CLIENT_PUBLIC_PATH = `/@vite/client` export const CLIENT_ENTRY = require.resolve('vite/dist/client/client.js') export const CLIENT_DIR = path.dirname(CLIENT_ENTRY) -const knownAssetTypes = [ +export const knownAssetTypes = [ // images 'png', 'jpe?g', diff --git a/packages/vite/src/node/optimizer/depAssetPlugin.ts b/packages/vite/src/node/optimizer/depAssetPlugin.ts deleted file mode 100644 index 9f92ea6718694a..00000000000000 --- a/packages/vite/src/node/optimizer/depAssetPlugin.ts +++ /dev/null @@ -1,86 +0,0 @@ -import path from 'path' -import { Plugin } from 'rollup' -import { init, parse } from 'es-module-lexer' -import { isCSSRequest } from '../plugins/css' -import MagicString from 'magic-string' -import { normalizePath } from '../utils' -import { ResolvedConfig } from '../config' -import { idToPkgMap } from '../plugins/resolve' - -export const REQUIRE_SUFFIX = '?commonjs-require' - -export const depAssetExternalPlugin = (config: ResolvedConfig): Plugin => ({ - name: 'vite:dep-assets-external', - resolveId(id) { - if (isCSSRequest(id) || config.assetsInclude(id)) { - return { - id, - external: true - } - } - } -}) - -export const depAssetRewritePlugin = (config: ResolvedConfig): Plugin => { - return { - name: 'vite:dep-assets-rewrite', - async transform(code, id) { - if (id.endsWith('.js')) { - await init - const [imports] = parse(code) - if (imports.length) { - let s: MagicString | undefined - for (let i = 0; i < imports.length; i++) { - const { - s: start, - e: end, - d: dynamicIndex, - ss: statementStart, - se: statementEnd - } = imports[i] - if (dynamicIndex === -1) { - const importee = code.slice(start, end) - if (isCSSRequest(importee) || config.assetsInclude(importee)) { - // replace css/asset imports to deep imports to their original - // location - s = s || new MagicString(code) - // #903 rollup-plugin-commonjs will inject proxy helper, - // it is unnecessary for assets - if (importee.endsWith('?commonjs-proxy')) { - s.remove(statementStart, statementEnd) - continue - } - // rollup-plugin-commonjs will inject require suffix for require call - if (importee.endsWith(REQUIRE_SUFFIX)) { - s.overwrite( - start, - end, - importee.slice(1, -REQUIRE_SUFFIX.length) - ) - continue - } - if (importee.startsWith('.')) { - const pkg = idToPkgMap.get(id) - if (pkg) { - const fsPath = path.resolve(path.dirname(id), importee) - const deepPath = - pkg.data.name + - '/' + - normalizePath(path.relative(pkg.dir, fsPath)) - s.overwrite(start, end, deepPath) - } - } - } - } else { - // ignore dynamic import - } - } - if (s) { - return s.toString() - } - } - } - return null - } - } -} diff --git a/packages/vite/src/node/optimizer/depMetadataPlugin.ts b/packages/vite/src/node/optimizer/depMetadataPlugin.ts deleted file mode 100644 index af0919d0a828c4..00000000000000 --- a/packages/vite/src/node/optimizer/depMetadataPlugin.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Plugin } from 'rollup' -import { DepOptimizationMetadata } from '.' - -const moduleIdRE = /node_modules\/([^@.][^/]*|@[^/]+\/[^/]+)\// - -export function recordCjsEntryPlugin(data: DepOptimizationMetadata): Plugin { - return { - name: 'vite:cjs-entry-named-export', - async generateBundle(_, bundle) { - Object.values(bundle).forEach((chunk) => { - if (chunk.type === 'chunk') { - if (chunk.isEntry) { - data.optimized[chunk.name] = chunk.fileName - if (chunk.facadeModuleId) { - const facadeInfo = this.getModuleInfo(chunk.facadeModuleId) - // this info is exposed by rollup commonjs plugin - if (facadeInfo?.meta?.commonjs?.isCommonJS) { - data.cjsEntries[chunk.fileName] = true - } - } - } - for (const id in chunk.modules) { - const depId = id.match(moduleIdRE)?.[1] - if (depId) { - data.transitiveOptimized[depId] = true - } - } - } - }) - - for (const key in data.transitiveOptimized) { - if (key in data.optimized) { - delete data.transitiveOptimized[key] - } - } - } - } -} diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts new file mode 100644 index 00000000000000..c8092b2aacd31a --- /dev/null +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -0,0 +1,95 @@ +import path from 'path' +import { Plugin } from 'esbuild' +import { knownAssetTypes } from '../constants' +import builtins from 'builtin-modules' +import { ResolvedConfig } from '..' +import chalk from 'chalk' +import { deepImportRE } from '../utils' + +const externalTypes = ['css', 'vue', 'svelte', ...knownAssetTypes] + +export function esbuildDepPlugin( + qualified: Record, + config: ResolvedConfig, + transitiveOptimized: Record +): Plugin { + return { + name: 'vite:dep-pre-bundle', + setup(build) { + // externalize assets and commonly known non-js file types + build.onResolve( + { + filter: new RegExp(`\\.(` + externalTypes.join('|') + `)(\\?.*)?$`) + }, + ({ path: _path, importer }) => { + if (_path.startsWith('.')) { + const dir = path.dirname(importer) + return { + path: path.resolve(dir, _path), + external: true + } + } + } + ) + + // record transitive deps + build.onResolve({ filter: /^[\w@]/ }, ({ path: id }) => { + if (!(id in qualified) && !/:\/\//.test(id)) { + const deepMatch = id.match(deepImportRE) + const pkgId = deepMatch ? deepMatch[1] || deepMatch[2] : id + transitiveOptimized[pkgId] = true + } + return null + }) + + // redirect node-builtins to empty module for browser + build.onResolve( + { + filter: new RegExp(`^(${builtins.join('|')})$`) + }, + ({ path: id, importer }) => { + config.logger.warn( + chalk.yellow( + `externalized node built-in "${id}" to empty module. ` + + `(imported by: ${chalk.white.dim(importer)})` + ) + ) + return { + path: id, + namespace: 'browser-external' + } + } + ) + + build.onLoad( + { filter: /.*/, namespace: 'browser-external' }, + ({ path: id }) => { + return { + contents: + `export default new Proxy({}, { + get() { + throw new Error('Module "${id}" has been externalized for ` + + `browser compatibility and cannot be accessed in client code.') + } +})` + } + } + ) + + if (config.dedupe) { + build.onResolve( + { + filter: new RegExp(`^(${config.dedupe.join('|')})$`) + }, + ({ path: id }) => { + if (id in qualified) { + return { + path: path.resolve(qualified[id]) + } + } + } + ) + } + } + } +} diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 4c393a69f90023..25564bc92de1ee 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -1,33 +1,29 @@ import fs from 'fs' import path from 'path' import chalk from 'chalk' -import Rollup from 'rollup' import { createHash } from 'crypto' -import { ResolvedConfig, sortUserPlugins } from '../config' +import { ResolvedConfig } from '../config' import { SUPPORTED_EXTS } from '../constants' -import { init, parse } from 'es-module-lexer' -import { onRollupWarning, resolveExternal } from '../build' import { createDebugger, emptyDir, lookupFile, + normalizePath, resolveFrom, writeFile } from '../utils' -import { depAssetExternalPlugin, depAssetRewritePlugin } from './depAssetPlugin' -import { recordCjsEntryPlugin } from './depMetadataPlugin' import { createPluginContainer, PluginContainer } from '../server/pluginContainer' -import { resolvePlugin, tryNodeResolve } from '../plugins/resolve' +import { tryNodeResolve } from '../plugins/resolve' import aliasPlugin from '@rollup/plugin-alias' -import commonjsPlugin from '@rollup/plugin-commonjs' -import jsonPlugin from '@rollup/plugin-json' -import { buildDefinePlugin } from '../plugins/define' -import { createFilter } from '@rollup/pluginutils' +import { createFilter, makeLegalIdentifier } from '@rollup/pluginutils' import { Plugin } from '../plugin' import { prompt } from 'enquirer' +import { build } from 'esbuild' +import { esbuildDepPlugin } from './esbuildDepPlugin' +import { init, parse } from 'es-module-lexer' const debug = createDebugger('vite:optimize') @@ -71,16 +67,14 @@ export interface DepOptimizationOptions { auto?: boolean /** * A list of linked dependencies that should be treated as source code. - * @deprecated local linked deps are auto detected in Vite 2. */ link?: string[] } export interface DepOptimizationMetadata { hash: string - optimized: Record + optimized: Record transitiveOptimized: Record - cjsEntries: Record dependencies: Record } @@ -89,6 +83,8 @@ export async function optimizeDeps( force = config.server.force, asCommand = false ) { + await init + config = { ...config, command: 'build' @@ -110,7 +106,6 @@ export async function optimizeDeps( hash: getDepHash(root, pkg, config), optimized: {}, transitiveOptimized: {}, - cjsEntries: {}, dependencies: pkg.dependencies } @@ -139,7 +134,7 @@ export async function optimizeDeps( // 1. Has imports to relative files (e.g. lodash-es, lit-html) // 2. Has imports to bare modules that are not in the project's own deps // (i.e. esm that imports its own dependencies, e.g. styled-components) - await init + // await init const aliasResolver = await createPluginContainer({ ...config, plugins: [aliasPlugin({ entries: config.alias })] @@ -236,69 +231,32 @@ export async function optimizeDeps( logger.info(chalk.greenBright(`Optimizing dependencies:\n${depsString}`)) } - const [pre, normal, post] = sortUserPlugins(options.plugins) - const resolvedExternal = resolveExternal( - external, - config.build.rollupOptions?.external - ) - - try { - const rollup = require('rollup') as typeof Rollup - const bundle = await rollup.rollup({ - input: qualified, - external: resolvedExternal, - onwarn(warning, warn) { - onRollupWarning(warning, warn, config) - }, - plugins: [ - aliasPlugin({ entries: config.alias }), - ...pre, - depAssetExternalPlugin(config), - resolvePlugin( - { - root: config.root, - dedupe: config.dedupe, - isBuild: true, - asSrc: false - }, - config - ), - jsonPlugin({ - preferConst: true, - namedExports: true - }), - ...normal, - commonjsPlugin(config.build.commonjsOptions), - buildDefinePlugin(config), - depAssetRewritePlugin(config), - recordCjsEntryPlugin(data), - ...post - ] - }) - - const { output } = await bundle.generate({ - format: 'es', - exports: 'named', - entryFileNames: '[name].[hash].js', - chunkFileNames: 'common/[name].[hash].js' - }) - - for (const chunk of output) { - if (chunk.type === 'chunk') { - writeFile(path.join(cacheDir, chunk.fileName), chunk.code) - } - } - writeFile(dataPath, JSON.stringify(data, null, 2)) - } catch (e) { - delete e.watchFiles - logger.error(chalk.red(`\nDep optimization failed with error:`)) - if (e.code === 'PARSE_ERROR') { - e.message += `\n\n${chalk.cyan( - path.relative(root, e.loc.file) - )}\n${chalk.dim(e.frame)}` - } - throw e + for (const id in qualified) { + data.optimized[id] = await parseExports( + qualified[id], + config, + aliasResolver + ) } + + // construct a entry containing all the deps + const tempEntry = buildTempEntry(qualified, data.optimized, cacheDir) + const tempEntryPath = path.resolve(path.join(cacheDir, 'depsEntry.js')) + fs.writeFileSync(tempEntryPath, tempEntry) + + await build({ + entryPoints: [tempEntryPath], + bundle: true, + format: 'esm', + outfile: path.join(cacheDir, 'deps.js'), + define: { + 'process.env.NODE_ENV': '"development"' + }, + plugins: [esbuildDepPlugin(qualified, config, data.transitiveOptimized)] + }) + + fs.unlinkSync(tempEntryPath) + writeFile(dataPath, JSON.stringify(data, null, 2)) } interface FilteredDeps { @@ -371,28 +329,8 @@ async function resolveQualifiedDeps( debug(`skipping ${id} (entry is not js)`) continue } - const content = fs.readFileSync(filePath, 'utf-8') - const [imports, exports] = parse(content) - if (!exports.length && !/export\s+\*\s+from/.test(content)) { - debug(`optimizing ${id} (no exports, likely commonjs)`) - qualified[id] = filePath - continue - } - for (const { s, e } of imports) { - let i = content.slice(s, e).trim() - i = (await aliasResolver.resolveId(i))?.id || i - if (i.startsWith('.')) { - debug(`optimizing ${id} (contains relative imports)`) - qualified[id] = filePath - break - } - if (!deps.includes(i)) { - debug(`optimizing ${id} (imports sub dependencies)`) - qualified[id] = filePath - break - } - } - debug(`skipping ${id} (single esm file, doesn't need optimization)`) + // qualified! + qualified[id] = filePath } // mark non-optimized deps as external @@ -496,3 +434,69 @@ function getDepHash( ) return createHash('sha256').update(content).digest('hex').substr(0, 8) } + +function buildTempEntry( + qualified: Record, + idToExports: DepOptimizationMetadata['optimized'], + basedir: string +) { + let res = '' + for (const id in qualified) { + const validId = makeLegalIdentifier(id) + const exports = idToExports[id] + const entry = normalizePath(path.relative(basedir, qualified[id])) + if (!exports.length) { + // cjs or umd - provide rollup-style compat + // by exposing both the default and named properties + res += `import ${validId}_default from "${entry}"\n` + res += `import * as ${validId}_all from "${entry}"\n` + res += `const ${validId} = { ...${validId}_all, default: ${validId}_default }\n` + res += `export { ${validId} }\n` + } else { + res += `export { ${exports + .map((e) => `${e} as ${validId}_${e}`) + .join(', ')} } from "${entry}"\n` + } + } + return res +} + +async function parseExports( + entry: string, + config: ResolvedConfig, + aliasResolver: PluginContainer +) { + const content = fs.readFileSync(entry, 'utf-8') + const [imports, exports] = parse(content) + + // check for export * from statements + for (const { + s: start, + e: end, + ss: expStart, + se: expEnd, + d: dynamicIndex + } of imports) { + if (dynamicIndex < 0) { + const exp = content.slice(expStart, expEnd) + if (exp.startsWith(`export * from`)) { + const id = content.slice(start, end) + const aliased = (await aliasResolver.resolveId(id))?.id || id + const filePath = tryNodeResolve( + aliased, + config.root, + config.isProduction + )?.id + if (filePath) { + const childExports = await parseExports( + filePath, + config, + aliasResolver + ) + exports.push(...childExports) + } + } + } + } + return exports +} diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 6ef3e423da7e83..3be1c157c5eace 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -7,6 +7,7 @@ import MagicString from 'magic-string' import { init, parse as parseImports, ImportSpecifier } from 'es-module-lexer' import { isCSSRequest, isDirectCSSRequest } from './css' import { + isBuiltin, cleanUrl, createDebugger, generateCodeFrame, @@ -29,15 +30,15 @@ import { CLIENT_PUBLIC_PATH, DEP_VERSION_RE, VALID_ID_PREFIX, - NULL_BYTE_PLACEHOLDER + NULL_BYTE_PLACEHOLDER, + OPTIMIZED_PREFIX } from '../constants' import { ViteDevServer } from '..' import { checkPublicFile } from './asset' import { parse as parseJS } from 'acorn' -import type { Node } from 'estree' +import type { ImportDeclaration, Node } from 'estree' import { makeLegalIdentifier } from '@rollup/pluginutils' import { transformImportGlob } from '../importGlob' -import isBuiltin from 'isbuiltin' const isDebug = !!process.env.DEBUG const debugRewrite = createDebugger('vite:rewrite') @@ -85,6 +86,7 @@ function markExplicitImport(url: string) { */ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { let server: ViteDevServer + let optimizedSource: string | undefined return { name: 'vite:import-analysis', @@ -347,7 +349,14 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { if (url !== rawUrl) { // for optimized cjs deps, support named imports by rewriting named // imports to const assignments. - if (isOptimizedCjs(resolvedId, server)) { + if (url.startsWith(OPTIMIZED_PREFIX)) { + const depId = resolvedId.slice(OPTIMIZED_PREFIX.length) + const optimizedId = makeLegalIdentifier(depId) + optimizedSource = + optimizedSource || + normalizePath(path.join(config.optimizeCacheDir!, 'deps.js')) + + `?v=${server._optimizeDepsMetadata!.hash}` + if (isLiteralDynamicId) { // rewrite `import('package')` to expose module.exports // note plugin-commonjs' behavior is exposing all properties on @@ -355,11 +364,18 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { str().overwrite( dynamicIndex, end + 1, - `import('${url}').then(m => ({ ...m.default, default: m.default }))` + `import('${optimizedSource}').then(m => m.${optimizedId})` ) } else { const exp = source.slice(expStart, expEnd) - const rewritten = transformCjsImport(exp, url, rawUrl, index) + const rewritten = transformOptimizedImport( + exp, + optimizedSource, + optimizedId, + index, + depId, + server._optimizeDepsMetadata!.optimized[depId] + ) if (rewritten) { str().overwrite(expStart, expEnd, rewritten) } else { @@ -485,81 +501,106 @@ function isSupportedDynamicImport(url: string) { return true } -function isOptimizedCjs( - id: string, - { - _optimizeDepsMetadata: optimizeDepsMetadata, - config: { optimizeCacheDir } - }: ViteDevServer -): boolean { - if (optimizeDepsMetadata && optimizeCacheDir) { - const relative = normalizePath( - path.relative(optimizeCacheDir, cleanUrl(id)) - ) - return relative in optimizeDepsMetadata.cjsEntries - } - return false -} - -type ImportNameSpecifier = { importedName: string; localName: string } - -/** - * Detect import statements to a known optimized CJS dependency and provide - * ES named imports interop. We do this by rewriting named imports to a variable - * assignment to the corresponding property on the `module.exports` of the cjs - * module. Note this doesn't support dynamic re-assignments from within the cjs - * module. - * - * Note that es-module-lexer treats `export * from '...'` as an import as well, - * so, we may encounter ExportAllDeclaration here, in which case `undefined` - * will be returned. - * - * Credits \@csr632 via #837 - */ -function transformCjsImport( +function transformOptimizedImport( importExp: string, - url: string, - rawUrl: string, - importIndex: number + optimizedSource: string, + optimizedId: string, + importIndex: number, + id: string, + exports: string[] ): string | undefined { const node = (parseJS(importExp, { ecmaVersion: 2020, sourceType: 'module' }) as any).body[0] as Node - if (node.type === 'ImportDeclaration') { - const importNames: ImportNameSpecifier[] = [] - for (const spec of node.specifiers) { - if ( - spec.type === 'ImportSpecifier' && - spec.imported.type === 'Identifier' - ) { - const importedName = spec.imported.name - const localName = spec.local.name - importNames.push({ importedName, localName }) - } else if (spec.type === 'ImportDefaultSpecifier') { - importNames.push({ - importedName: 'default', - localName: spec.local.name - }) - } else if (spec.type === 'ImportNamespaceSpecifier') { - importNames.push({ importedName: '*', localName: spec.local.name }) - } - } - + const lines: string[] = [] + if (!exports.length) { + // optimized cjs dep. import then assign. + // Credits \@csr632 via #837 // If there is multiple import for same id in one file, // importIndex will prevent the cjsModuleName to be duplicate - const cjsModuleName = makeLegalIdentifier( - `__vite__cjsImport${importIndex}_${rawUrl}` + const moduleName = `__vite__${optimizedId}_${importIndex}` + lines.push( + `import { ${optimizedId} as ${moduleName} } from "${optimizedSource}";` ) - const lines: string[] = [`import ${cjsModuleName} from "${url}";`] - importNames.forEach(({ importedName, localName }) => { - if (importedName === '*' || importedName === 'default') { - lines.push(`const ${localName} = ${cjsModuleName};`) - } else { - lines.push(`const ${localName} = ${cjsModuleName}["${importedName}"];`) + if (node.type === 'ImportDeclaration') { + getImportNamePairs(node, id, exports).forEach( + ({ importedName, localName }) => { + if (importedName === '*' || importedName === 'default') { + lines.push(`const ${localName} = ${moduleName}.default`) + } else { + lines.push(`const ${localName} = ${moduleName}["${importedName}"]`) + } + } + ) + } else if (node.type === 'ExportAllDeclaration') { + const namedExports = exports.filter((e) => e !== 'default') + lines.push(`const { ${namedExports.join(', ')} } = ${moduleName}`) + lines.push(`export { ${namedExports.join(', ')} }`) + } + } else { + const namedExports = exports.filter((e) => e !== 'default') + // optimized esm dep + if (node.type === 'ImportDeclaration') { + getImportNamePairs(node, id, exports).forEach( + ({ importedName, localName }) => { + if (importedName === '*') { + lines.push( + `import { ${namedExports + .map( + (e) => `${optimizedId}_${e} as __vite__${optimizedId}_${e}` + ) + .join(', ')} } from "${optimizedSource}"`, + `const ${localName} = Object.freeze({ ${namedExports + .map((e) => `${e}: __vite__${optimizedId}_${e}`) + .join(',')} })` + ) + } else { + lines.push( + `import { ${optimizedId}_${importedName} as ${localName} } from "${optimizedSource}"` + ) + } + } + ) + } else if (node.type === 'ExportAllDeclaration') { + lines.push( + `export { ${namedExports + .map((e) => `${optimizedId}_${e} as ${e}`) + .join(', ')} } from "${optimizedSource}"` + ) + } + } + return lines.join('\n') +} + +type ImportNameSpecifier = { importedName: string; localName: string } + +function getImportNamePairs( + node: ImportDeclaration, + id: string, + exports: string[] +): ImportNameSpecifier[] { + const importNames: ImportNameSpecifier[] = [] + for (const spec of node.specifiers) { + if ( + spec.type === 'ImportSpecifier' && + spec.imported.type === 'Identifier' + ) { + const importedName = spec.imported.name + const localName = spec.local.name + importNames.push({ importedName, localName }) + } else if (spec.type === 'ImportDefaultSpecifier') { + if (exports.length && !exports.includes('default')) { + throw new Error(`Module "${id}" has no default export.`) } - }) - return lines.join('\n') + importNames.push({ + importedName: 'default', + localName: spec.local.name + }) + } else if (spec.type === 'ImportNamespaceSpecifier') { + importNames.push({ importedName: '*', localName: spec.local.name }) + } } + return importNames } diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index e48ad1a7a95266..d2a1c93b77859a 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -2,8 +2,9 @@ import fs from 'fs' import path from 'path' import { Plugin } from '../plugin' import chalk from 'chalk' -import { FS_PREFIX, SUPPORTED_EXTS } from '../constants' +import { FS_PREFIX, OPTIMIZED_PREFIX, SUPPORTED_EXTS } from '../constants' import { + isBuiltin, bareImportRE, createDebugger, deepImportRE, @@ -21,7 +22,6 @@ import { ResolvedConfig, ViteDevServer } from '..' import slash from 'slash' import { createFilter } from '@rollup/pluginutils' import { PartialResolvedId } from 'rollup' -import isBuiltin from 'isbuiltin' import { isCSSRequest } from './css' import { resolve as _resolveExports } from 'resolve.exports' @@ -364,17 +364,15 @@ export function tryNodeResolve( } export function tryOptimizedResolve( - rawId: string, + id: string, server: ViteDevServer ): string | undefined { const cacheDir = server.config.optimizeCacheDir const depData = server._optimizeDepsMetadata if (cacheDir && depData) { - const [id, q] = rawId.split(`?`, 2) - const query = q ? `?${q}` : `` - const filePath = depData.optimized[id] - if (filePath) { - return normalizePath(path.resolve(cacheDir, filePath)) + query + const isOptimized = depData.optimized[cleanUrl(id)] + if (isOptimized) { + return `${OPTIMIZED_PREFIX}${id}` } } } diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 5d290a9cc1e94b..958f73397596f0 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -7,6 +7,11 @@ import { parse as parseUrl } from 'url' import slash from 'slash' import { FS_PREFIX, SUPPORTED_EXTS } from './constants' import resolve from 'resolve' +import builtins from 'builtin-modules' + +export function isBuiltin(id: string): boolean { + return builtins.includes(id) +} export const bareImportRE = /^[\w@](?!.*:\/\/)/ export const deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\// diff --git a/packages/vite/types/shims.d.ts b/packages/vite/types/shims.d.ts index 15952f07ecb3a0..e3533845957fa7 100644 --- a/packages/vite/types/shims.d.ts +++ b/packages/vite/types/shims.d.ts @@ -98,11 +98,6 @@ declare module 'rollup-plugin-web-worker-loader' { export default p } -declare module 'isbuiltin' { - function isBuiltin(moduleName: string): boolean - export default isBuiltin -} - declare module 'minimatch' { function match(path: string, pattern: string): boolean export default match diff --git a/yarn.lock b/yarn.lock index d25bd0c8fa5810..5dbc0e97b05d90 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1812,16 +1812,16 @@ buffer@^5.5.0: base64-js "^1.3.1" ieee754 "^1.1.13" -builtin-modules@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" - integrity sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8= - builtin-modules@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.1.0.tgz#aad97c15131eb76b65b50ef208e7584cd76a7484" integrity sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw== +builtin-modules@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.2.0.tgz#45d5db99e7ee5e6bc4f362e008bf917ab5049887" + integrity sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA== + bytes@3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048" @@ -2817,10 +2817,10 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" -esbuild@^0.8.26: - version "0.8.26" - resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.26.tgz#a85491617ebd2bd35ca4bf479239487eb6819d71" - integrity sha512-u3MMHOOumdWoAKF+073GHPpzvVB2cM+y9VD4ZwYs1FAQ6atRPISya35dbrbOu/mM68mQ42P+nwPzQVBTfQhkvQ== +esbuild@^0.8.34: + version "0.8.34" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.34.tgz#16b4ac58f74c821d2c5a8c2f0585ca96a38ab4e6" + integrity sha512-tnr0V1ooakYr1aRLXQLzCn2GVG1kBTW3FWpRyC+NgrR3ntsouVpJOlTOV0BS4YLATx3/c+x3h/uBq9lWJlUAtQ== escape-html@^1.0.3, escape-html@~1.0.3: version "1.0.3" @@ -4193,13 +4193,6 @@ isarray@1.0.0, isarray@~1.0.0: resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= -isbuiltin@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/isbuiltin/-/isbuiltin-1.0.0.tgz#4453b2915690cb47c0cb9c9255a0807778315c96" - integrity sha1-RFOykVaQy0fAy5ySVaCAd3gxXJY= - dependencies: - builtin-modules "^1.1.1" - isexe@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" From 809d4bd3bf62d3bc6b35f182178922d2ab2175f1 Mon Sep 17 00:00:00 2001 From: bompus Date: Fri, 22 Jan 2021 15:45:51 -0700 Subject: [PATCH 204/514] feat: support `base` option during dev, deprecate `build.base` (#1556) --- docs/config/index.md | 14 +- docs/guide/build.md | 2 +- docs/guide/env-and-mode.md | 2 +- .../assets/__tests__/assets.spec.ts | 30 +++- packages/playground/assets/vite.config.js | 2 +- packages/plugin-legacy/index.js | 6 +- packages/plugin-vue/src/template.ts | 4 +- packages/vite/src/client/client.ts | 11 +- packages/vite/src/node/build.ts | 14 +- packages/vite/src/node/cli.ts | 7 +- packages/vite/src/node/config.ts | 65 ++++++++- packages/vite/src/node/logger.ts | 7 +- packages/vite/src/node/plugins/asset.ts | 26 ++-- .../vite/src/node/plugins/clientInjections.ts | 1 + packages/vite/src/node/plugins/css.ts | 23 +-- .../src/node/plugins/dynamicImportPolyfill.ts | 2 +- packages/vite/src/node/plugins/html.ts | 137 ++++++++++-------- .../vite/src/node/plugins/importAnalysis.ts | 18 ++- .../src/node/plugins/importAnaysisBuild.ts | 4 +- packages/vite/src/node/plugins/index.ts | 4 +- packages/vite/src/node/server/index.ts | 27 ++-- .../vite/src/node/server/middlewares/base.ts | 29 ++++ .../src/node/server/middlewares/indexHtml.ts | 93 +++++++++--- .../vite/src/node/ssr/ssrManifestPlugin.ts | 2 +- scripts/jestPerTestSetup.ts | 7 +- 25 files changed, 384 insertions(+), 153 deletions(-) create mode 100644 packages/vite/src/node/server/middlewares/base.ts diff --git a/docs/config/index.md b/docs/config/index.md index 89ba6508cc1e15..c614f0298712ea 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -98,6 +98,13 @@ export default ({ command, mode }) => { See [Project Root](/guide/#project-root) for more details. +### base + +- **Type:** `string` +- **Default:** `/` + + Base public path when served in development or production. Note the path should start and end with `/`. See [Public Base Path](/guide/build#public-base-path) for more details. + ### mode - **Type:** `string` @@ -322,13 +329,6 @@ export default ({ command, mode }) => { ## Build Options -### build.base - -- **Type:** `string` -- **Default:** `/` - - Base public path when served in production. Note the path should start and end with `/`. See [Public Base Path](/guide/build#public-base-path) for more details. - ### build.target - **Type:** `string` diff --git a/docs/guide/build.md b/docs/guide/build.md index aefd258bf6b490..e3ac5e31be1b1e 100644 --- a/docs/guide/build.md +++ b/docs/guide/build.md @@ -23,7 +23,7 @@ Legacy browsers can be supported via [@vitejs/plugin-legacy](https://github.com/ - Related: [Asset Handling](./features#asset-handling) -If you are deploying your project under a nested public path, simply specify the [`build.base` config option](/config/#build-base) and all asset paths will be rewritten accordingly. This option can also be specified as a command line flag, e.g. `vite build --base=/my/public/path/`. +If you are deploying your project under a nested public path, simply specify the [`base` config option](/config/#base) and all asset paths will be rewritten accordingly. This option can also be specified as a command line flag, e.g. `vite build --base=/my/public/path/`. JS-imported asset URLs, CSS `url()` references, and asset references in your `.html` files are all automatically adjusted to respect this option during build. diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md index b2d54d83f16900..9180e552cc0637 100644 --- a/docs/guide/env-and-mode.md +++ b/docs/guide/env-and-mode.md @@ -6,7 +6,7 @@ Vite exposes env variables on the special **`import.meta.env`** object. Some bui - **`import.meta.env.MODE`**: {string} the [mode](#modes) the app is running in. -- **`import.meta.env.BASE_URL`**: {string} the base url the app is being served from. In development, this is always `/`. In production, this is determined by the [`build.base` config option](/config/#build-base). +- **`import.meta.env.BASE_URL`**: {string} the base url the app is being served from. This is determined by the [`base` config option](/config/#base). - **`import.meta.env.PROD`**: {boolean} whether the app is running in production. diff --git a/packages/playground/assets/__tests__/assets.spec.ts b/packages/playground/assets/__tests__/assets.spec.ts index eae3552fbb7101..0164d12d15b8ee 100644 --- a/packages/playground/assets/__tests__/assets.spec.ts +++ b/packages/playground/assets/__tests__/assets.spec.ts @@ -10,9 +10,9 @@ import { const assetMatch = isBuild ? /\/foo\/assets\/asset\.\w{8}\.png/ - : '/nested/asset.png' + : '/foo/nested/asset.png' -const iconMatch = isBuild ? `/foo/icon.png` : `icon.png` +const iconMatch = `/foo/icon.png` test('should have no 404s', () => { browserLogs.forEach((msg) => { @@ -20,6 +20,30 @@ test('should have no 404s', () => { }) }) +describe('injected scripts', () => { + test('@vite/client', async () => { + const hasClient = await page.$( + 'script[type="module"][src="/foo/@vite/client"]' + ) + if (isBuild) { + expect(hasClient).toBeFalsy() + } else { + expect(hasClient).toBeTruthy() + } + }) + + test('html-proxy', async () => { + const hasHtmlProxy = await page.$( + 'script[type="module"][src="/foo/index.html?html-proxy&index=0.js"]' + ) + if (isBuild) { + expect(hasHtmlProxy).toBeFalsy() + } else { + expect(hasHtmlProxy).toBeTruthy() + } + }) +}) + describe('raw references from /public', () => { test('load raw js from /public', async () => { expect(await page.textContent('.raw-js')).toMatch('[success]') @@ -70,7 +94,7 @@ describe('css url() references', () => { }) test('base64 inline', async () => { - const match = isBuild ? `data:image/png;base64` : `/icon.png` + const match = isBuild ? `data:image/png;base64` : `/foo/nested/icon.png` expect(await getBg('.css-url-base64-inline')).toMatch(match) expect(await getBg('.css-url-quotes-base64-inline')).toMatch(match) }) diff --git a/packages/playground/assets/vite.config.js b/packages/playground/assets/vite.config.js index 875c0cff93b254..9bfd9ac261a6c0 100644 --- a/packages/playground/assets/vite.config.js +++ b/packages/playground/assets/vite.config.js @@ -2,8 +2,8 @@ * @type {import('vite').UserConfig} */ module.exports = { + base: '/foo/', build: { - base: '/foo/', outDir: 'dist/foo' } } diff --git a/packages/plugin-legacy/index.js b/packages/plugin-legacy/index.js index 77f840cc811e99..4a3c90a47c4f2e 100644 --- a/packages/plugin-legacy/index.js +++ b/packages/plugin-legacy/index.js @@ -265,7 +265,7 @@ function viteLegacyPlugin(options = {}) { tag: 'script', attrs: { type: 'module', - src: `${config.build.base}${modernPolyfillFilename}` + src: `${config.base}${modernPolyfillFilename}` } }) } else if (modernPolyfills.size) { @@ -295,7 +295,7 @@ function viteLegacyPlugin(options = {}) { tag: 'script', attrs: { nomodule: true, - src: `${config.build.base}${legacyPolyfillFilename}` + src: `${config.base}${legacyPolyfillFilename}` }, injectTo: 'body' }) @@ -318,7 +318,7 @@ function viteLegacyPlugin(options = {}) { // script content will stay consistent - which allows using a constant // hash value for CSP. id: legacyEntryId, - 'data-src': config.build.base + legacyEntryFilename + 'data-src': config.base + legacyEntryFilename }, children: systemJSInlineCode, injectTo: 'body' diff --git a/packages/plugin-vue/src/template.ts b/packages/plugin-vue/src/template.ts index c7219284223649..0abe1dd0109c82 100644 --- a/packages/plugin-vue/src/template.ts +++ b/packages/plugin-vue/src/template.ts @@ -108,7 +108,9 @@ export function resolveTemplateCompilerOptions( // request if (filename.startsWith(options.root)) { assetUrlOptions = { - base: '/' + slash(path.relative(options.root, path.dirname(filename))) + base: + options.devServer.config.base + + slash(path.relative(options.root, path.dirname(filename))) } } } else { diff --git a/packages/vite/src/client/client.ts b/packages/vite/src/client/client.ts index 949145a2103d0b..6af2ff8875792f 100644 --- a/packages/vite/src/client/client.ts +++ b/packages/vite/src/client/client.ts @@ -3,6 +3,7 @@ import { ErrorOverlay, overlayId } from './overlay' // injected by the hmr plugin when served declare const __ROOT__: string +declare const __BASE__: string declare const __MODE__: string declare const __DEFINES__: Record declare const __HMR_PROTOCOL__: string @@ -38,6 +39,8 @@ const socketProtocol = __HMR_PROTOCOL__ || (location.protocol === 'https:' ? 'wss' : 'ws') const socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__}` const socket = new WebSocket(`${socketProtocol}://${socketHost}`, 'vite-hmr') +const base = __BASE__ || '/' +const baseNoSlash = base.replace(/\/$/, '') function warnFailedFetch(err: Error, path: string | string[]) { if (!err.message.match('fetch')) { @@ -107,9 +110,10 @@ async function handleMessage(payload: HMRPayload) { // if html file is edited, only reload the page if the browser is // currently on that page. const pagePath = location.pathname + const payloadPath = baseNoSlash + payload.path if ( - pagePath === payload.path || - (pagePath.endsWith('/') && pagePath + 'index.html' === payload.path) + pagePath === payloadPath || + (pagePath.endsWith('/') && pagePath + 'index.html' === payloadPath) ) { location.reload() } @@ -259,6 +263,9 @@ export function removeStyle(id: string) { } async function fetchUpdate({ path, acceptedPath, timestamp }: Update) { + path = baseNoSlash + path + acceptedPath = baseNoSlash + acceptedPath + const mod = hotModulesMap.get(path) if (!mod) { // In a code-splitting project, diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 5abf0146e9afef..a2856d1dbb57d0 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -34,7 +34,7 @@ import { ssrManifestPlugin } from './ssr/ssrManifestPlugin' export interface BuildOptions { /** * Base public path when served in production. - * @default '/' + * @deprecated `base` is now a root-level config option. */ base?: string /** @@ -168,11 +168,10 @@ export interface LibraryOptions { export type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife' -export function resolveBuildOptions( - raw?: BuildOptions -): Required { - const resolved: Required = { - base: '/', +export type ResolvedBuildOptions = Required> + +export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions { + const resolved: ResolvedBuildOptions = { target: 'modules', polyfillDynamicImport: raw?.target !== 'esnext' && !raw?.lib, outDir: 'dist', @@ -207,9 +206,6 @@ export function resolveBuildOptions( resolved.target = 'es2019' } - // ensure base ending slash - resolved.base = resolved.base.replace(/([^/])$/, '$1/') - // normalize false string into actual false if ((resolved.minify as any) === 'false') { resolved.minify = false diff --git a/packages/vite/src/node/cli.ts b/packages/vite/src/node/cli.ts index ecf57946e791ae..09fe8a57cb0714 100644 --- a/packages/vite/src/node/cli.ts +++ b/packages/vite/src/node/cli.ts @@ -17,6 +17,7 @@ interface GlobalCLIOptions { config?: string c?: boolean | string root?: string + base?: string r?: string mode?: string m?: string @@ -38,6 +39,7 @@ function cleanOptions(options: GlobalCLIOptions) { delete ret.config delete ret.c delete ret.root + delete ret.base delete ret.r delete ret.mode delete ret.m @@ -50,6 +52,7 @@ function cleanOptions(options: GlobalCLIOptions) { cli .option('-c, --config ', `[string] use specified config file`) .option('-r, --root ', `[string] use specified root directory`) + .option('--base ', `[string] public base path (default: /)`) .option('-l, --logLevel ', `[string] silent | error | warn | all`) .option('--clearScreen', `[boolean] allow/disable clear screen when logging`) .option('-d, --debug [feat]', `[string | boolean] show debug logs`) @@ -77,6 +80,7 @@ cli try { const server = await createServer({ root, + base: options.base, mode: options.mode, configFile: options.config, logLevel: options.logLevel, @@ -95,7 +99,6 @@ cli // build cli .command('build [root]') - .option('--base ', `[string] public base path (default: /)`) .option('--target ', `[string] transpile target (default: 'modules')`) .option('--outDir ', `[string] output directory (default: dist)`) .option( @@ -141,6 +144,7 @@ cli try { await build({ root, + base: options.base, mode: options.mode, configFile: options.config, logLevel: options.logLevel, @@ -169,6 +173,7 @@ cli const config = await resolveConfig( { root, + base: options.base, configFile: options.config, logLevel: options.logLevel }, diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 396415e5223d7a..4111fc54341be5 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -22,6 +22,7 @@ import { resolvePlugin } from './plugins/resolve' import { createLogger, Logger, LogLevel } from './logger' import { DepOptimizationOptions } from './optimizer' import { createFilter } from '@rollup/pluginutils' +import { ResolvedBuildOptions } from '.' const debug = createDebugger('vite:config') @@ -112,6 +113,11 @@ export interface UserConfig { * Default: true */ clearScreen?: boolean + /** + * Base public path when served in development or production. + * @default '/' + */ + base?: string } export interface SSROptions { @@ -136,9 +142,10 @@ export type ResolvedConfig = Readonly< alias: Alias[] plugins: readonly Plugin[] server: ServerOptions - build: Required + build: ResolvedBuildOptions assetsInclude: (file: string) => boolean logger: Logger + base: string } > @@ -149,6 +156,7 @@ export async function resolveConfig( ): Promise { let config = inlineConfig let mode = inlineConfig.mode || defaultMode + const logger = createLogger(config.logLevel, config.clearScreen) // some dependencies e.g. @vue/compiler-* relies on NODE_ENV for getting // production-specific behavior, so set it here even though we haven't @@ -218,8 +226,45 @@ export async function resolveConfig( process.env.NODE_ENV = 'production' } + // resolve public base url + // TODO remove when out of beta + if (config.build?.base) { + logger.warn( + chalk.yellow.bold( + `(!) "build.base" config option is deprecated. ` + + `"base" is now a root-level config option.` + ) + ) + config.base = config.build.base + } + + let BASE_URL = config.base || '/' + if (!BASE_URL.startsWith('/') || !BASE_URL.endsWith('/')) { + logger.warn( + chalk.bold.yellow( + `(!) "base" config option should start and end with "/".` + ) + ) + if (!BASE_URL.startsWith('/')) BASE_URL = '/' + BASE_URL + if (!BASE_URL.endsWith('/')) BASE_URL = BASE_URL + '/' + } + const resolvedBuildOptions = resolveBuildOptions(config.build) + // TODO remove when out of beta + Object.defineProperty(resolvedBuildOptions, 'base', { + get() { + logger.warn( + chalk.yellow.bold( + `(!) "build.base" config option is deprecated. ` + + `"base" is now a root-level config option.\n` + + new Error().stack + ) + ) + return config.base + } + }) + // resolve optimizer cache directory const pkgPath = lookupFile( resolvedRoot, @@ -233,6 +278,17 @@ export async function resolveConfig( ? createFilter(config.assetsInclude) : () => false + let hmr = config.server?.hmr === true ? {} : config.server?.hmr + hmr = { + ...hmr, + path: BASE_URL !== '/' ? BASE_URL.substr(1) : undefined + } + + const server = { + ...config.server, + hmr + } + const resolved = { ...config, configFile: configFile ? normalizePath(configFile) : undefined, @@ -244,11 +300,11 @@ export async function resolveConfig( optimizeCacheDir, alias: resolvedAlias, plugins: userPlugins, - server: config.server || {}, + server, build: resolvedBuildOptions, env: { ...userEnv, - BASE_URL: command === 'build' ? resolvedBuildOptions.base : '/', + BASE_URL, MODE: mode, DEV: !isProduction, PROD: isProduction @@ -256,7 +312,8 @@ export async function resolveConfig( assetsInclude(file: string) { return DEFAULT_ASSETS_RE.test(file) || assetsFilter(file) }, - logger: createLogger(config.logLevel, config.clearScreen) + logger, + base: BASE_URL } resolved.plugins = await resolvePlugins( diff --git a/packages/vite/src/node/logger.ts b/packages/vite/src/node/logger.ts index 5d8988dc8958d8..73cedc7cd78a9e 100644 --- a/packages/vite/src/node/logger.ts +++ b/packages/vite/src/node/logger.ts @@ -10,6 +10,7 @@ export interface Logger { warn(msg: string, options?: LogOptions): void error(msg: string, options?: LogOptions): void clearScreen(type: LogType): void + hasWarned: boolean } export interface LogOptions { @@ -74,11 +75,13 @@ export function createLogger( } } - return { + const logger: Logger = { + hasWarned: false, info(msg, opts) { output('info', msg, opts) }, warn(msg, opts) { + logger.hasWarned = true output('warn', msg, opts) }, error(msg, opts) { @@ -90,4 +93,6 @@ export function createLogger( } } } + + return logger } diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 62248025127253..0f86defc276b10 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -59,7 +59,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin { s = s || (s = new MagicString(code)) const [full, fileHandle, postfix = ''] = match const outputFilepath = - config.build.base + this.getFileName(fileHandle) + postfix + config.base + this.getFileName(fileHandle) + postfix s.overwrite( match.index, match.index + full.length, @@ -118,18 +118,22 @@ export function fileToUrl( } } -function fileToDevUrl(id: string, { root }: ResolvedConfig) { +function fileToDevUrl(id: string, { root, base }: ResolvedConfig) { + let rtn: string + if (checkPublicFile(id, root)) { // in public dir, keep the url as-is - return id - } - if (id.startsWith(root)) { + rtn = id + } else if (id.startsWith(root)) { // in project root, infer short public path - return '/' + path.posix.relative(root, id) + rtn = '/' + path.posix.relative(root, id) + } else { + // outside of project root, use absolute fs path + // (this is special handled by the serve static middleware + rtn = FS_PREFIX + id } - // outside of project root, use absolute fs path - // (this is special handled by the serve static middleware - return FS_PREFIX + id + + return path.posix.join(base, rtn) } const assetCache = new WeakMap>() @@ -145,7 +149,7 @@ async function fileToBuiltUrl( skipPublicCheck = false ): Promise { if (!skipPublicCheck && checkPublicFile(id, config.root)) { - return config.build.base + id.slice(1) + return config.base + id.slice(1) } let cache = assetCache.get(config) @@ -197,7 +201,7 @@ export async function urlToBuiltUrl( pluginContext: PluginContext ): Promise { if (checkPublicFile(url, config.root)) { - return config.build.base + url.slice(1) + return config.base + url.slice(1) } const file = url.startsWith('/') ? path.join(config.root, url) diff --git a/packages/vite/src/node/plugins/clientInjections.ts b/packages/vite/src/node/plugins/clientInjections.ts index d4913fe770d14c..ed21e81fb0b9cc 100644 --- a/packages/vite/src/node/plugins/clientInjections.ts +++ b/packages/vite/src/node/plugins/clientInjections.ts @@ -37,6 +37,7 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin { return code .replace(`__MODE__`, JSON.stringify(config.mode)) + .replace(`__BASE__`, JSON.stringify(config.base)) .replace(`__ROOT__`, JSON.stringify(config.root)) .replace(`__DEFINES__`, JSON.stringify(config.define || {})) .replace(`__HMR_PROTOCOL__`, JSON.stringify(protocol)) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 8349749f2b255e..b17aa65b726677 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -100,15 +100,20 @@ export function cssPlugin(config: ResolvedConfig): Plugin { const urlReplacer: CssUrlReplacer = server ? (url, importer) => { - if (url.startsWith('/')) return url - const filePath = normalizePath( - path.resolve(path.dirname(importer || id), url) - ) - if (filePath.startsWith(config.root)) { - return filePath.slice(config.root.length) + let rtn: string + + if (url.startsWith('/')) { + rtn = url } else { - return `${FS_PREFIX}${filePath}` + const filePath = normalizePath( + path.resolve(path.dirname(importer || id), url) + ) + rtn = filePath.startsWith(config.root) + ? filePath.slice(config.root.length) + : `${FS_PREFIX}${filePath}` } + + return path.posix.join(config.base, rtn) } : (url, importer) => { return urlToBuiltUrl(url, importer || id, config, this) @@ -194,7 +199,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } return [ `import { updateStyle, removeStyle } from ${JSON.stringify( - CLIENT_PUBLIC_PATH + path.posix.join(config.base, CLIENT_PUBLIC_PATH) )}`, `const id = ${JSON.stringify(id)}`, `const css = ${JSON.stringify(css)}`, @@ -235,7 +240,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { // replace asset url references with resolved url chunkCSS = chunkCSS.replace(assetUrlRE, (_, fileId, postfix = '') => { - return config.build.base + this.getFileName(fileId) + postfix + return config.base + this.getFileName(fileId) + postfix }) if (config.build.cssCodeSplit) { diff --git a/packages/vite/src/node/plugins/dynamicImportPolyfill.ts b/packages/vite/src/node/plugins/dynamicImportPolyfill.ts index 5ac75f35921288..b42b9db3b0c6e3 100644 --- a/packages/vite/src/node/plugins/dynamicImportPolyfill.ts +++ b/packages/vite/src/node/plugins/dynamicImportPolyfill.ts @@ -11,7 +11,7 @@ export function dynamicImportPolyfillPlugin(config: ResolvedConfig): Plugin { const polyfillString = `const p = ${polyfill.toString()};` + `${isModernFlag}&&p(${JSON.stringify( - path.posix.join(config.build.base, config.build.assetsDir, '/') + path.posix.join(config.base, config.build.assetsDir, '/') )});` return { diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index bfb6377fdc4991..874cb19804ff15 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -10,14 +10,20 @@ import MagicString from 'magic-string' import { checkPublicFile, assetUrlRE, urlToBuiltUrl } from './asset' import { isCSSRequest, chunkToEmittedCssFileMap } from './css' import { polyfillId } from './dynamicImportPolyfill' -import { AttributeNode, NodeTransform, NodeTypes } from '@vue/compiler-dom' +import { + AttributeNode, + NodeTransform, + NodeTypes, + ElementNode +} from '@vue/compiler-dom' const htmlProxyRE = /\?html-proxy&index=(\d+)\.js$/ export const isHTMLProxy = (id: string) => htmlProxyRE.test(id) -export const htmlCommentRE = //g -export const scriptModuleRE = /(]*type\s*=\s*(?:"module"|'module')[^>]*>)([\s\S]*?)<\/script>/gm -export function htmlPlugin(): Plugin { +const htmlCommentRE = //g +const scriptModuleRE = /(]*type\s*=\s*(?:"module"|'module')[^>]*>)([\s\S]*?)<\/script>/gm + +export function htmlInlineScriptProxyPlugin(): Plugin { return { name: 'vite:html', @@ -49,7 +55,7 @@ export function htmlPlugin(): Plugin { } // this extends the config in @vue/compiler-sfc with -const assetAttrsConfig: Record = { +export const assetAttrsConfig: Record = { link: ['href'], video: ['src', 'poster'], source: ['src'], @@ -58,6 +64,61 @@ const assetAttrsConfig: Record = { use: ['xlink:href', 'href'] } +export async function traverseHtml( + html: string, + filePath: string, + visitor: NodeTransform +) { + // lazy load compiler + const { parse, transform } = await import('@vue/compiler-dom') + // @vue/compiler-core doesn't like lowercase doctypes + html = html.replace(/ { + + await traverseHtml(html, id, (node) => { if (node.type !== NodeTypes.ELEMENT) { return } @@ -113,26 +151,19 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { // script tags if (node.tag === 'script') { - const srcAttr = node.props.find( - (p) => p.type === NodeTypes.ATTRIBUTE && p.name === 'src' - ) as AttributeNode - const typeAttr = node.props.find( - (p) => p.type === NodeTypes.ATTRIBUTE && p.name === 'type' - ) as AttributeNode - const isJsModule = - typeAttr && typeAttr.value && typeAttr.value.content === 'module' - - const url = srcAttr && srcAttr.value && srcAttr.value.content + const { src, isModule } = getScriptInfo(node) + + const url = src && src.value && src.value.content if (url && checkPublicFile(url, config.root)) { // referencing public dir url, prefix with base s.overwrite( - srcAttr.value!.loc.start.offset, - srcAttr.value!.loc.end.offset, - config.build.base + url.slice(1) + src!.value!.loc.start.offset, + src!.value!.loc.end.offset, + config.base + url.slice(1) ) } - if (isJsModule) { + if (isModule) { inlineModuleIndex++ if (url && !isExcludedUrl(url)) { // ` + const s = new MagicString(html) + let scriptModuleIndex = -1 + + await traverseHtml(html, htmlPath, (node) => { + if (node.type !== NodeTypes.ELEMENT) { + return + } + + // script tags + if (node.tag === 'script') { + const { src, isModule } = getScriptInfo(node) + if (isModule) { + scriptModuleIndex++ + } + + if (src) { + const url = src.value?.content || '' + if (url.startsWith('/')) { + // prefix with base + s.overwrite( + src.value!.loc.start.offset, + src.value!.loc.end.offset, + `"${config.base + url.slice(1)}"` + ) + } + } else if (isModule) { + // inline js module. convert to src="proxy" + s.overwrite( + node.loc.start.offset, + node.loc.end.offset, + `` + ) } - return _match - }) - .replace(//g, (_, i) => comments[i]) + } + + // elements with [href/src] attrs + const assetAttrs = assetAttrsConfig[node.tag] + if (assetAttrs) { + for (const p of node.props) { + if ( + p.type === NodeTypes.ATTRIBUTE && + p.value && + assetAttrs.includes(p.name) + ) { + const url = p.value.content || '' + if (url.startsWith('/')) { + s.overwrite( + p.value.loc.start.offset, + p.value.loc.end.offset, + `"${config.base + url.slice(1)}"` + ) + } + } + } + } + }) + + html = s.toString() return { html, tags: [ { tag: 'script', - attrs: { type: 'module', src: CLIENT_PUBLIC_PATH }, + attrs: { + type: 'module', + src: path.posix.join(base, CLIENT_PUBLIC_PATH) + }, injectTo: 'head-prepend' } ] diff --git a/packages/vite/src/node/ssr/ssrManifestPlugin.ts b/packages/vite/src/node/ssr/ssrManifestPlugin.ts index 2f724a790ebb92..0044e63df39b52 100644 --- a/packages/vite/src/node/ssr/ssrManifestPlugin.ts +++ b/packages/vite/src/node/ssr/ssrManifestPlugin.ts @@ -5,7 +5,7 @@ import { chunkToEmittedCssFileMap } from '../plugins/css' export function ssrManifestPlugin(config: ResolvedConfig): Plugin { // module id => preload assets mapping const ssrManifest: Record = {} - const base = config.build.base + const base = config.base return { name: 'vite:manifest', diff --git a/scripts/jestPerTestSetup.ts b/scripts/jestPerTestSetup.ts index dc7c6b28ca7bdd..b2cbfed0cbc51f 100644 --- a/scripts/jestPerTestSetup.ts +++ b/scripts/jestPerTestSetup.ts @@ -66,8 +66,9 @@ beforeAll(async () => { if (!isBuildTest) { process.env.VITE_INLINE = 'inline-serve' server = await (await createServer(options)).listen() - // use resolved port from server - const url = ((global as any).viteTestUrl = `http://localhost:${server.config.server.port}`) + // use resolved port/base from server + const base = server.config.base === '/' ? '' : server.config.base + const url = ((global as any).viteTestUrl = `http://localhost:${server.config.server.port}${base}`) await page.goto(url) } else { process.env.VITE_INLINE = 'inline-build' @@ -100,7 +101,7 @@ function startStaticServer(): Promise { try { config = require(configFile) } catch (e) {} - const base = config?.build?.base || '' + const base = (config?.base || '/') === '/' ? '' : config.base // @ts-ignore if (config && config.__test__) { From 406cbeaa4f52472ce356980840f1a2a824eaa497 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 18:27:08 -0500 Subject: [PATCH 205/514] fix(optimizer): improve exports analysis --- packages/vite/src/node/optimizer/index.ts | 45 +++++++++++------------ packages/vite/src/node/plugins/resolve.ts | 2 +- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 25564bc92de1ee..c022c17b7fa45b 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -5,6 +5,7 @@ import { createHash } from 'crypto' import { ResolvedConfig } from '../config' import { SUPPORTED_EXTS } from '../constants' import { + bareImportRE, createDebugger, emptyDir, lookupFile, @@ -16,7 +17,7 @@ import { createPluginContainer, PluginContainer } from '../server/pluginContainer' -import { tryNodeResolve } from '../plugins/resolve' +import { tryNodeResolve, tryFsResolve } from '../plugins/resolve' import aliasPlugin from '@rollup/plugin-alias' import { createFilter, makeLegalIdentifier } from '@rollup/pluginutils' import { Plugin } from '../plugin' @@ -232,11 +233,9 @@ export async function optimizeDeps( } for (const id in qualified) { - data.optimized[id] = await parseExports( - qualified[id], - config, - aliasResolver - ) + data.optimized[id] = [ + ...new Set(await parseExports(qualified[id], config, aliasResolver)) + ] } // construct a entry containing all the deps @@ -255,7 +254,7 @@ export async function optimizeDeps( plugins: [esbuildDepPlugin(qualified, config, data.transitiveOptimized)] }) - fs.unlinkSync(tempEntryPath) + // fs.unlinkSync(tempEntryPath) writeFile(dataPath, JSON.stringify(data, null, 2)) } @@ -455,18 +454,18 @@ function buildTempEntry( } else { res += `export { ${exports .map((e) => `${e} as ${validId}_${e}`) - .join(', ')} } from "${entry}"\n` + .join(',\n')} } from "${entry}"\n` } } return res } async function parseExports( - entry: string, + file: string, config: ResolvedConfig, aliasResolver: PluginContainer ) { - const content = fs.readFileSync(entry, 'utf-8') + const content = fs.readFileSync(file, 'utf-8') const [imports, exports] = parse(content) // check for export * from statements @@ -480,20 +479,20 @@ async function parseExports( if (dynamicIndex < 0) { const exp = content.slice(expStart, expEnd) if (exp.startsWith(`export * from`)) { - const id = content.slice(start, end) - const aliased = (await aliasResolver.resolveId(id))?.id || id - const filePath = tryNodeResolve( - aliased, - config.root, - config.isProduction - )?.id - if (filePath) { - const childExports = await parseExports( - filePath, - config, - aliasResolver + let id: string | undefined = content.slice(start, end) + id = (await aliasResolver.resolveId(id))?.id || id + if (bareImportRE.test(id)) { + id = tryNodeResolve(id, config.root, config.isProduction)?.id + } else { + id = tryFsResolve( + normalizePath(path.resolve(path.dirname(file), id)), + false, // production: false + true // tryIndex: true ) - exports.push(...childExports) + } + if (id) { + const childExports = await parseExports(id, config, aliasResolver) + exports.push(...childExports.filter((e) => e !== 'default')) } } } diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index d2a1c93b77859a..2812c3c287f403 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -225,7 +225,7 @@ export function resolvePlugin( } } -function tryFsResolve( +export function tryFsResolve( fsPath: string, isProduction: boolean, tryIndex = true From f1689231a227b1314b557c87db581b00d7066522 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 18:50:57 -0500 Subject: [PATCH 206/514] chore: issue template chooser [skip ci] --- .github/ISSUE_TEMPLATE/config.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/config.yml diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000000000..1db862a27cb6d4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: Questions & Discussions + url: https://github.com/vitejs/vite/discussions + about: Use Discussions tab for questions and discussions. From 626cf159969ce912175eb4cea0772ab7da82cdcb Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 21:30:48 -0500 Subject: [PATCH 207/514] refactor: use split esbuild pre-bundling --- package.json | 2 +- packages/vite/src/node/constants.ts | 2 - .../src/node/optimizer/esbuildDepPlugin.ts | 4 +- packages/vite/src/node/optimizer/index.ts | 118 ++++-------- .../vite/src/node/plugins/importAnalysis.ts | 172 ++++++------------ packages/vite/src/node/plugins/resolve.ts | 9 +- 6 files changed, 99 insertions(+), 208 deletions(-) diff --git a/package.json b/package.json index 1b0437597fa0e6..e36a2f2131965d 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "test": "run-s test-serve test-build", "test-serve": "jest", "debug-serve": "cross-env VITE_DEBUG_SERVE=1 node --inspect-brk ./node_modules/.bin/jest", - "test-build": "cross-env VITE_TEST_BUILD=1 jest", + "test-build": "cross-env VITE_TEST_BUILD=1 jest playground", "debug-build": "cross-env VITE_TEST_BUILD=1 VITE_PRESERVE_BUILD_ARTIFACTS=1 node --inspect-brk ./node_modules/.bin/jest", "docs": "vitepress dev docs", "build-docs": "vitepress build docs", diff --git a/packages/vite/src/node/constants.ts b/packages/vite/src/node/constants.ts index 1e54f696466631..252627120afae8 100644 --- a/packages/vite/src/node/constants.ts +++ b/packages/vite/src/node/constants.ts @@ -14,8 +14,6 @@ export const FS_PREFIX = `/@fs/` */ export const VALID_ID_PREFIX = `/@id/` -export const OPTIMIZED_PREFIX = `/@optimized/` - /** * Some Rollup plugins use ids that starts with the null byte \0 to avoid * collisions, but it is not permitted in import URLs so we have to replace diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index c8092b2aacd31a..eaf206b4adcd4a 100644 --- a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -4,7 +4,7 @@ import { knownAssetTypes } from '../constants' import builtins from 'builtin-modules' import { ResolvedConfig } from '..' import chalk from 'chalk' -import { deepImportRE } from '../utils' +import { deepImportRE, isBuiltin } from '../utils' const externalTypes = ['css', 'vue', 'svelte', ...knownAssetTypes] @@ -34,7 +34,7 @@ export function esbuildDepPlugin( // record transitive deps build.onResolve({ filter: /^[\w@]/ }, ({ path: id }) => { - if (!(id in qualified) && !/:\/\//.test(id)) { + if (!(id in qualified) && !isBuiltin(id)) { const deepMatch = id.match(deepImportRE) const pkgId = deepMatch ? deepMatch[1] || deepMatch[2] : id transitiveOptimized[pkgId] = true diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index c022c17b7fa45b..3eb20d9ff816b5 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -5,7 +5,6 @@ import { createHash } from 'crypto' import { ResolvedConfig } from '../config' import { SUPPORTED_EXTS } from '../constants' import { - bareImportRE, createDebugger, emptyDir, lookupFile, @@ -17,9 +16,9 @@ import { createPluginContainer, PluginContainer } from '../server/pluginContainer' -import { tryNodeResolve, tryFsResolve } from '../plugins/resolve' +import { tryNodeResolve } from '../plugins/resolve' import aliasPlugin from '@rollup/plugin-alias' -import { createFilter, makeLegalIdentifier } from '@rollup/pluginutils' +import { createFilter } from '@rollup/pluginutils' import { Plugin } from '../plugin' import { prompt } from 'enquirer' import { build } from 'esbuild' @@ -74,7 +73,13 @@ export interface DepOptimizationOptions { export interface DepOptimizationMetadata { hash: string - optimized: Record + optimized: Record< + string, + { + file: string + needsInterop: boolean + } + > transitiveOptimized: Record dependencies: Record } @@ -84,8 +89,6 @@ export async function optimizeDeps( force = config.server.force, asCommand = false ) { - await init - config = { ...config, command: 'build' @@ -232,29 +235,40 @@ export async function optimizeDeps( logger.info(chalk.greenBright(`Optimizing dependencies:\n${depsString}`)) } - for (const id in qualified) { - data.optimized[id] = [ - ...new Set(await parseExports(qualified[id], config, aliasResolver)) - ] - } - - // construct a entry containing all the deps - const tempEntry = buildTempEntry(qualified, data.optimized, cacheDir) - const tempEntryPath = path.resolve(path.join(cacheDir, 'depsEntry.js')) - fs.writeFileSync(tempEntryPath, tempEntry) + const esbuildMetaPath = path.join(cacheDir, 'esbuild.json') await build({ - entryPoints: [tempEntryPath], + entryPoints: Object.values(qualified), bundle: true, format: 'esm', - outfile: path.join(cacheDir, 'deps.js'), + splitting: true, + outdir: cacheDir, + metafile: esbuildMetaPath, define: { 'process.env.NODE_ENV': '"development"' }, plugins: [esbuildDepPlugin(qualified, config, data.transitiveOptimized)] }) - // fs.unlinkSync(tempEntryPath) + const meta = JSON.parse(fs.readFileSync(esbuildMetaPath, 'utf-8')) + + await init + for (const output in meta.outputs) { + const absolute = normalizePath(path.resolve(output)) + const relative = normalizePath(path.relative(cacheDir, absolute)) + for (const id in qualified) { + const entry = qualified[id] + if (entry.endsWith(relative)) { + // check if this is a cjs dep. + const [, exports] = parse(fs.readFileSync(entry, 'utf-8')) + data.optimized[id] = { + file: absolute, + needsInterop: !exports.length + } + } + } + } + writeFile(dataPath, JSON.stringify(data, null, 2)) } @@ -433,69 +447,3 @@ function getDepHash( ) return createHash('sha256').update(content).digest('hex').substr(0, 8) } - -function buildTempEntry( - qualified: Record, - idToExports: DepOptimizationMetadata['optimized'], - basedir: string -) { - let res = '' - for (const id in qualified) { - const validId = makeLegalIdentifier(id) - const exports = idToExports[id] - const entry = normalizePath(path.relative(basedir, qualified[id])) - if (!exports.length) { - // cjs or umd - provide rollup-style compat - // by exposing both the default and named properties - res += `import ${validId}_default from "${entry}"\n` - res += `import * as ${validId}_all from "${entry}"\n` - res += `const ${validId} = { ...${validId}_all, default: ${validId}_default }\n` - res += `export { ${validId} }\n` - } else { - res += `export { ${exports - .map((e) => `${e} as ${validId}_${e}`) - .join(',\n')} } from "${entry}"\n` - } - } - return res -} - -async function parseExports( - file: string, - config: ResolvedConfig, - aliasResolver: PluginContainer -) { - const content = fs.readFileSync(file, 'utf-8') - const [imports, exports] = parse(content) - - // check for export * from statements - for (const { - s: start, - e: end, - ss: expStart, - se: expEnd, - d: dynamicIndex - } of imports) { - if (dynamicIndex < 0) { - const exp = content.slice(expStart, expEnd) - if (exp.startsWith(`export * from`)) { - let id: string | undefined = content.slice(start, end) - id = (await aliasResolver.resolveId(id))?.id || id - if (bareImportRE.test(id)) { - id = tryNodeResolve(id, config.root, config.isProduction)?.id - } else { - id = tryFsResolve( - normalizePath(path.resolve(path.dirname(file), id)), - false, // production: false - true // tryIndex: true - ) - } - if (id) { - const childExports = await parseExports(id, config, aliasResolver) - exports.push(...childExports.filter((e) => e !== 'default')) - } - } - } - } - return exports -} diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 78073707548ef8..c0ed57aaaefaea 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -30,15 +30,14 @@ import { CLIENT_PUBLIC_PATH, DEP_VERSION_RE, VALID_ID_PREFIX, - NULL_BYTE_PLACEHOLDER, - OPTIMIZED_PREFIX + NULL_BYTE_PLACEHOLDER } from '../constants' import { ViteDevServer } from '..' import { checkPublicFile } from './asset' import { parse as parseJS } from 'acorn' -import type { ImportDeclaration, Node } from 'estree' -import { makeLegalIdentifier } from '@rollup/pluginutils' +import type { Node } from 'estree' import { transformImportGlob } from '../importGlob' +import { makeLegalIdentifier } from '@rollup/pluginutils' const isDebug = !!process.env.DEBUG const debugRewrite = createDebugger('vite:rewrite') @@ -87,7 +86,6 @@ function markExplicitImport(url: string) { export function importAnalysisPlugin(config: ResolvedConfig): Plugin { const clientPublicPath = path.posix.join(config.base, CLIENT_PUBLIC_PATH) let server: ViteDevServer - let optimizedSource: string | undefined return { name: 'vite:import-analysis', @@ -357,33 +355,18 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { if (url !== rawUrl) { // for optimized cjs deps, support named imports by rewriting named // imports to const assignments. - if (resolvedId.startsWith(OPTIMIZED_PREFIX)) { - const depId = resolvedId.slice(OPTIMIZED_PREFIX.length) - const optimizedId = makeLegalIdentifier(depId) - optimizedSource = - optimizedSource || - normalizePath(path.join(config.optimizeCacheDir!, 'deps.js')) + - `?v=${server._optimizeDepsMetadata!.hash}` - + if (resolvedId.endsWith(`&es-interop`)) { + url = url.slice(0, -11) if (isLiteralDynamicId) { - // rewrite `import('package')` to expose module.exports - // note plugin-commonjs' behavior is exposing all properties on - // `module.exports` PLUS `module.exports` itself as `default`. + // rewrite `import('package')` to expose the default directly str().overwrite( dynamicIndex, end + 1, - `import('${optimizedSource}').then(m => m.${optimizedId})` + `import('${url}').then(m => ({ ...m.default, default: m.default }))` ) } else { const exp = source.slice(expStart, expEnd) - const rewritten = transformOptimizedImport( - exp, - optimizedSource, - optimizedId, - index, - depId, - server._optimizeDepsMetadata!.optimized[depId] - ) + const rewritten = transformCjsImport(exp, url, rawUrl, index) if (rewritten) { str().overwrite(expStart, expEnd, rewritten) } else { @@ -509,106 +492,65 @@ function isSupportedDynamicImport(url: string) { return true } -function transformOptimizedImport( +type ImportNameSpecifier = { importedName: string; localName: string } + +/** + * Detect import statements to a known optimized CJS dependency and provide + * ES named imports interop. We do this by rewriting named imports to a variable + * assignment to the corresponding property on the `module.exports` of the cjs + * module. Note this doesn't support dynamic re-assignments from within the cjs + * module. + * + * Note that es-module-lexer treats `export * from '...'` as an import as well, + * so, we may encounter ExportAllDeclaration here, in which case `undefined` + * will be returned. + * + * Credits \@csr632 via #837 + */ +function transformCjsImport( importExp: string, - optimizedSource: string, - optimizedId: string, - importIndex: number, - id: string, - exports: string[] + url: string, + rawUrl: string, + importIndex: number ): string | undefined { const node = (parseJS(importExp, { ecmaVersion: 2020, sourceType: 'module' }) as any).body[0] as Node - const lines: string[] = [] - if (!exports.length) { - // optimized cjs dep. import then assign. - // Credits \@csr632 via #837 + if (node.type === 'ImportDeclaration') { + const importNames: ImportNameSpecifier[] = [] + for (const spec of node.specifiers) { + if ( + spec.type === 'ImportSpecifier' && + spec.imported.type === 'Identifier' + ) { + const importedName = spec.imported.name + const localName = spec.local.name + importNames.push({ importedName, localName }) + } else if (spec.type === 'ImportDefaultSpecifier') { + importNames.push({ + importedName: 'default', + localName: spec.local.name + }) + } else if (spec.type === 'ImportNamespaceSpecifier') { + importNames.push({ importedName: '*', localName: spec.local.name }) + } + } + // If there is multiple import for same id in one file, // importIndex will prevent the cjsModuleName to be duplicate - const moduleName = `__vite__${optimizedId}_${importIndex}` - lines.push( - `import { ${optimizedId} as ${moduleName} } from "${optimizedSource}";` + const cjsModuleName = makeLegalIdentifier( + `__vite__cjsImport${importIndex}_${rawUrl}` ) - if (node.type === 'ImportDeclaration') { - getImportNamePairs(node, id, exports).forEach( - ({ importedName, localName }) => { - if (importedName === '*' || importedName === 'default') { - lines.push(`const ${localName} = ${moduleName}.default`) - } else { - lines.push(`const ${localName} = ${moduleName}["${importedName}"]`) - } - } - ) - } else if (node.type === 'ExportAllDeclaration') { - const namedExports = exports.filter((e) => e !== 'default') - lines.push(`const { ${namedExports.join(', ')} } = ${moduleName}`) - lines.push(`export { ${namedExports.join(', ')} }`) - } - } else { - const namedExports = exports.filter((e) => e !== 'default') - // optimized esm dep - if (node.type === 'ImportDeclaration') { - getImportNamePairs(node, id, exports).forEach( - ({ importedName, localName }) => { - if (importedName === '*') { - lines.push( - `import { ${namedExports - .map( - (e) => `${optimizedId}_${e} as __vite__${optimizedId}_${e}` - ) - .join(', ')} } from "${optimizedSource}"`, - `const ${localName} = Object.freeze({ ${namedExports - .map((e) => `${e}: __vite__${optimizedId}_${e}`) - .join(',')} })` - ) - } else { - lines.push( - `import { ${optimizedId}_${importedName} as ${localName} } from "${optimizedSource}"` - ) - } - } - ) - } else if (node.type === 'ExportAllDeclaration') { - lines.push( - `export { ${namedExports - .map((e) => `${optimizedId}_${e} as ${e}`) - .join(', ')} } from "${optimizedSource}"` - ) - } - } - return lines.join('\n') -} - -type ImportNameSpecifier = { importedName: string; localName: string } - -function getImportNamePairs( - node: ImportDeclaration, - id: string, - exports: string[] -): ImportNameSpecifier[] { - const importNames: ImportNameSpecifier[] = [] - for (const spec of node.specifiers) { - if ( - spec.type === 'ImportSpecifier' && - spec.imported.type === 'Identifier' - ) { - const importedName = spec.imported.name - const localName = spec.local.name - importNames.push({ importedName, localName }) - } else if (spec.type === 'ImportDefaultSpecifier') { - if (exports.length && !exports.includes('default')) { - throw new Error(`Module "${id}" has no default export.`) + const lines: string[] = [`import ${cjsModuleName} from "${url}";`] + importNames.forEach(({ importedName, localName }) => { + if (importedName === '*' || importedName === 'default') { + lines.push(`const ${localName} = ${cjsModuleName};`) + } else { + lines.push(`const ${localName} = ${cjsModuleName}["${importedName}"];`) } - importNames.push({ - importedName: 'default', - localName: spec.local.name - }) - } else if (spec.type === 'ImportNamespaceSpecifier') { - importNames.push({ importedName: '*', localName: spec.local.name }) - } + }) + return lines.join('\n') } - return importNames } diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 2812c3c287f403..7e5fb8abde6b7b 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -2,7 +2,7 @@ import fs from 'fs' import path from 'path' import { Plugin } from '../plugin' import chalk from 'chalk' -import { FS_PREFIX, OPTIMIZED_PREFIX, SUPPORTED_EXTS } from '../constants' +import { FS_PREFIX, SUPPORTED_EXTS } from '../constants' import { isBuiltin, bareImportRE, @@ -370,9 +370,12 @@ export function tryOptimizedResolve( const cacheDir = server.config.optimizeCacheDir const depData = server._optimizeDepsMetadata if (cacheDir && depData) { - const isOptimized = depData.optimized[cleanUrl(id)] + const isOptimized = depData.optimized[id] if (isOptimized) { - return `${OPTIMIZED_PREFIX}${id}` + return ( + isOptimized.file + + `?v=${depData.hash}${isOptimized.needsInterop ? `&es-interop` : ``}` + ) } } } From 01c047ec4bbb8943355907111fcc0b0c8940c82e Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 21:52:31 -0500 Subject: [PATCH 208/514] chore: fix esbuild entries --- packages/vite/src/node/optimizer/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 3eb20d9ff816b5..b545610fada6cc 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -238,7 +238,7 @@ export async function optimizeDeps( const esbuildMetaPath = path.join(cacheDir, 'esbuild.json') await build({ - entryPoints: Object.values(qualified), + entryPoints: Object.values(qualified).map((p) => path.resolve(p)), bundle: true, format: 'esm', splitting: true, From 2261fc3ab032d26a196b24cce9c68c7fc96b8af3 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 21:57:27 -0500 Subject: [PATCH 209/514] chore: remove rollup options from optimizer hash --- packages/vite/src/node/optimizer/index.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index b545610fada6cc..40664fc642c49a 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -241,6 +241,7 @@ export async function optimizeDeps( entryPoints: Object.values(qualified).map((p) => path.resolve(p)), bundle: true, format: 'esm', + external, splitting: true, outdir: cacheDir, metafile: esbuildMetaPath, @@ -425,12 +426,6 @@ function getDepHash( alias: config.alias, dedupe: config.dedupe, assetsInclude: config.assetsInclude, - build: { - commonjsOptions: config.build.commonjsOptions, - rollupOptions: { - external: config.build.rollupOptions?.external - } - }, optimizeDeps: { include: config.optimizeDeps?.include, exclude: config.optimizeDeps?.exclude, From 38524f6c6e864f9805dd0083da1dfa8ce20fa816 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 22:04:51 -0500 Subject: [PATCH 210/514] refactor: remove optimizeDeps.plugins BREAKING CHANGE: `optimizeDeps.plugins` has been removed. The dep optimizer is now using `esbuild`, and all non-js files are automatically externalized to be processed by Vite's transform pipeline when imported. --- docs/config/index.md | 8 ++++---- packages/vite/src/node/optimizer/index.ts | 10 ++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index c614f0298712ea..9d46f835bd66dc 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -471,13 +471,13 @@ export default ({ command, mode }) => { Dependencies to force exclude in pre-bundling. -### optimizeDeps.plugins +### optimizeDeps.link -- **Type:** `Plugin[]` +- **Type:** `string[]` - By default, Vite assumes dependencies ship plain JavaScript and will not attempt to transform non-js file formats during pre-bundling. If you wish to support special file types, e.g. `.vue` files, you will need to supply the relevant plugins via this option. + A list of packages to be treated as "linked". Linked packages will not be pre-bundled - Vite will analyze and pre-bundle its depndencies instead. - Note that you will also need to include these plugins in the main `plugins` option in order to support the same file types during production build. + Note that if you are using a monorepo via package manager workspaces, and have the packages listed as dependencies in your Vite entry package, Vite will automatically treat them as linked (by checking if it's inside `node_modules`). This option is only needed if you have unusual setups where your Vite app is importing from a package that isn't already linked as a Node-resolvable dependency. ### optimizeDeps.auto diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 40664fc642c49a..ffae3c55790b2d 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -19,7 +19,6 @@ import { import { tryNodeResolve } from '../plugins/resolve' import aliasPlugin from '@rollup/plugin-alias' import { createFilter } from '@rollup/pluginutils' -import { Plugin } from '../plugin' import { prompt } from 'enquirer' import { build } from 'esbuild' import { esbuildDepPlugin } from './esbuildDepPlugin' @@ -57,18 +56,14 @@ export interface DepOptimizationOptions { */ exclude?: string | RegExp | (string | RegExp)[] /** - * Plugins to use for dep optimizations. + * A list of linked dependencies that should be treated as source code. */ - plugins?: Plugin[] + link?: string[] /** * Automatically run `vite optimize` on server start? * @default true */ auto?: boolean - /** - * A list of linked dependencies that should be treated as source code. - */ - link?: string[] } export interface DepOptimizationMetadata { @@ -429,7 +424,6 @@ function getDepHash( optimizeDeps: { include: config.optimizeDeps?.include, exclude: config.optimizeDeps?.exclude, - plugins: config.optimizeDeps?.plugins?.map((p) => p.name), link: config.optimizeDeps?.link } }, From f22ddbdb52d4579a5756215c320a13cd674a38a0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 22:33:39 -0500 Subject: [PATCH 211/514] fix(ssr): fix ssr transform edge cases fix #1646 --- packages/playground/tsconfig.json | 1 + .../node/ssr/__tests__/ssrTransform.spec.ts | 131 ++++++++++++++++++ packages/vite/src/node/ssr/ssrTransform.ts | 15 +- 3 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts diff --git a/packages/playground/tsconfig.json b/packages/playground/tsconfig.json index 14bc3bf1ce2e18..5f1c7aa8a50c38 100644 --- a/packages/playground/tsconfig.json +++ b/packages/playground/tsconfig.json @@ -2,6 +2,7 @@ "include": ["."], "exclude": ["**/dist/**"], "compilerOptions": { + "target": "esnext", "outDir": "dist", "allowJs": true, "esModuleInterop": true, diff --git a/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts b/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts new file mode 100644 index 00000000000000..e948f0b7fbb5e5 --- /dev/null +++ b/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts @@ -0,0 +1,131 @@ +import { traverseHtml } from '../../plugins/html' +import { ssrTransform } from '../ssrTransform' + +test('default import', async () => { + expect( + (await ssrTransform(`import foo from 'vue';console.log(foo.bar)`, null)) + .code + ).toMatchInlineSnapshot(` + "const __vite_ssr_import_0__ = __vite_ssr_import__(\\"vue\\") + console.log(__vite_ssr_import_0__.default.bar)" + `) +}) + +test('named import', async () => { + expect( + ( + await ssrTransform( + `import { ref } from 'vue';function foo() { return ref(0) }`, + null + ) + ).code + ).toMatchInlineSnapshot(` + "const __vite_ssr_import_0__ = __vite_ssr_import__(\\"vue\\") + function foo() { return __vite_ssr_import_0__.ref(0) }" + `) +}) + +test('namespace import', async () => { + expect( + ( + await ssrTransform( + `import * as vue from 'vue';function foo() { return vue.ref(0) }`, + null + ) + ).code + ).toMatchInlineSnapshot(` + "const __vite_ssr_import_0__ = __vite_ssr_import__(\\"vue\\") + function foo() { return __vite_ssr_import_0__.ref(0) }" + `) +}) + +test('export function decl', async () => { + expect((await ssrTransform(`export function foo() {}`, null)).code) + .toMatchInlineSnapshot(` + "function foo() {} + Object.defineProperty(__vite_ssr_exports__, \\"foo\\", { get(){ return foo }})" + `) +}) + +test('export class decl', async () => { + expect((await ssrTransform(`export class foo {}`, null)).code) + .toMatchInlineSnapshot(` + "class foo {} + Object.defineProperty(__vite_ssr_exports__, \\"foo\\", { get(){ return foo }})" + `) +}) + +test('export var decl', async () => { + expect((await ssrTransform(`export const a = 1, b = 2`, null)).code) + .toMatchInlineSnapshot(` + "const a = 1, b = 2 + Object.defineProperty(__vite_ssr_exports__, \\"a\\", { get(){ return a }}) + Object.defineProperty(__vite_ssr_exports__, \\"b\\", { get(){ return b }})" + `) +}) + +test('export named', async () => { + expect( + (await ssrTransform(`const a = 1, b = 2; export { a, b as c }`, null)).code + ).toMatchInlineSnapshot(` + "const a = 1, b = 2; + Object.defineProperty(__vite_ssr_exports__, \\"a\\", { get(){ return a }}) + Object.defineProperty(__vite_ssr_exports__, \\"c\\", { get(){ return b }})" + `) +}) + +test('export named from', async () => { + expect( + (await ssrTransform(`export { ref, computed as c } from 'vue'`, null)).code + ).toMatchInlineSnapshot(` + "const __vite_ssr_import_0__ = __vite_ssr_import__(\\"vue\\") + + Object.defineProperty(__vite_ssr_exports__, \\"ref\\", { get(){ return __vite_ssr_import_0__.ref }}) + Object.defineProperty(__vite_ssr_exports__, \\"c\\", { get(){ return __vite_ssr_import_0__.computed }})" + `) +}) + +test('named exports of imported binding', async () => { + expect( + ( + await ssrTransform( + `import {createApp} from 'vue';export {createApp}`, + null + ) + ).code + ).toMatchInlineSnapshot(` + "const __vite_ssr_import_0__ = __vite_ssr_import__(\\"vue\\") + + Object.defineProperty(__vite_ssr_exports__, \\"createApp\\", { get(){ return __vite_ssr_import_0__.createApp }})" + `) +}) + +test('export * from', async () => { + expect((await ssrTransform(`export * from 'vue'`, null)).code) + .toMatchInlineSnapshot(` + "const __vite_ssr_import_0__ = __vite_ssr_import__(\\"vue\\") + + __vite_ssr_exportAll__(__vite_ssr_import_0__)" + `) +}) + +test('export default', async () => { + expect( + (await ssrTransform(`export default {}`, null)).code + ).toMatchInlineSnapshot(`"__vite_ssr_exports__.default = {}"`) +}) + +test('import.meta', async () => { + expect( + (await ssrTransform(`console.log(import.meta.url)`, null)).code + ).toMatchInlineSnapshot(`"console.log(__vite_ssr_import_meta__.url)"`) +}) + +test('dynamic import', async () => { + expect( + (await ssrTransform(`export const i = () => import('./foo')`, null)).code + ).toMatchInlineSnapshot(` + "const i = () => __vite_ssr_dynamic_import__('./foo') + Object.defineProperty(__vite_ssr_exports__, \\"i\\", { get(){ return i }})" + `) +}) diff --git a/packages/vite/src/node/ssr/ssrTransform.ts b/packages/vite/src/node/ssr/ssrTransform.ts index 6ee39987dbe905..460c9202e1b44b 100644 --- a/packages/vite/src/node/ssr/ssrTransform.ts +++ b/packages/vite/src/node/ssr/ssrTransform.ts @@ -56,7 +56,7 @@ export async function ssrTransform( ) } - // 1. check all import/export statements + // 1. check all import statements and record id -> importName map for (const node of ast.body as Node[]) { // import foo from 'foo' --> foo -> __import_foo__.default // import { baz } from 'foo' --> baz -> __import_foo__.baz @@ -78,7 +78,10 @@ export async function ssrTransform( } s.remove(node.start, node.end) } + } + // 2. check all export statements and define exports + for (const node of ast.body as Node[]) { // named exports if (node.type === 'ExportNamedDeclaration') { if (node.declaration) { @@ -104,10 +107,13 @@ export async function ssrTransform( for (const spec of node.specifiers) { defineExport(spec.exported.name, `${importId}.${spec.local.name}`) } + s.remove(node.start, node.end) } else { // export { foo, bar } for (const spec of node.specifiers) { - defineExport(spec.exported.name, spec.local.name) + const local = spec.local.name + const binding = idToImportMap.get(local) + defineExport(spec.exported.name, binding || local) } s.remove(node.start, node.end) } @@ -125,6 +131,7 @@ export async function ssrTransform( // export * from './foo' if (node.type === 'ExportAllDeclaration') { const importId = defineImport(node, node.source.value as string) + s.remove(node.start, node.end) s.append(`\n${ssrExportAllKey}(${importId})`) } } @@ -319,6 +326,10 @@ function isRefIdentifier(id: Identifier, parent: _Node, parentStack: _Node[]) { return false } + if (parent.type === 'ExportSpecifier') { + return false + } + // is a special keyword but parsed as identifier if (id.name === 'arguments') { return false From 2c9db83dfac18da303022da3250edd9a5b0e2cf8 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 22:55:12 -0500 Subject: [PATCH 212/514] chore: target es2019 for test ts transform (for CI) --- packages/playground/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playground/tsconfig.json b/packages/playground/tsconfig.json index 5f1c7aa8a50c38..db0ed51d0fc259 100644 --- a/packages/playground/tsconfig.json +++ b/packages/playground/tsconfig.json @@ -2,7 +2,7 @@ "include": ["."], "exclude": ["**/dist/**"], "compilerOptions": { - "target": "esnext", + "target": "es2019", "outDir": "dist", "allowJs": true, "esModuleInterop": true, From 16248c02844c5447eeb7c441cc4b051becef2346 Mon Sep 17 00:00:00 2001 From: underfin Date: Sat, 23 Jan 2021 12:02:24 +0800 Subject: [PATCH 213/514] fix(dev): remove comment for sourcemap reference at debug (#1658) --- packages/vite/src/node/server/send.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/send.ts b/packages/vite/src/node/server/send.ts index 36f3618a531e65..4d50af7cd3c624 100644 --- a/packages/vite/src/node/server/send.ts +++ b/packages/vite/src/node/server/send.ts @@ -32,7 +32,10 @@ export function send( // inject source map reference if (map && map.mappings) { if (isDebug) { - content += `\n/*${JSON.stringify(map, null, 2)}*/\n` + content += `\n/*${JSON.stringify(map, null, 2).replace( + /\*\//g, + '*\\/' + )}*/\n` } content += genSourceMapString(map) } From de01271321a709e36f307c3fa08d01ff62f387a8 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 23:09:07 -0500 Subject: [PATCH 214/514] chore: more warn --- packages/vite/src/node/optimizer/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index ffae3c55790b2d..006e3c13881467 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -44,7 +44,7 @@ const KNOWN_WARN_LIST = new Set([ 'typescript' ]) -const WARN_RE = /^(@vitejs\/|vite-)plugin-/ +const WARN_RE = /^(@vitejs\/|@rollup\/|vite-|rollup-|postcss-|babel-)plugin-/ export interface DepOptimizationOptions { /** From 4fe51beddb7b1797f66b8295b656a953d0500852 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 23:15:41 -0500 Subject: [PATCH 215/514] chore: improve deep import message --- packages/vite/src/node/plugins/resolve.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 7e5fb8abde6b7b..58cd6dbec43966 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -311,7 +311,9 @@ export function tryNodeResolve( `${chalk.green(`import { ... } from "${pkg.data.name}"`)}\n\n` + `If the used import is not exported from the package's main entry ` + `and can only be attained via deep import, you can explicitly add ` + - `the deep import path to "optimizeDeps.include" in vite.config.js.` + `the deep import path to "optimizeDeps.include" in vite.config.js.\n\n` + + `If you intend to only use deep imports with this package and it ` + + `exposes valid ESM, consider adding it to "optimizeDeps.exclude".` ) ) } From 3dd193de606d8d75b06f5ffb6f277fa9f511dd35 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 23:16:16 -0500 Subject: [PATCH 216/514] release: v2.0.0-beta.38 --- packages/vite/CHANGELOG.md | 30 ++++++++++++++++++++ packages/vite/LICENSE.md | 58 -------------------------------------- packages/vite/package.json | 2 +- 3 files changed, 31 insertions(+), 59 deletions(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index a676a312b14fd1..a6b1efc8352341 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,33 @@ +# [2.0.0-beta.38](https://github.com/vitejs/vite/compare/v2.0.0-beta.37...v2.0.0-beta.38) (2021-01-23) + + +### Bug Fixes + +* **dev:** remove comment for sourcemap reference at debug ([#1658](https://github.com/vitejs/vite/issues/1658)) ([16248c0](https://github.com/vitejs/vite/commit/16248c02844c5447eeb7c441cc4b051becef2346)) +* **optimizer:** improve exports analysis ([406cbea](https://github.com/vitejs/vite/commit/406cbeaa4f52472ce356980840f1a2a824eaa497)) +* **ssr:** fix ssr transform edge cases ([f22ddbd](https://github.com/vitejs/vite/commit/f22ddbdb52d4579a5756215c320a13cd674a38a0)), closes [#1646](https://github.com/vitejs/vite/issues/1646) +* exclude spa-fallback middleware in middlewareMode ([#1645](https://github.com/vitejs/vite/issues/1645)) ([843c879](https://github.com/vitejs/vite/commit/843c87915082b36f7d1ffeb81515b45d5d65aabb)) + + +### Code Refactoring + +* remove optimizeDeps.plugins ([38524f6](https://github.com/vitejs/vite/commit/38524f6c6e864f9805dd0083da1dfa8ce20fa816)) + + +### Features + +* esbuild based dep pre-bundling ([6e7f652](https://github.com/vitejs/vite/commit/6e7f652d89dde43806a2323560486c9b4b771a35)) +* support `base` option during dev, deprecate `build.base` ([#1556](https://github.com/vitejs/vite/issues/1556)) ([809d4bd](https://github.com/vitejs/vite/commit/809d4bd3bf62d3bc6b35f182178922d2ab2175f1)) + + +### BREAKING CHANGES + +* `optimizeDeps.plugins` has been removed. The dep +optimizer is now using `esbuild`, and all non-js files are automatically +externalized to be processed by Vite's transform pipeline when imported. + + + # [2.0.0-beta.37](https://github.com/vitejs/vite/compare/v2.0.0-beta.35...v2.0.0-beta.37) (2021-01-22) diff --git a/packages/vite/LICENSE.md b/packages/vite/LICENSE.md index 825821c0b8385b..0d7b086382d65c 100644 --- a/packages/vite/LICENSE.md +++ b/packages/vite/LICENSE.md @@ -295,35 +295,6 @@ Repository: rollup/plugins --------------------------------------- -## @rollup/plugin-json -License: MIT -By: rollup -Repository: rollup/plugins - -> The MIT License (MIT) -> -> Copyright (c) 2019 RollupJS Plugin Contributors (https://github.com/rollup/plugins/graphs/contributors) -> -> Permission is hereby granted, free of charge, to any person obtaining a copy -> of this software and associated documentation files (the "Software"), to deal -> in the Software without restriction, including without limitation the rights -> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -> copies of the Software, and to permit persons to whom the Software is -> furnished to do so, subject to the following conditions: -> -> The above copyright notice and this permission notice shall be included in -> all copies or substantial portions of the Software. -> -> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -> THE SOFTWARE. - ---------------------------------------- - ## @rollup/pluginutils License: MIT By: Rich Harris @@ -2361,35 +2332,6 @@ Repository: sindresorhus/is-wsl --------------------------------------- -## isbuiltin -License: MIT -By: Deepak Kapoor -Repository: git+https://github.com/deepak-kapoor/is-builtin.git - -> The MIT License (MIT) -> -> Copyright (c) 2016 Deepak Kapoor -> -> Permission is hereby granted, free of charge, to any person obtaining a copy -> of this software and associated documentation files (the "Software"), to deal -> in the Software without restriction, including without limitation the rights -> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -> copies of the Software, and to permit persons to whom the Software is -> furnished to do so, subject to the following conditions: -> -> The above copyright notice and this permission notice shall be included in all -> copies or substantial portions of the Software. -> -> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -> SOFTWARE. - ---------------------------------------- - ## isexe License: ISC By: Isaac Z. Schlueter diff --git a/packages/vite/package.json b/packages/vite/package.json index b6f648cd892c9f..e87bf8631f04cb 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.37", + "version": "2.0.0-beta.38", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 6e832bae3339a440eacc70d84d0717f7976dad73 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 23:37:29 -0500 Subject: [PATCH 217/514] docs: we got search! --- docs/.vitepress/config.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index 3b77732dfd7662..a1e1f953387127 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -20,9 +20,14 @@ module.exports = { editLinks: true, editLinkText: 'Suggest changes to this page', + algolia: { + apiKey: 'b573aa848fd57fb47d693b531297403c', + indexName: 'vitejs' + }, + nav: [ - { text: 'Guide & APIs', link: '/guide/' }, - { text: 'Config Reference', link: '/config/' }, + { text: 'Guide', link: '/guide/' }, + { text: 'Config', link: '/config/' }, { text: 'Plugins', link: '/plugins/' }, { text: 'Changelog', @@ -80,10 +85,6 @@ module.exports = { { text: 'APIs', children: [ - { - text: 'Config Reference', - link: '/config/' - }, { text: 'Plugin API', link: '/guide/api-plugin' @@ -95,6 +96,10 @@ module.exports = { { text: 'JavaScript API', link: '/guide/api-javascript' + }, + { + text: 'Config Reference', + link: '/config/' } ] } From 8693c362ab03f644ae69d4d3d03b59f94fe66beb Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Jan 2021 23:43:56 -0500 Subject: [PATCH 218/514] docs: ads --- docs/.vitepress/config.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index a1e1f953387127..f5fc40ff07a5bf 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -10,7 +10,7 @@ module.exports = { [ 'style', {}, - 'img { border-radius: 10px }' + 'h1.title { margin-left: 0.5em }' + '.content img { border-radius: 10px }' + 'h1.title { margin-left: 0.5em }' ] ], themeConfig: { @@ -25,6 +25,11 @@ module.exports = { indexName: 'vitejs' }, + carbonAds: { + carbon: 'CEBIEK3N', + placement: 'vitejsdev' + }, + nav: [ { text: 'Guide', link: '/guide/' }, { text: 'Config', link: '/config/' }, From c30f6d7a2e2ab24b68a8c024644ee1ccb67925af Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 00:00:14 -0500 Subject: [PATCH 219/514] chore: do not error on failed load --- .../vite/src/node/server/transformRequest.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index d263852609c91d..6c042377c60e07 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -98,12 +98,16 @@ export async function transformRequest( } } if (code == null) { - const msg = checkPublicFile(url, root) - ? `This file is in /public and will be copied as-is during build without ` + - `going through the plugin transforms, and therefore should not be ` + - `imported from source code. It can only be referenced via HTML tags.` - : `Does the file exist?` - throw new Error(`Failed to load url ${url} (resolved id: ${id}). ${msg}`) + if (checkPublicFile(url, root)) { + throw new Error( + `Failed to load url ${url} (resolved id: ${id}). ` + + `This file is in /public and will be copied as-is during build without ` + + `going through the plugin transforms, and therefore should not be ` + + `imported from source code. It can only be referenced via HTML tags.` + ) + } else { + return null + } } // ensure module in graph after successful load From 80473c1423209824d143df77b38f1bdb8723f47b Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 00:06:16 -0500 Subject: [PATCH 220/514] fix(ssr): remove import query in ssrLoadModule --- packages/vite/src/node/ssr/ssrModuleLoader.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/ssr/ssrModuleLoader.ts b/packages/vite/src/node/ssr/ssrModuleLoader.ts index 5cd97ce31e164a..6dc1ff2869b6ca 100644 --- a/packages/vite/src/node/ssr/ssrModuleLoader.ts +++ b/packages/vite/src/node/ssr/ssrModuleLoader.ts @@ -1,6 +1,6 @@ import path from 'path' import { ViteDevServer } from '..' -import { resolveFrom } from '../utils' +import { removeImportQuery, resolveFrom } from '../utils' import { ssrRewriteStacktrace } from './ssrStacktrace' import { ssrExportAllKey, @@ -22,6 +22,8 @@ export async function ssrLoadModule( context: SSRContext = { global: isolated ? Object.create(global) : global }, urlStack: string[] = [] ): Promise> { + url = removeImportQuery(url) + if (urlStack.includes(url)) { server.config.logger.warn( `Circular dependency: ${urlStack.join(' -> ')} -> ${url}` From ce2d49ab396aa7b4ed582650e569d7f2f6d3ef9f Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 00:20:34 -0500 Subject: [PATCH 221/514] fix: file dir resolve should prioritize package.json --- packages/vite/src/node/plugins/resolve.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 58cd6dbec43966..6b9f036276111c 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -252,16 +252,16 @@ function tryResolveFile( if (fs.existsSync(file)) { const isDir = fs.statSync(file).isDirectory() if (isDir) { - if (tryIndex) { - const index = tryFsResolve(file + '/index', isProduction, false) - if (index) return normalizePath(index) + query - } const pkgPath = file + '/package.json' if (fs.existsSync(pkgPath)) { // path points to a node package const pkg = loadPackageData(pkgPath) return resolvePackageEntry(file, pkg, isProduction) } + if (tryIndex) { + const index = tryFsResolve(file + '/index', isProduction, false) + if (index) return normalizePath(index) + query + } } else { return normalizePath(file) + query } From 3955fe37fe4498e6c7df122376a942d63afe6acb Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 00:43:55 -0500 Subject: [PATCH 222/514] fix(ssr): avoid resolving externals to mjs --- packages/vite/src/node/ssr/ssrModuleLoader.ts | 2 +- packages/vite/src/node/utils.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/ssr/ssrModuleLoader.ts b/packages/vite/src/node/ssr/ssrModuleLoader.ts index 6dc1ff2869b6ca..8fba4ee086955f 100644 --- a/packages/vite/src/node/ssr/ssrModuleLoader.ts +++ b/packages/vite/src/node/ssr/ssrModuleLoader.ts @@ -131,7 +131,7 @@ export async function ssrLoadModule( function nodeRequire(id: string, importer: string | null) { const mod = importer - ? require(resolveFrom(id, path.dirname(importer))) + ? require(resolveFrom(id, path.dirname(importer), true)) : require(id) // rollup-style default import interop for cjs return new Proxy(mod, { diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 958f73397596f0..f9ec84603a54c1 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -21,10 +21,12 @@ try { isRunningWithYarnPnp = Boolean(require('pnpapi')) } catch {} -export function resolveFrom(id: string, basedir: string) { +const ssrExtensions = ['.js', '.json', '.node'] + +export function resolveFrom(id: string, basedir: string, ssr = false) { return resolve.sync(id, { basedir, - extensions: SUPPORTED_EXTS, + extensions: ssr ? ssrExtensions : SUPPORTED_EXTS, // necessary to work with pnpm preserveSymlinks: isRunningWithYarnPnp || false }) From 98f60e53312fb3f6aa102f83875595c59bcffbe1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 00:44:11 -0500 Subject: [PATCH 223/514] refactor: server restart handling in middleware mode --- packages/vite/src/node/server/hmr.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/server/hmr.ts b/packages/vite/src/node/server/hmr.ts index 3da7f925a6345d..836acbe3d213e4 100644 --- a/packages/vite/src/node/server/hmr.ts +++ b/packages/vite/src/node/server/hmr.ts @@ -441,6 +441,16 @@ function hasDepsChanged(deps: any, prevDeps: any): boolean { async function restartServer(server: ViteDevServer) { await server.close() ;(global as any).__vite_start_time = Date.now() - server = await createServer(server.config.inlineConfig) - await server.listen() + const newServer = await createServer(server.config.inlineConfig) + for (const key in newServer) { + if (key !== 'app') { + // @ts-ignore + server[key] = newServer[key] + } + } + if (!server.config.server.middlewareMode) { + await server.listen() + } else { + server.config.logger.info('server restarted.', { timestamp: true }) + } } From 36a94560399e03cdbdbdbdb16913c05deb87ab9b Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 00:53:12 -0500 Subject: [PATCH 224/514] fix: hmr port fallback in middlewareMode --- packages/vite/src/node/plugins/clientInjections.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/clientInjections.ts b/packages/vite/src/node/plugins/clientInjections.ts index ed21e81fb0b9cc..ee7e03f5818e72 100644 --- a/packages/vite/src/node/plugins/clientInjections.ts +++ b/packages/vite/src/node/plugins/clientInjections.ts @@ -24,9 +24,8 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin { let port if (config.server.middlewareMode) { port = String( - typeof config.server.hmr === 'object' - ? config.server.hmr.port - : 24678 + (typeof config.server.hmr === 'object' && config.server.hmr.port) || + 24678 ) } else { port = String(options.port || config.server.port!) From 7d261191e5ebf0c2fede0c6fc82137999d58cc5c Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 00:54:38 -0500 Subject: [PATCH 225/514] fix(ssr): do not inject ?import query for ssr transforms fix #1655 --- packages/vite/src/node/plugins/importAnalysis.ts | 6 ++++-- packages/vite/src/node/ssr/ssrModuleLoader.ts | 4 +--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index c0ed57aaaefaea..9a4f3b2b3785ae 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -201,7 +201,9 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { } // mark non-js/css imports with `?import` - url = markExplicitImport(url) + if (!ssr) { + url = markExplicitImport(url) + } // prepend base path without trailing slash ( default empty string ) url = path.posix.join(config.base, url) @@ -381,7 +383,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { // record for HMR import chain analysis importedUrls.add(url) - } else if (!importer.startsWith(clientDir)) { + } else if (!importer.startsWith(clientDir) && !ssr) { if (!hasViteIgnore && !isSupportedDynamicImport(url)) { this.warn( `\n` + diff --git a/packages/vite/src/node/ssr/ssrModuleLoader.ts b/packages/vite/src/node/ssr/ssrModuleLoader.ts index 8fba4ee086955f..eddf4debd060ea 100644 --- a/packages/vite/src/node/ssr/ssrModuleLoader.ts +++ b/packages/vite/src/node/ssr/ssrModuleLoader.ts @@ -1,6 +1,6 @@ import path from 'path' import { ViteDevServer } from '..' -import { removeImportQuery, resolveFrom } from '../utils' +import { resolveFrom } from '../utils' import { ssrRewriteStacktrace } from './ssrStacktrace' import { ssrExportAllKey, @@ -22,8 +22,6 @@ export async function ssrLoadModule( context: SSRContext = { global: isolated ? Object.create(global) : global }, urlStack: string[] = [] ): Promise> { - url = removeImportQuery(url) - if (urlStack.includes(url)) { server.config.logger.warn( `Circular dependency: ${urlStack.join(' -> ')} -> ${url}` From ef1a7e33cc19bac7893bca85b6df14adeb847516 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 01:17:12 -0500 Subject: [PATCH 226/514] fix(optimizer): fix es interop heuristics for entry with only export * from --- packages/vite/src/node/optimizer/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 006e3c13881467..4c0d3ea09a5b8a 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -256,10 +256,10 @@ export async function optimizeDeps( const entry = qualified[id] if (entry.endsWith(relative)) { // check if this is a cjs dep. - const [, exports] = parse(fs.readFileSync(entry, 'utf-8')) + const [imports, exports] = parse(fs.readFileSync(entry, 'utf-8')) data.optimized[id] = { file: absolute, - needsInterop: !exports.length + needsInterop: !exports.length && !imports.length } } } From 523198e86ceba38e139e383b2544d9d6ea0b339a Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 01:21:45 -0500 Subject: [PATCH 227/514] release: v2.0.0-beta.39 --- packages/vite/CHANGELOG.md | 14 ++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index a6b1efc8352341..a9d31b3843dae1 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,17 @@ +# [2.0.0-beta.39](https://github.com/vitejs/vite/compare/v2.0.0-beta.38...v2.0.0-beta.39) (2021-01-23) + + +### Bug Fixes + +* **optimizer:** fix es interop heuristics for entry with only export * from ([ef1a7e3](https://github.com/vitejs/vite/commit/ef1a7e33cc19bac7893bca85b6df14adeb847516)) +* **ssr:** do not inject ?import query for ssr transforms ([7d26119](https://github.com/vitejs/vite/commit/7d261191e5ebf0c2fede0c6fc82137999d58cc5c)), closes [#1655](https://github.com/vitejs/vite/issues/1655) +* hmr port fallback in middlewareMode ([36a9456](https://github.com/vitejs/vite/commit/36a94560399e03cdbdbdbdb16913c05deb87ab9b)) +* **ssr:** avoid resolving externals to mjs ([3955fe3](https://github.com/vitejs/vite/commit/3955fe37fe4498e6c7df122376a942d63afe6acb)) +* file dir resolve should prioritize package.json ([ce2d49a](https://github.com/vitejs/vite/commit/ce2d49ab396aa7b4ed582650e569d7f2f6d3ef9f)) +* **ssr:** remove import query in ssrLoadModule ([80473c1](https://github.com/vitejs/vite/commit/80473c1423209824d143df77b38f1bdb8723f47b)) + + + # [2.0.0-beta.38](https://github.com/vitejs/vite/compare/v2.0.0-beta.37...v2.0.0-beta.38) (2021-01-23) diff --git a/packages/vite/package.json b/packages/vite/package.json index e87bf8631f04cb..43b0affedaf19e 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.38", + "version": "2.0.0-beta.39", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 68266245338d4f1c27d9552d5d54eff3420af8b6 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 01:33:43 -0500 Subject: [PATCH 228/514] fix(optimizer): compiled esmdoule interop close #1659 --- packages/vite/src/node/plugins/importAnalysis.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 9a4f3b2b3785ae..0cd1ba45e3ec80 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -545,12 +545,16 @@ function transformCjsImport( const cjsModuleName = makeLegalIdentifier( `__vite__cjsImport${importIndex}_${rawUrl}` ) - const lines: string[] = [`import ${cjsModuleName} from "${url}";`] + const lines: string[] = [`import ${cjsModuleName} from "${url}"`] importNames.forEach(({ importedName, localName }) => { - if (importedName === '*' || importedName === 'default') { - lines.push(`const ${localName} = ${cjsModuleName};`) + if (importedName === '*') { + lines.push(`const ${localName} = ${cjsModuleName}`) + } else if (importedName === 'default') { + lines.push( + `const ${localName} = ${cjsModuleName}.__esModule ? ${cjsModuleName}.default : ${cjsModuleName}` + ) } else { - lines.push(`const ${localName} = ${cjsModuleName}["${importedName}"];`) + lines.push(`const ${localName} = ${cjsModuleName}["${importedName}"]`) } }) return lines.join('\n') From 2f7ecafa0851c53f206691bbae04b8dde063de6a Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 01:37:12 -0500 Subject: [PATCH 229/514] release: v2.0.0-beta.40 --- packages/vite/CHANGELOG.md | 9 +++++++++ packages/vite/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index a9d31b3843dae1..dd497efc047a13 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,12 @@ +# [2.0.0-beta.40](https://github.com/vitejs/vite/compare/v2.0.0-beta.39...v2.0.0-beta.40) (2021-01-23) + + +### Bug Fixes + +* **optimizer:** compiled esmdoule interop ([6826624](https://github.com/vitejs/vite/commit/68266245338d4f1c27d9552d5d54eff3420af8b6)), closes [#1659](https://github.com/vitejs/vite/issues/1659) + + + # [2.0.0-beta.39](https://github.com/vitejs/vite/compare/v2.0.0-beta.38...v2.0.0-beta.39) (2021-01-23) diff --git a/packages/vite/package.json b/packages/vite/package.json index 43b0affedaf19e..7b068f2d178534 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.39", + "version": "2.0.0-beta.40", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From b15e90e6893582d04f9506ef56cc9d03c9c6d775 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 02:11:11 -0500 Subject: [PATCH 230/514] fix: lower .mjs resolve priority close #1660 --- packages/vite/src/node/optimizer/index.ts | 3 ++- packages/vite/src/node/plugins/resolve.ts | 17 ++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 4c0d3ea09a5b8a..e8467022132981 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -250,11 +250,12 @@ export async function optimizeDeps( await init for (const output in meta.outputs) { + if (/chunk\.\w+\.js$/.test(output)) continue const absolute = normalizePath(path.resolve(output)) const relative = normalizePath(path.relative(cacheDir, absolute)) for (const id in qualified) { const entry = qualified[id] - if (entry.endsWith(relative)) { + if (entry.replace(/\.mjs$/, '.js').endsWith(relative)) { // check if this is a cjs dep. const [imports, exports] = parse(fs.readFileSync(entry, 'utf-8')) data.optimized[id] = { diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 6b9f036276111c..d4371d7eba697e 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -25,11 +25,10 @@ import { PartialResolvedId } from 'rollup' import { isCSSRequest } from './css' import { resolve as _resolveExports } from 'resolve.exports' -const mainFields = [ +const altMainFields = [ 'module', 'jsnext:main', // moment still uses this... - 'jsnext', - 'main' + 'jsnext' ] function resolveExports( @@ -455,7 +454,11 @@ export function resolvePackageEntry( entryPoint = resolveExports(data, '.', isProduction) } - if (!entryPoint) { + // if exports resolved to .mjs, still resolve other fields. + // This is because .mjs files can technically import .cjs files which would + // make them invalid for pure ESM environments - so if other module/browser + // fields are present, prioritize those instead. + if (!entryPoint || entryPoint.endsWith('.mjs')) { // check browser field // https://github.com/defunctzombie/package-browser-field-spec const browserEntry = @@ -492,8 +495,8 @@ export function resolvePackageEntry( } } - if (!entryPoint) { - for (const field of mainFields) { + if (!entryPoint || entryPoint.endsWith('.mjs')) { + for (const field of altMainFields) { if (typeof data[field] === 'string') { entryPoint = data[field] break @@ -501,7 +504,7 @@ export function resolvePackageEntry( } } - entryPoint = entryPoint || 'index.js' + entryPoint = entryPoint || data.main || 'index.js' // resolve object browser field in package.json const { browser: browserField } = data From 69d8d01d3f952a4c7d04574c1da03eece23745f0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 02:19:55 -0500 Subject: [PATCH 231/514] release: v2.0.0-beta.41 --- packages/vite/CHANGELOG.md | 9 +++++++++ packages/vite/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index dd497efc047a13..ad640388223748 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,12 @@ +# [2.0.0-beta.41](https://github.com/vitejs/vite/compare/v2.0.0-beta.40...v2.0.0-beta.41) (2021-01-23) + + +### Bug Fixes + +* lower .mjs resolve priority ([b15e90e](https://github.com/vitejs/vite/commit/b15e90e6893582d04f9506ef56cc9d03c9c6d775)), closes [#1660](https://github.com/vitejs/vite/issues/1660) + + + # [2.0.0-beta.40](https://github.com/vitejs/vite/compare/v2.0.0-beta.39...v2.0.0-beta.40) (2021-01-23) diff --git a/packages/vite/package.json b/packages/vite/package.json index 7b068f2d178534..4b0ef4bf18ed27 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.40", + "version": "2.0.0-beta.41", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From bdb9b3c5a5c8da83d8b8082e936cb3cc16eeb1e0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 02:36:49 -0500 Subject: [PATCH 232/514] fix(optimizer): ensure esbuild use vite-resolved entries --- .../src/node/optimizer/esbuildDepPlugin.ts | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index eaf206b4adcd4a..f1faf398011380 100644 --- a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -32,14 +32,20 @@ export function esbuildDepPlugin( } ) - // record transitive deps build.onResolve({ filter: /^[\w@]/ }, ({ path: id }) => { - if (!(id in qualified) && !isBuiltin(id)) { + // ensure esbuild uses our resolved entires of optimized deps in all + // cases + if (id in qualified) { + return { + path: path.resolve(qualified[id]) + } + } + // record transitive deps + if (!isBuiltin(id)) { const deepMatch = id.match(deepImportRE) const pkgId = deepMatch ? deepMatch[1] || deepMatch[2] : id transitiveOptimized[pkgId] = true } - return null }) // redirect node-builtins to empty module for browser @@ -75,21 +81,6 @@ export function esbuildDepPlugin( } } ) - - if (config.dedupe) { - build.onResolve( - { - filter: new RegExp(`^(${config.dedupe.join('|')})$`) - }, - ({ path: id }) => { - if (id in qualified) { - return { - path: path.resolve(qualified[id]) - } - } - } - ) - } } } } From 7b85755b81882b5998124beb73704a7c03193692 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 02:48:26 -0500 Subject: [PATCH 233/514] release: v2.0.0-beta.42 --- packages/vite/CHANGELOG.md | 9 +++++++++ packages/vite/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index ad640388223748..8dc88c343d74e9 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,12 @@ +# [2.0.0-beta.42](https://github.com/vitejs/vite/compare/v2.0.0-beta.41...v2.0.0-beta.42) (2021-01-23) + + +### Bug Fixes + +* **optimizer:** ensure esbuild use vite-resolved entries ([bdb9b3c](https://github.com/vitejs/vite/commit/bdb9b3c5a5c8da83d8b8082e936cb3cc16eeb1e0)) + + + # [2.0.0-beta.41](https://github.com/vitejs/vite/compare/v2.0.0-beta.40...v2.0.0-beta.41) (2021-01-23) diff --git a/packages/vite/package.json b/packages/vite/package.json index 4b0ef4bf18ed27..30bd2a52903ed9 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.41", + "version": "2.0.0-beta.42", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 4c4d629c391415351c797cf9b9c54d22be6244fe Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 03:25:20 -0500 Subject: [PATCH 234/514] fix(optimizer): force vite resolver for esbuild pre-bundle --- jest.config.js | 2 +- .../__tests__/optimize-deps.spec.ts | 4 +++ packages/playground/optimize-deps/index.html | 9 +++++ .../playground/optimize-deps/package.json | 4 ++- .../src/node/optimizer/esbuildDepPlugin.ts | 35 +++++++++++-------- packages/vite/src/node/optimizer/index.ts | 14 +++++++- yarn.lock | 5 +++ 7 files changed, 55 insertions(+), 18 deletions(-) diff --git a/jest.config.js b/jest.config.js index ad5def4e9542b6..65c89e59fb18f6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,7 @@ module.exports = { preset: 'ts-jest', testMatch: ['**/*.spec.[jt]s?(x)'], - testTimeout: process.env.CI ? 25000 : 10000, + testTimeout: process.env.CI ? 30000 : 10000, globalSetup: './scripts/jestGlobalSetup.js', globalTeardown: './scripts/jestGlobalTeardown.js', testEnvironment: './scripts/jestEnv.js', diff --git a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts b/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts index 65d9a04323299f..788eb2b3200891 100644 --- a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts +++ b/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts @@ -41,3 +41,7 @@ test('dep with css import', async () => { test('dep w/ non-js files handled via plugin', async () => { expect(await page.textContent('.plugin')).toMatch(`[success]`) }) + +test('vue + vuex', async () => { + expect(await page.textContent('.vue')).toMatch(`[success]`) +}) diff --git a/packages/playground/optimize-deps/index.html b/packages/playground/optimize-deps/index.html index ade0515ab11010..f846fb4a3fe5ec 100644 --- a/packages/playground/optimize-deps/index.html +++ b/packages/playground/optimize-deps/index.html @@ -27,6 +27,9 @@

import * as ...

Dep w/ special file format supported via plugins

+

Vue & Vuex

+
+ diff --git a/packages/playground/optimize-deps/package.json b/packages/playground/optimize-deps/package.json index 61f23a59ede4d4..d54cf2d2db08ee 100644 --- a/packages/playground/optimize-deps/package.json +++ b/packages/playground/optimize-deps/package.json @@ -13,6 +13,8 @@ "optimize-deps-linked-include": "0.0.0", "react": "^17.0.1", "react-dom": "^17.0.1", - "resolve-linked": "0.0.0" + "resolve-linked": "0.0.0", + "vue": "^3.0.5", + "vuex": "^4.0.0-rc.2" } } diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index f1faf398011380..50b3537e838585 100644 --- a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -1,10 +1,10 @@ import path from 'path' import { Plugin } from 'esbuild' import { knownAssetTypes } from '../constants' -import builtins from 'builtin-modules' import { ResolvedConfig } from '..' import chalk from 'chalk' import { deepImportRE, isBuiltin } from '../utils' +import { tryNodeResolve } from '../plugins/resolve' const externalTypes = ['css', 'vue', 'svelte', ...knownAssetTypes] @@ -32,28 +32,33 @@ export function esbuildDepPlugin( } ) - build.onResolve({ filter: /^[\w@]/ }, ({ path: id }) => { + build.onResolve({ filter: /^[\w@]/ }, ({ path: id, importer }) => { // ensure esbuild uses our resolved entires of optimized deps in all // cases if (id in qualified) { return { path: path.resolve(qualified[id]) } - } - // record transitive deps - if (!isBuiltin(id)) { + } else if (!isBuiltin(id)) { + // record transitive deps const deepMatch = id.match(deepImportRE) const pkgId = deepMatch ? deepMatch[1] || deepMatch[2] : id transitiveOptimized[pkgId] = true - } - }) - - // redirect node-builtins to empty module for browser - build.onResolve( - { - filter: new RegExp(`^(${builtins.join('|')})$`) - }, - ({ path: id, importer }) => { + const resolved = tryNodeResolve( + id, + path.dirname(importer), + false, + true, + config.dedupe, + config.root + ) + if (resolved) { + return { + path: resolved.id + } + } + } else { + // redirect node-builtins to empty module for browser config.logger.warn( chalk.yellow( `externalized node built-in "${id}" to empty module. ` + @@ -65,7 +70,7 @@ export function esbuildDepPlugin( namespace: 'browser-external' } } - ) + }) build.onLoad( { filter: /.*/, namespace: 'browser-external' }, diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index e8467022132981..7c61024dcb8ac5 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -253,6 +253,7 @@ export async function optimizeDeps( if (/chunk\.\w+\.js$/.test(output)) continue const absolute = normalizePath(path.resolve(output)) const relative = normalizePath(path.relative(cacheDir, absolute)) + const generateExports = meta.outputs[output].exports for (const id in qualified) { const entry = qualified[id] if (entry.replace(/\.mjs$/, '.js').endsWith(relative)) { @@ -260,7 +261,14 @@ export async function optimizeDeps( const [imports, exports] = parse(fs.readFileSync(entry, 'utf-8')) data.optimized[id] = { file: absolute, - needsInterop: !exports.length && !imports.length + needsInterop: + // entry has no ESM syntax - likely CJS or UMD + (!exports.length && !imports.length) || + // if a peer dep used require() on a ESM dep, esbuild turns the + // ESM dep's entry chunk into a single default export... detect + // such cases by checking exports mismatch, and force interop. + (isSingleDefaultExport(generateExports) && + !isSingleDefaultExport(exports)) } } } @@ -269,6 +277,10 @@ export async function optimizeDeps( writeFile(dataPath, JSON.stringify(data, null, 2)) } +function isSingleDefaultExport(exports: string[]) { + return exports.length === 1 && exports[0] === 'default' +} + interface FilteredDeps { qualified: Record external: string[] diff --git a/yarn.lock b/yarn.lock index 5dbc0e97b05d90..29ada72da1c640 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7889,6 +7889,11 @@ vue@^3.0.5: "@vue/runtime-dom" "3.0.5" "@vue/shared" "3.0.5" +vuex@^4.0.0-rc.2: + version "4.0.0-rc.2" + resolved "https://registry.yarnpkg.com/vuex/-/vuex-4.0.0-rc.2.tgz#3681c84eb6f5171b039edaa17cc78105e20724f3" + integrity sha512-HCPzYGea1xL7fMpDoMiHKujC1Bi/HM9LS5ML0Kv55zQtZJvOl0Lq7eWvJoen+SI4Lf7p9V5AqcVsoLPXNBywjg== + w3c-hr-time@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz#0a89cdf5cc15822df9c360543676963e0cc308cd" From ac18c3eb5caec11cebb22eb521a6b610d2dcc151 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 03:29:50 -0500 Subject: [PATCH 235/514] release: v2.0.0-beta.43 --- packages/vite/CHANGELOG.md | 9 +++++++++ packages/vite/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 8dc88c343d74e9..bc7f5e8641051e 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,12 @@ +# [2.0.0-beta.43](https://github.com/vitejs/vite/compare/v2.0.0-beta.42...v2.0.0-beta.43) (2021-01-23) + + +### Bug Fixes + +* **optimizer:** force vite resolver for esbuild pre-bundle ([4c4d629](https://github.com/vitejs/vite/commit/4c4d629c391415351c797cf9b9c54d22be6244fe)) + + + # [2.0.0-beta.42](https://github.com/vitejs/vite/compare/v2.0.0-beta.41...v2.0.0-beta.42) (2021-01-23) diff --git a/packages/vite/package.json b/packages/vite/package.json index 30bd2a52903ed9..d013bd2c5e60b1 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.42", + "version": "2.0.0-beta.43", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 62e4d724a8a008cb6bd6f2122753880ec3568192 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 03:53:38 -0500 Subject: [PATCH 236/514] fix: esbuild dep resolving on windows --- packages/vite/src/node/optimizer/esbuildDepPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index 50b3537e838585..8275100dafd6e5 100644 --- a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -54,7 +54,7 @@ export function esbuildDepPlugin( ) if (resolved) { return { - path: resolved.id + path: path.resolve(resolved.id) } } } else { From 85b4e17642acdc8d70428375880a70ed6727428d Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 03:55:33 -0500 Subject: [PATCH 237/514] chore: improve unwanted dep detection --- packages/vite/src/node/optimizer/index.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 7c61024dcb8ac5..2ebbbeb10cea2f 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -26,14 +26,10 @@ import { init, parse } from 'es-module-lexer' const debug = createDebugger('vite:optimize') -const KNOWN_IGNORE_LIST = new Set([ +const KNOWN_WARN_LIST = new Set([ 'vite', 'vitepress', 'tailwindcss', - '@tailwindcss/ui' -]) - -const KNOWN_WARN_LIST = new Set([ 'sass', 'less', 'stylus', @@ -44,7 +40,7 @@ const KNOWN_WARN_LIST = new Set([ 'typescript' ]) -const WARN_RE = /^(@vitejs\/|@rollup\/|vite-|rollup-|postcss-|babel-)plugin-/ +const WARN_RE = /^(@vitejs\/|@rollup\/|vite-|rollup-|postcss-|babel-)plugin-|^@babel\/|^@tailwindcss\// export interface DepOptimizationOptions { /** @@ -322,10 +318,6 @@ async function resolveQualifiedDeps( debug(`skipping ${id} (link)`) continue } - if (KNOWN_IGNORE_LIST.has(id)) { - debug(`skipping ${id} (internal excluded)`) - continue - } // #804 if (id.startsWith('@types/')) { debug(`skipping ${id} (ts declaration)`) From d85c0883242eb31eb0372cbe45e91285361852c7 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 04:03:26 -0500 Subject: [PATCH 238/514] release: v2.0.0-beta.44 --- packages/vite/CHANGELOG.md | 9 +++++++++ packages/vite/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index bc7f5e8641051e..b463b1e411a82e 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,12 @@ +# [2.0.0-beta.44](https://github.com/vitejs/vite/compare/v2.0.0-beta.43...v2.0.0-beta.44) (2021-01-23) + + +### Bug Fixes + +* esbuild dep resolving on windows ([62e4d72](https://github.com/vitejs/vite/commit/62e4d724a8a008cb6bd6f2122753880ec3568192)) + + + # [2.0.0-beta.43](https://github.com/vitejs/vite/compare/v2.0.0-beta.42...v2.0.0-beta.43) (2021-01-23) diff --git a/packages/vite/package.json b/packages/vite/package.json index d013bd2c5e60b1..4f83ca94518e26 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.43", + "version": "2.0.0-beta.44", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From b9df3f9dd8cc1ccfc68fd2e40d718d1cb39c0f54 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 04:23:10 -0500 Subject: [PATCH 239/514] release: plugin-vue@1.1.1 --- packages/plugin-vue/CHANGELOG.md | 14 ++++++++++++++ packages/plugin-vue/package.json | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/plugin-vue/CHANGELOG.md b/packages/plugin-vue/CHANGELOG.md index a4da0f64a18d88..29f342b309b64f 100644 --- a/packages/plugin-vue/CHANGELOG.md +++ b/packages/plugin-vue/CHANGELOG.md @@ -1,3 +1,17 @@ +## [1.1.1](https://github.com/vitejs/vite/compare/plugin-vue@1.1.0...plugin-vue@1.1.1) (2021-01-23) + + +### Bug Fixes + +* avoid eager hmr api access ([fa37456](https://github.com/vitejs/vite/commit/fa37456584a09b52b39a61760a6d130e261886ff)) + + +### Features + +* support `base` option during dev, deprecate `build.base` ([#1556](https://github.com/vitejs/vite/issues/1556)) ([809d4bd](https://github.com/vitejs/vite/commit/809d4bd3bf62d3bc6b35f182178922d2ab2175f1)) + + + # [1.1.0](https://github.com/vitejs/vite/compare/plugin-vue@1.0.6...plugin-vue@1.1.0) (2021-01-19) diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index f77a415005e589..81a56293a4408d 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-vue", - "version": "1.1.0", + "version": "1.1.1", "license": "MIT", "author": "Evan You", "files": [ From 93da168057abe1ac67b3b4d3adae0979ead0eec1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 04:24:22 -0500 Subject: [PATCH 240/514] release: create-app@1.3.0 --- packages/create-app/CHANGELOG.md | 9 +++++++++ packages/create-app/package.json | 2 +- packages/create-app/template-preact-ts/package.json | 2 +- packages/create-app/template-preact/package.json | 2 +- packages/create-app/template-react-ts/package.json | 2 +- packages/create-app/template-react/package.json | 2 +- packages/create-app/template-vanilla/package.json | 2 +- packages/create-app/template-vue-ts/package.json | 4 ++-- packages/create-app/template-vue/package.json | 4 ++-- 9 files changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/create-app/CHANGELOG.md b/packages/create-app/CHANGELOG.md index c62317f2c64534..e3408f5b7b8d17 100644 --- a/packages/create-app/CHANGELOG.md +++ b/packages/create-app/CHANGELOG.md @@ -1,3 +1,12 @@ +# [1.3.0](https://github.com/vitejs/vite/compare/create-app@1.1.0...create-app@1.3.0) (2021-01-23) + + +### Features + +* add colors to create-app options ([cf7e43f](https://github.com/vitejs/vite/commit/cf7e43f8484e21ebd3efb3c86899eadb4f949848)) + + + # [1.2.0](https://github.com/vitejs/vite/compare/create-app@1.1.0...create-app@1.2.0) (2021-01-08) diff --git a/packages/create-app/package.json b/packages/create-app/package.json index d18be56e6c33f2..1d5ebd03e3a44d 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/create-app", - "version": "1.2.0", + "version": "1.3.0", "license": "MIT", "author": "Evan You", "bin": { diff --git a/packages/create-app/template-preact-ts/package.json b/packages/create-app/template-preact-ts/package.json index c919f16121a895..19934ef3510e5e 100644 --- a/packages/create-app/template-preact-ts/package.json +++ b/packages/create-app/template-preact-ts/package.json @@ -11,6 +11,6 @@ "devDependencies": { "@prefresh/vite": "^2.0.0", "typescript": "^4.1.3", - "vite": "^2.0.0-beta.12" + "vite": "^2.0.0-beta.44" } } \ No newline at end of file diff --git a/packages/create-app/template-preact/package.json b/packages/create-app/template-preact/package.json index c9d0a3bd5c8615..eeae1444238521 100644 --- a/packages/create-app/template-preact/package.json +++ b/packages/create-app/template-preact/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@prefresh/vite": "^2.0.0", - "vite": "^2.0.0-beta.12" + "vite": "^2.0.0-beta.44" } } \ No newline at end of file diff --git a/packages/create-app/template-react-ts/package.json b/packages/create-app/template-react-ts/package.json index 54647816727875..46a73396e1d467 100644 --- a/packages/create-app/template-react-ts/package.json +++ b/packages/create-app/template-react-ts/package.json @@ -14,6 +14,6 @@ "@types/react-dom": "^17.0.0", "@vitejs/plugin-react-refresh": "^1.1.0", "typescript": "^4.1.2", - "vite": "^2.0.0-beta.12" + "vite": "^2.0.0-beta.44" } } \ No newline at end of file diff --git a/packages/create-app/template-react/package.json b/packages/create-app/template-react/package.json index 1dba355f4a5bdc..958f5f184a2f85 100644 --- a/packages/create-app/template-react/package.json +++ b/packages/create-app/template-react/package.json @@ -11,6 +11,6 @@ }, "devDependencies": { "@vitejs/plugin-react-refresh": "^1.1.0", - "vite": "^2.0.0-beta.12" + "vite": "^2.0.0-beta.44" } } \ No newline at end of file diff --git a/packages/create-app/template-vanilla/package.json b/packages/create-app/template-vanilla/package.json index 80e49fcbe6774b..b78385fc15961a 100644 --- a/packages/create-app/template-vanilla/package.json +++ b/packages/create-app/template-vanilla/package.json @@ -6,6 +6,6 @@ "build": "vite build" }, "devDependencies": { - "vite": "^2.0.0-beta.12" + "vite": "^2.0.0-beta.44" } } \ No newline at end of file diff --git a/packages/create-app/template-vue-ts/package.json b/packages/create-app/template-vue-ts/package.json index e09592581562ef..0ae26272525729 100644 --- a/packages/create-app/template-vue-ts/package.json +++ b/packages/create-app/template-vue-ts/package.json @@ -9,11 +9,11 @@ "vue": "^3.0.5" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.0.4", + "@vitejs/plugin-vue": "^1.1.1", "@vue/compiler-sfc": "^3.0.5", "@vuedx/typecheck": "^0.4.1", "@vuedx/typescript-plugin-vue": "^0.4.1", "typescript": "^4.1.3", - "vite": "^2.0.0-beta.12" + "vite": "^2.0.0-beta.44" } } \ No newline at end of file diff --git a/packages/create-app/template-vue/package.json b/packages/create-app/template-vue/package.json index fa19c11ebeee79..f00beb9174e2d0 100644 --- a/packages/create-app/template-vue/package.json +++ b/packages/create-app/template-vue/package.json @@ -9,8 +9,8 @@ "vue": "^3.0.5" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.0.4", + "@vitejs/plugin-vue": "^1.1.1", "@vue/compiler-sfc": "^3.0.5", - "vite": "^2.0.0-beta.12" + "vite": "^2.0.0-beta.44" } } \ No newline at end of file From 2824d067d5239b506f93dc9c073c21d7e059bbe3 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 13:47:21 -0500 Subject: [PATCH 241/514] fix(optimizer): repsect alias in pre-bundling fix #1674 --- packages/vite/src/node/optimizer/esbuildDepPlugin.ts | 8 ++++++-- packages/vite/src/node/optimizer/index.ts | 9 ++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index 8275100dafd6e5..68583a70c5dfaa 100644 --- a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -5,13 +5,15 @@ import { ResolvedConfig } from '..' import chalk from 'chalk' import { deepImportRE, isBuiltin } from '../utils' import { tryNodeResolve } from '../plugins/resolve' +import { PluginContainer } from '../server/pluginContainer' const externalTypes = ['css', 'vue', 'svelte', ...knownAssetTypes] export function esbuildDepPlugin( qualified: Record, config: ResolvedConfig, - transitiveOptimized: Record + transitiveOptimized: Record, + aliasResolver: PluginContainer ): Plugin { return { name: 'vite:dep-pre-bundle', @@ -32,7 +34,7 @@ export function esbuildDepPlugin( } ) - build.onResolve({ filter: /^[\w@]/ }, ({ path: id, importer }) => { + build.onResolve({ filter: /^[\w@]/ }, async ({ path: id, importer }) => { // ensure esbuild uses our resolved entires of optimized deps in all // cases if (id in qualified) { @@ -44,6 +46,8 @@ export function esbuildDepPlugin( const deepMatch = id.match(deepImportRE) const pkgId = deepMatch ? deepMatch[1] || deepMatch[2] : id transitiveOptimized[pkgId] = true + + id = (await aliasResolver.resolveId(id))?.id || id const resolved = tryNodeResolve( id, path.dirname(importer), diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 2ebbbeb10cea2f..1d6120b0f67913 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -239,7 +239,14 @@ export async function optimizeDeps( define: { 'process.env.NODE_ENV': '"development"' }, - plugins: [esbuildDepPlugin(qualified, config, data.transitiveOptimized)] + plugins: [ + esbuildDepPlugin( + qualified, + config, + data.transitiveOptimized, + aliasResolver + ) + ] }) const meta = JSON.parse(fs.readFileSync(esbuildMetaPath, 'utf-8')) From 01e9ac0222dcc36c075c25e3fe8f7e8881867e9c Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 14:21:51 -0500 Subject: [PATCH 242/514] fix: revert trailing slash handling + improve dev base usage fix #1664 --- packages/playground/html/index.html | 4 ++-- packages/vite/src/node/server/index.ts | 7 ++++++- .../vite/src/node/server/middlewares/base.ts | 17 ++++++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/playground/html/index.html b/packages/playground/html/index.html index 391521a34bb28e..b0b5947debd00c 100644 --- a/packages/playground/html/index.html +++ b/packages/playground/html/index.html @@ -1,7 +1,7 @@ - +

Hello

- + diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 557e30b1ccf5a8..5dd30944e1e384 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -406,7 +406,12 @@ export async function createServer( { from: /\/$/, to({ parsedUrl }: any) { - return parsedUrl.pathname + 'index.html' + const rewritten = parsedUrl.pathname + 'index.html' + if (fs.existsSync(path.join(root, rewritten))) { + return rewritten + } else { + return `/index.html` + } } } ] diff --git a/packages/vite/src/node/server/middlewares/base.ts b/packages/vite/src/node/server/middlewares/base.ts index 6bf124a1a4b073..7a9dddeeb893bd 100644 --- a/packages/vite/src/node/server/middlewares/base.ts +++ b/packages/vite/src/node/server/middlewares/base.ts @@ -15,13 +15,24 @@ export function baseMiddleware({ const path = parsed.pathname || '/' if (path.startsWith(base)) { - // rewrite url to remove base.. this ensures that other middleware does not need to consider base being prepended or not + // rewrite url to remove base.. this ensures that other middleware does + // not need to consider base being prepended or not req.url = url.replace(base, '/') } else if (path === '/' || path === '/index.html') { - // to prevent confusion, do not allow access at / if we have specified a base path - res.statusCode = 404 + // redirect root visit to based url + res.writeHead(302, { + Location: base + }) res.end() return + } else if (req.headers.accept?.includes('text/html')) { + // non-based page visit + res.statusCode = 404 + res.end( + `The server is configured with a public base URL of ${base} - ` + + `did you mean to visit ${base}${url.slice(1)} instead?` + ) + return } next() From 73066105727e669fe15d926fbe07d1788a469844 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 15:01:51 -0500 Subject: [PATCH 243/514] fix(html): ensure quote in rebased asset urls in html fix #1668 --- packages/vite/src/node/plugins/html.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index 874cb19804ff15..d371ec4bbfde6c 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -159,7 +159,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { s.overwrite( src!.value!.loc.start.offset, src!.value!.loc.end.offset, - config.base + url.slice(1) + `"${config.base + url.slice(1)}"` ) } @@ -201,7 +201,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { s.overwrite( p.value.loc.start.offset, p.value.loc.end.offset, - config.base + url.slice(1) + `"${config.base + url.slice(1)}"` ) } } @@ -220,11 +220,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { for (const attr of assetUrls) { const value = attr.value! const url = await urlToBuiltUrl(value.content, id, config, this) - s.overwrite( - value.loc.start.offset, - value.loc.end.offset, - JSON.stringify(url) - ) + s.overwrite(value.loc.start.offset, value.loc.end.offset, `"${url}"`) } processedHtml.set(id, s.toString()) From 00bc4466567bd5613d67abd1bdf46d9c9cb23a80 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 15:48:07 -0500 Subject: [PATCH 244/514] fix: support empty, relative and external base values close #1669 --- docs/config/index.md | 8 +++- packages/vite/src/node/config.ts | 69 ++++++++++++++++++++++----- packages/vite/src/node/plugins/css.ts | 38 +++++++++++---- 3 files changed, 94 insertions(+), 21 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 9d46f835bd66dc..9515267dd0313c 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -103,7 +103,13 @@ export default ({ command, mode }) => { - **Type:** `string` - **Default:** `/` - Base public path when served in development or production. Note the path should start and end with `/`. See [Public Base Path](/guide/build#public-base-path) for more details. + Base public path when served in development or production. Valid values include: + + - Absolute URL pathname, e.g. `/foo/` + - Full URL, e.g. `https://foo.com/` + - Empty string or `./` (for embedded deployment) + + See [Public Base Path](/guide/build#public-base-path) for more details. ### mode diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 4111fc54341be5..1e05703c6b7452 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -5,7 +5,13 @@ import Rollup from 'rollup' import { BuildOptions, resolveBuildOptions } from './build' import { ServerOptions } from './server' import { CSSOptions } from './plugins/css' -import { createDebugger, isObject, lookupFile, normalizePath } from './utils' +import { + createDebugger, + isExternalUrl, + isObject, + lookupFile, + normalizePath +} from './utils' import { resolvePlugins } from './plugins' import chalk from 'chalk' import { @@ -23,6 +29,7 @@ import { createLogger, Logger, LogLevel } from './logger' import { DepOptimizationOptions } from './optimizer' import { createFilter } from '@rollup/pluginutils' import { ResolvedBuildOptions } from '.' +import { parse as parseUrl } from 'url' const debug = createDebugger('vite:config') @@ -238,16 +245,7 @@ export async function resolveConfig( config.base = config.build.base } - let BASE_URL = config.base || '/' - if (!BASE_URL.startsWith('/') || !BASE_URL.endsWith('/')) { - logger.warn( - chalk.bold.yellow( - `(!) "base" config option should start and end with "/".` - ) - ) - if (!BASE_URL.startsWith('/')) BASE_URL = '/' + BASE_URL - if (!BASE_URL.endsWith('/')) BASE_URL = BASE_URL + '/' - } + const BASE_URL = resolveBaseUrl(config.base, command === 'build', logger) const resolvedBuildOptions = resolveBuildOptions(config.build) @@ -339,6 +337,55 @@ export async function resolveConfig( return resolved } +/** + * Resolve base. Note that some users use Vite to build for non-web targets like + * electron or expects to deploy + */ +function resolveBaseUrl( + base: UserConfig['base'] = '/', + isBuild: boolean, + logger: Logger +): string { + // #1669 special treatment for empty for same dir relative base + if (base === '' || base === './') { + return isBuild ? base : '/' + } + if (base.startsWith('.')) { + logger.warn( + chalk.yellow.bold( + `(!) invalid "base" option: ${base}. The value can only be an absolute ` + + `URL, ./, or an empty string.` + ) + ) + base = '/' + } + + // external URL + if (isExternalUrl(base)) { + if (!isBuild) { + // get base from full url during dev + const parsed = parseUrl(base) + base = parsed.pathname || '/' + } + } else { + // ensure leading slash + if (!base.startsWith('/')) { + logger.warn( + chalk.yellow.bold(`(!) "base" option should start with a slash.`) + ) + base = '/' + base + } + } + + // ensure ending slash + if (!base.endsWith('/')) { + logger.warn(chalk.yellow.bold(`(!) "base" option should end with a slash.`)) + base += '/' + } + + return base +} + export function mergeConfig( a: Record, b: Record, diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index b17aa65b726677..dcfb561f7de83f 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -15,6 +15,7 @@ import postcssrc from 'postcss-load-config' import merge from 'merge-source-map' import { NormalizedOutputOptions, + PluginContext, RenderedChunk, RollupError, SourceMap @@ -238,21 +239,13 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { return null } - // replace asset url references with resolved url - chunkCSS = chunkCSS.replace(assetUrlRE, (_, fileId, postfix = '') => { - return config.base + this.getFileName(fileId) + postfix - }) - if (config.build.cssCodeSplit) { if (!code.trim()) { // this is a shared CSS-only chunk that is empty. emptyChunks.add(chunk.fileName) } - // minify - if (config.build.minify) { - chunkCSS = await minifyCSS(chunkCSS, config) - } if (opts.format === 'es') { + chunkCSS = await processChunkCSS(chunkCSS, config, this, false) // emit corresponding css file const fileHandle = this.emitFile({ name: chunk.name + '.css', @@ -262,6 +255,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { chunkToEmittedCssFileMap.set(chunk, fileHandle) } else if (!config.build.ssr) { // legacy build, inline css + chunkCSS = await processChunkCSS(chunkCSS, config, this, true) const style = `__vite_style__` const injectCode = `var ${style} = document.createElement('style');` + @@ -284,6 +278,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } } else { const extractedCss = outputToExtractedCSSMap.get(opts) || '' + chunkCSS = await processChunkCSS(chunkCSS, config, this, false) outputToExtractedCSSMap.set(opts, extractedCss + chunkCSS) return null } @@ -739,6 +734,31 @@ function rewriteCssUrls( }) } +async function processChunkCSS( + css: string, + config: ResolvedConfig, + pluginCtx: PluginContext, + isInlined: boolean +): Promise { + // replace asset url references with resolved url. + const isRelativeBase = config.base === '' || config.base.startsWith('.') + css = css.replace(assetUrlRE, (_, fileId, postfix = '') => { + const filename = pluginCtx.getFileName(fileId) + postfix + if (!isRelativeBase || isInlined) { + // absoulte base or relative base but inlined (injected as style tag into + // index.html) use the base as-is + return config.base + filename + } else { + // relative base + extracted CSS - asset file will be in the same dir + return `./${path.posix.basename(filename)}` + } + }) + if (config.build.minify) { + css = await minifyCSS(css, config) + } + return css +} + let CleanCSS: any async function minifyCSS(css: string, config: ResolvedConfig) { From 226e9849253677770f11f8a26e6ec205067dc902 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 24 Jan 2021 05:00:26 +0800 Subject: [PATCH 245/514] fix(import-anaysis): markPos out-of-range for overwrite (#1671) --- .../src/node/plugins/importAnaysisBuild.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnaysisBuild.ts b/packages/vite/src/node/plugins/importAnaysisBuild.ts index 52fb5841ca2a35..06dc29a3b8b6e4 100644 --- a/packages/vite/src/node/plugins/importAnaysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnaysisBuild.ts @@ -186,7 +186,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { for (let index = 0; index < imports.length; index++) { const { s: start, e: end, d: dynamicIndex } = imports[index] if (dynamicIndex > -1) { - // if dynmamic import polyfill is used, rewrite the import to + // if dynamic import polyfill is used, rewrite the import to // use the polyfilled function. if (isPolyfillEnabled) { s.overwrite(dynamicIndex, dynamicIndex + 6, `__import__`) @@ -218,15 +218,17 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { } const markPos = code.indexOf(preloadMarker, end) - s.overwrite( - markPos - 1, - markPos + preloadMarker.length + 1, - // the dep list includes the main chunk, so only need to - // preload when there are actual other deps. - deps.size > 1 - ? `[${[...deps].map((d) => JSON.stringify(d)).join(',')}]` - : `void 0` - ) + if (markPos > 0) { + s.overwrite( + markPos - 1, + markPos + preloadMarker.length + 1, + // the dep list includes the main chunk, so only need to + // preload when there are actual other deps. + deps.size > 1 + ? `[${[...deps].map((d) => JSON.stringify(d)).join(',')}]` + : `void 0` + ) + } } } chunk.code = s.toString() From d4909b936994d4fec37dfbafd27cd24494de8d14 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 21:07:57 -0500 Subject: [PATCH 246/514] fix: import analysis dynamic import check --- .../src/node/plugins/importAnaysisBuild.ts | 80 +++++++++---------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnaysisBuild.ts b/packages/vite/src/node/plugins/importAnaysisBuild.ts index 06dc29a3b8b6e4..91c4c049b5fae3 100644 --- a/packages/vite/src/node/plugins/importAnaysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnaysisBuild.ts @@ -176,7 +176,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { const code = chunk.code let imports: ImportSpecifier[] try { - imports = parseImports(code)[0] + imports = parseImports(code)[0].filter((i) => i.d > -1) } catch (e) { this.error(e, e.idx) } @@ -185,50 +185,48 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { const s = new MagicString(code) for (let index = 0; index < imports.length; index++) { const { s: start, e: end, d: dynamicIndex } = imports[index] - if (dynamicIndex > -1) { - // if dynamic import polyfill is used, rewrite the import to - // use the polyfilled function. - if (isPolyfillEnabled) { - s.overwrite(dynamicIndex, dynamicIndex + 6, `__import__`) - } - // check the chunk being imported - const url = code.slice(start, end) - const deps: Set = new Set() - - if (url[0] === `"` && url[url.length - 1] === `"`) { - const ownerFilename = chunk.fileName - // literal import - trace direct imports and add to deps - const addDeps = (filename: string) => { - if (filename === ownerFilename) return - const chunk = bundle[filename] as OutputChunk | undefined - if (chunk) { - deps.add(config.base + chunk.fileName) - const cssId = chunkToEmittedCssFileMap.get(chunk) - if (cssId) { - deps.add(config.base + this.getFileName(cssId)) - } - chunk.imports.forEach(addDeps) + // if dynamic import polyfill is used, rewrite the import to + // use the polyfilled function. + if (isPolyfillEnabled) { + s.overwrite(dynamicIndex, dynamicIndex + 6, `__import__`) + } + // check the chunk being imported + const url = code.slice(start, end) + const deps: Set = new Set() + + if (url[0] === `"` && url[url.length - 1] === `"`) { + const ownerFilename = chunk.fileName + // literal import - trace direct imports and add to deps + const addDeps = (filename: string) => { + if (filename === ownerFilename) return + const chunk = bundle[filename] as OutputChunk | undefined + if (chunk) { + deps.add(config.base + chunk.fileName) + const cssId = chunkToEmittedCssFileMap.get(chunk) + if (cssId) { + deps.add(config.base + this.getFileName(cssId)) } + chunk.imports.forEach(addDeps) } - const normalizedFile = path.posix.join( - path.posix.dirname(chunk.fileName), - url.slice(1, -1) - ) - addDeps(normalizedFile) } + const normalizedFile = path.posix.join( + path.posix.dirname(chunk.fileName), + url.slice(1, -1) + ) + addDeps(normalizedFile) + } - const markPos = code.indexOf(preloadMarker, end) - if (markPos > 0) { - s.overwrite( - markPos - 1, - markPos + preloadMarker.length + 1, - // the dep list includes the main chunk, so only need to - // preload when there are actual other deps. - deps.size > 1 - ? `[${[...deps].map((d) => JSON.stringify(d)).join(',')}]` - : `void 0` - ) - } + const markPos = code.indexOf(preloadMarker, end) + if (markPos > 0) { + s.overwrite( + markPos - 1, + markPos + preloadMarker.length + 1, + // the dep list includes the main chunk, so only need to + // preload when there are actual other deps. + deps.size > 1 + ? `[${[...deps].map((d) => JSON.stringify(d)).join(',')}]` + : `void 0` + ) } } chunk.code = s.toString() From f6b58a0f535b1c26f9c1dfda74c28c685402c3c9 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 21:24:09 -0500 Subject: [PATCH 247/514] feat: default vendor chunk splitting --- jest.config.js | 4 +++- package.json | 2 +- packages/plugin-legacy/index.js | 3 ++- packages/vite/src/node/build.ts | 42 ++++++++++++++++++++++++++++++--- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/jest.config.js b/jest.config.js index 65c89e59fb18f6..56f9d45ff5a0aa 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,8 @@ module.exports = { preset: 'ts-jest', - testMatch: ['**/*.spec.[jt]s?(x)'], + testMatch: process.env.VITE_TEST_BUILD + ? ['**/playground/**/*.spec.[jt]s?(x)'] + : ['**/*.spec.[jt]s?(x)'], testTimeout: process.env.CI ? 30000 : 10000, globalSetup: './scripts/jestGlobalSetup.js', globalTeardown: './scripts/jestGlobalTeardown.js', diff --git a/package.json b/package.json index e36a2f2131965d..1b0437597fa0e6 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "test": "run-s test-serve test-build", "test-serve": "jest", "debug-serve": "cross-env VITE_DEBUG_SERVE=1 node --inspect-brk ./node_modules/.bin/jest", - "test-build": "cross-env VITE_TEST_BUILD=1 jest playground", + "test-build": "cross-env VITE_TEST_BUILD=1 jest", "debug-build": "cross-env VITE_TEST_BUILD=1 VITE_PRESERVE_BUILD_ARTIFACTS=1 node --inspect-brk ./node_modules/.bin/jest", "docs": "vitepress dev docs", "build-docs": "vitepress build docs", diff --git a/packages/plugin-legacy/index.js b/packages/plugin-legacy/index.js index 4a3c90a47c4f2e..6be196f756faf6 100644 --- a/packages/plugin-legacy/index.js +++ b/packages/plugin-legacy/index.js @@ -418,7 +418,8 @@ async function buildPolyfillChunk( [name]: polyfillId }, output: { - format: name.includes('legacy') ? 'iife' : 'es' + format: name.includes('legacy') ? 'iife' : 'es', + manualChunks: undefined } } } diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index a2856d1dbb57d0..2385ee60718764 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -10,7 +10,9 @@ import Rollup, { WarningHandler, OutputOptions, RollupOutput, - ExternalOption + ExternalOption, + GetManualChunk, + GetModuleInfo } from 'rollup' import { buildReporterPlugin } from './plugins/reporter' import { buildDefinePlugin } from './plugins/define' @@ -338,8 +340,8 @@ async function doBuild( const generate = (output: OutputOptions = {}) => { return bundle[options.write ? 'write' : 'generate']({ dir: outDir, - format: options.ssr ? 'cjs' : 'es', - exports: options.ssr ? 'named' : 'auto', + format: ssr ? 'cjs' : 'es', + exports: ssr ? 'named' : 'auto', sourcemap: options.sourcemap, name: libOptions ? libOptions.name : undefined, entryFileNames: ssr @@ -359,6 +361,13 @@ async function doBuild( // #1048 add `Symbol.toStringTag` for module default export namespaceToStringTag: true, inlineDynamicImports: ssr && typeof input === 'string', + manualChunks: + !ssr && + !libOptions && + output?.format !== 'umd' && + output?.format !== 'iife' + ? moveToVendorChunk + : undefined, ...output }) } @@ -418,6 +427,33 @@ async function doBuild( } } +const moveToVendorChunk: GetManualChunk = (id, { getModuleInfo }) => { + if (id.includes('node_modules') && !hasDynamicImporter(id, getModuleInfo)) { + return 'vendor' + } +} + +function hasDynamicImporter( + id: string, + getModuleInfo: GetModuleInfo, + importStack: string[] = [] +): boolean { + if (importStack.includes(id)) { + // circular deps! + return false + } + const mod = getModuleInfo(id) + if (!mod) { + return false + } + if (mod.dynamicImporters.length) { + return true + } + return mod.importers.some((importer) => + hasDynamicImporter(importer, getModuleInfo, importStack.concat(id)) + ) +} + function resolveBuildOutputs( outputs: OutputOptions | OutputOptions[] | undefined, libOptions: LibraryOptions | false, From 98c321b3694dc77dd66e8064f14467e909832171 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 21:57:16 -0500 Subject: [PATCH 248/514] feat: support stringifying json close #1672 --- docs/config/index.md | 20 +++++++- packages/vite/src/node/config.ts | 15 ++++-- packages/vite/src/node/plugins/index.ts | 12 +++-- packages/vite/src/node/plugins/json.ts | 68 +++++++++++-------------- 4 files changed, 66 insertions(+), 49 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 9515267dd0313c..30f51264b2db71 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -104,11 +104,11 @@ export default ({ command, mode }) => { - **Default:** `/` Base public path when served in development or production. Valid values include: - + - Absolute URL pathname, e.g. `/foo/` - Full URL, e.g. `https://foo.com/` - Empty string or `./` (for embedded deployment) - + See [Public Base Path](/guide/build#public-base-path) for more details. ### mode @@ -167,6 +167,22 @@ export default ({ command, mode }) => { } ``` +### json.namedExports + +- **Type:** `boolean` +- **Default:** `true` + + Whether to support named imports from `.json` files. + +### json.stringify + +- **Type:** `boolean` +- **Default:** `false` + + If set to `true`, imported JSON will be transformed into `export default JSON.parse("...")` which is significantly more performant than Object literals, espeically when the JSON file is large. + + Enabling this disables named imports. + ### esbuild - **Type:** `ESBuildOptions | false` diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 1e05703c6b7452..880db15f445c99 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -30,6 +30,7 @@ import { DepOptimizationOptions } from './optimizer' import { createFilter } from '@rollup/pluginutils' import { ResolvedBuildOptions } from '.' import { parse as parseUrl } from 'url' +import { JsonOptions } from './plugins/json' const debug = createDebugger('vite:config') @@ -58,6 +59,11 @@ export interface UserConfig { * @default process.cwd() */ root?: string + /** + * Base public path when served in development or production. + * @default '/' + */ + base?: string /** * Explicitly set a mode to run in. This will override the default mode for * each command, and can be overridden by the command line --mode option. @@ -80,6 +86,10 @@ export interface UserConfig { * CSS related options (preprocessors and CSS modules) */ css?: CSSOptions + /** + * JSON loading options + */ + json?: JsonOptions /** * Transform options to pass to esbuild. * Or set to `false` to disable esbuild. @@ -120,11 +130,6 @@ export interface UserConfig { * Default: true */ clearScreen?: boolean - /** - * Base public path when served in development or production. - * @default '/' - */ - base?: string } export interface SSROptions { diff --git a/packages/vite/src/node/plugins/index.ts b/packages/vite/src/node/plugins/index.ts index fe565190732bf4..8d8402570ea053 100644 --- a/packages/vite/src/node/plugins/index.ts +++ b/packages/vite/src/node/plugins/index.ts @@ -45,10 +45,14 @@ export async function resolvePlugins( htmlInlineScriptProxyPlugin(), cssPlugin(config), config.esbuild !== false ? esbuildPlugin(config.esbuild) : null, - jsonPlugin({ - preferConst: true, - namedExports: true - }), + jsonPlugin( + { + preferConst: true, + namedExports: true, + ...config.json + }, + isBuild + ), wasmPlugin(config), webWorkerPlugin(config), assetPlugin(config), diff --git a/packages/vite/src/node/plugins/json.ts b/packages/vite/src/node/plugins/json.ts index a601dda85f1e12..e9e969f485cb35 100644 --- a/packages/vite/src/node/plugins/json.ts +++ b/packages/vite/src/node/plugins/json.ts @@ -6,65 +6,57 @@ * https://github.com/rollup/plugins/blob/master/LICENSE */ -import { createFilter, dataToEsm } from '@rollup/pluginutils' -import { FilterPattern } from '@rollup/pluginutils' +import { dataToEsm } from '@rollup/pluginutils' import { Plugin } from 'rollup' -export interface RollupJsonOptions { - /** - * All JSON files will be parsed by default, - * but you can also specifically include files - */ - include?: FilterPattern - /** - * All JSON files will be parsed by default, - * but you can also specifically exclude files - */ - exclude?: FilterPattern - /** - * For tree-shaking, properties will be declared as variables, using - * either `var` or `const`. - * @default false - */ - preferConst?: boolean - /** - * Specify indentation for the generated default export - * @default '\t' - */ - indent?: string - /** - * Ignores indent and generates the smallest code - * @default false - */ - compact?: boolean +export interface JsonOptions { /** * Generate a named export for every property of the JSON object * @default true */ namedExports?: boolean + /** + * Generate performant output as JSON.parse("stringified"). + * Enabling this will disable namedExports. + * @default false + */ + stringify?: boolean } // Custom json filter for vite const jsonExtRE = new RegExp(`\\.json($|\\?)`) -export function jsonPlugin(options: RollupJsonOptions = {}): Plugin { - const filter = createFilter(options.include, options.exclude) - const indent = 'indent' in options ? options.indent : '\t' - +export function jsonPlugin( + options: JsonOptions = {}, + isBuild: boolean +): Plugin { return { name: 'vite:json', transform(json, id) { - if (!jsonExtRE.test(id) || !filter(id)) return null + if (!jsonExtRE.test(id)) return null try { + if (options.stringify) { + if (isBuild) { + return { + // during build, parse then double-stringify to remove all + // unnecessary whitespaces to reduce bundle size. + code: `export default JSON.parse(${JSON.stringify( + JSON.stringify(JSON.parse(json)) + )})`, + map: { mappings: '' } + } + } else { + return `export default JSON.parse(${JSON.stringify(json)})` + } + } + const parsed = JSON.parse(json) return { code: dataToEsm(parsed, { - preferConst: options.preferConst, - compact: options.compact, - namedExports: options.namedExports, - indent + preferConst: true, + namedExports: options.namedExports }), map: { mappings: '' } } From 629d60b6df761c41f47aab48ce1b1206667ec1ea Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 22:00:13 -0500 Subject: [PATCH 249/514] chore: fix type --- packages/vite/src/node/plugins/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/vite/src/node/plugins/index.ts b/packages/vite/src/node/plugins/index.ts index 8d8402570ea053..1ed0211b279455 100644 --- a/packages/vite/src/node/plugins/index.ts +++ b/packages/vite/src/node/plugins/index.ts @@ -47,7 +47,6 @@ export async function resolvePlugins( config.esbuild !== false ? esbuildPlugin(config.esbuild) : null, jsonPlugin( { - preferConst: true, namedExports: true, ...config.json }, From 63dd1a2829ea0764c12e11f2f3510bc1c096febf Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 22:01:35 -0500 Subject: [PATCH 250/514] feat: disable prompts and clearScreen on CI fix #1673 --- packages/vite/src/node/logger.ts | 2 +- packages/vite/src/node/optimizer/index.ts | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/vite/src/node/logger.ts b/packages/vite/src/node/logger.ts index 73cedc7cd78a9e..1ced609135c252 100644 --- a/packages/vite/src/node/logger.ts +++ b/packages/vite/src/node/logger.ts @@ -41,7 +41,7 @@ export function createLogger( allowClearScreen = true ): Logger { const thresh = LogLevels[level] - const clear = allowClearScreen ? clearScreen : () => {} + const clear = allowClearScreen && !process.env.CI ? clearScreen : () => {} function output(type: LogType, msg: string, options: LogOptions = {}) { if (thresh >= LogLevels[type]) { diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 1d6120b0f67913..00e18251a23188 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -171,18 +171,23 @@ export async function optimizeDeps( ) if (invalidIds.length) { + const msg = + `It seems your dependencies contain packages that are not meant to\n` + + `be used in the browser, e.g. ${chalk.cyan(invalidIds.join(', '))}. ` + + `\nSince vite pre-bundles eligible dependencies to improve performance,\n` + + `they should probably be moved to devDependencies instead.` + + if (process.env.CI) { + logger.error(msg) + process.exit(1) + } + const { yes } = (await prompt({ type: 'confirm', name: 'yes', initial: true, message: chalk.yellow( - `It seems your dependencies contain packages that are not meant to\n` + - `be used in the browser, e.g. ${chalk.cyan( - invalidIds.join(', ') - )}. ` + - `\nSince vite pre-bundles eligible dependencies to improve performance,\n` + - `they should probably be moved to devDependencies instead.\n` + - `Auto-update package.json and continue without these deps?` + msg + `\nAuto-update package.json and continue without these deps?` ) })) as { yes: boolean } if (yes) { From a198990efe4f96c2155928ac23264437d393d54e Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 22:41:40 -0500 Subject: [PATCH 251/514] feat: vite preview command for previewing build output close #1627 --- packages/playground/alias/package.json | 3 +- packages/playground/assets/package.json | 3 +- packages/playground/css/package.json | 3 +- packages/playground/data-uri/package.json | 3 +- packages/playground/define/package.json | 3 +- .../playground/dynamic-import/package.json | 3 +- packages/playground/env/package.json | 3 +- packages/playground/glob-import/package.json | 3 +- packages/playground/hmr/package.json | 3 +- packages/playground/html/package.json | 3 +- packages/playground/json/package.json | 3 +- packages/playground/legacy/package.json | 3 +- packages/playground/lib/package.json | 3 +- .../playground/optimize-deps/package.json | 3 +- packages/playground/react/package.json | 3 +- packages/playground/resolve/package.json | 3 +- packages/playground/vue-jsx/package.json | 3 +- packages/playground/vue/package.json | 3 +- packages/playground/wasm/package.json | 3 +- packages/playground/worker/package.json | 3 +- packages/vite/package.json | 1 + packages/vite/src/node/cli.ts | 27 ++++++++++ packages/vite/src/node/serve.ts | 53 +++++++++++++++++++ .../src/node/server/{https.ts => http.ts} | 28 ++++++++++ packages/vite/src/node/server/index.ts | 27 +--------- packages/vite/types/shims.d.ts | 5 ++ 26 files changed, 155 insertions(+), 46 deletions(-) create mode 100644 packages/vite/src/node/serve.ts rename packages/vite/src/node/server/{https.ts => http.ts} (77%) diff --git a/packages/playground/alias/package.json b/packages/playground/alias/package.json index de2c9f2756b52a..d76e350b2e4c69 100644 --- a/packages/playground/alias/package.json +++ b/packages/playground/alias/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" }, "dependencies": { "vue": "^3.0.5" diff --git a/packages/playground/assets/package.json b/packages/playground/assets/package.json index d49d88090ebd1a..ed26f61e22c261 100644 --- a/packages/playground/assets/package.json +++ b/packages/playground/assets/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" } } \ No newline at end of file diff --git a/packages/playground/css/package.json b/packages/playground/css/package.json index a64c656276955a..7822dfca4ea45a 100644 --- a/packages/playground/css/package.json +++ b/packages/playground/css/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" }, "devDependencies": { "postcss-nested": "^5.0.3" diff --git a/packages/playground/data-uri/package.json b/packages/playground/data-uri/package.json index 6197cbb29e7589..54912c035d44e7 100644 --- a/packages/playground/data-uri/package.json +++ b/packages/playground/data-uri/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" } } \ No newline at end of file diff --git a/packages/playground/define/package.json b/packages/playground/define/package.json index fd68a46c35162d..eed4e7a31eb969 100644 --- a/packages/playground/define/package.json +++ b/packages/playground/define/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" } } diff --git a/packages/playground/dynamic-import/package.json b/packages/playground/dynamic-import/package.json index e6cfed7b7b91fd..91048d3c3b90a2 100644 --- a/packages/playground/dynamic-import/package.json +++ b/packages/playground/dynamic-import/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" } } diff --git a/packages/playground/env/package.json b/packages/playground/env/package.json index 2ced20d5275744..efb93c23954582 100644 --- a/packages/playground/env/package.json +++ b/packages/playground/env/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "cross-env VITE_INLINE=inline-serve vite", "build": "cross-env VITE_INLINE=inline-build vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" }, "devDependencies": { "cross-env": "^7.0.3" diff --git a/packages/playground/glob-import/package.json b/packages/playground/glob-import/package.json index 235656874986be..2910f5f10b88f2 100644 --- a/packages/playground/glob-import/package.json +++ b/packages/playground/glob-import/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" } } diff --git a/packages/playground/hmr/package.json b/packages/playground/hmr/package.json index 97fb6577fb4d28..d16ba46fc693c0 100644 --- a/packages/playground/hmr/package.json +++ b/packages/playground/hmr/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" } } diff --git a/packages/playground/html/package.json b/packages/playground/html/package.json index 6368db40153c7d..db225e882d34dc 100644 --- a/packages/playground/html/package.json +++ b/packages/playground/html/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" } } diff --git a/packages/playground/json/package.json b/packages/playground/json/package.json index 7e20d7591f29de..feae12478e1446 100644 --- a/packages/playground/json/package.json +++ b/packages/playground/json/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" } } diff --git a/packages/playground/legacy/package.json b/packages/playground/legacy/package.json index c0f4f90fa497b7..9c7c676b3d186e 100644 --- a/packages/playground/legacy/package.json +++ b/packages/playground/legacy/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "vite", "build": "vite build --debug legacy", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" }, "devDependencies": { "@vitejs/plugin-legacy": "^1.0.0" diff --git a/packages/playground/lib/package.json b/packages/playground/lib/package.json index dc8a64ad4bbf8d..c6b75f4fa7c6b2 100644 --- a/packages/playground/lib/package.json +++ b/packages/playground/lib/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" } } diff --git a/packages/playground/optimize-deps/package.json b/packages/playground/optimize-deps/package.json index d54cf2d2db08ee..0a9b3eaa25952d 100644 --- a/packages/playground/optimize-deps/package.json +++ b/packages/playground/optimize-deps/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" }, "dependencies": { "axios": "^0.21.1", diff --git a/packages/playground/react/package.json b/packages/playground/react/package.json index 38a33bb6b073d3..9213ed00802ee1 100644 --- a/packages/playground/react/package.json +++ b/packages/playground/react/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" }, "dependencies": { "react": "^17.0.1", diff --git a/packages/playground/resolve/package.json b/packages/playground/resolve/package.json index ad7b8903502fd2..ea9b0598a28442 100644 --- a/packages/playground/resolve/package.json +++ b/packages/playground/resolve/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" }, "dependencies": { "resolve-exports-path": "link:./exports-path", diff --git a/packages/playground/vue-jsx/package.json b/packages/playground/vue-jsx/package.json index 8c1ad4c2d27032..ac4f309ffb58d3 100644 --- a/packages/playground/vue-jsx/package.json +++ b/packages/playground/vue-jsx/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" }, "devDependencies": { "@vitejs/plugin-vue-jsx": "^1.0.0" diff --git a/packages/playground/vue/package.json b/packages/playground/vue/package.json index b9afe797d66a5a..612a8f6a9073e9 100644 --- a/packages/playground/vue/package.json +++ b/packages/playground/vue/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" }, "dependencies": { "vue": "^3.0.5" diff --git a/packages/playground/wasm/package.json b/packages/playground/wasm/package.json index b0603222524f42..4ecd7d5a883564 100644 --- a/packages/playground/wasm/package.json +++ b/packages/playground/wasm/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" } } diff --git a/packages/playground/worker/package.json b/packages/playground/worker/package.json index abf6cfeee5551c..04fd69b27dab34 100644 --- a/packages/playground/worker/package.json +++ b/packages/playground/worker/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "debug": "node --inspect-brk ../../vite/bin/vite" + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" } } diff --git a/packages/vite/package.json b/packages/vite/package.json index 4f83ca94518e26..c67356e833b21f 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -81,6 +81,7 @@ "chalk": "^4.1.0", "chokidar": "^3.4.3", "clean-css": "^4.2.3", + "compression": "^1.7.4", "connect": "^3.7.0", "connect-history-api-fallback": "^1.6.0", "convert-source-map": "^1.7.0", diff --git a/packages/vite/src/node/cli.ts b/packages/vite/src/node/cli.ts index 09fe8a57cb0714..5ff5b56c74709a 100644 --- a/packages/vite/src/node/cli.ts +++ b/packages/vite/src/node/cli.ts @@ -4,6 +4,7 @@ import { BuildOptions } from './build' import { ServerOptions } from './server' import { createLogger, LogLevel } from './logger' import { resolveConfig } from '.' +import { serve } from './serve' const cli = cac('vite') @@ -190,6 +191,32 @@ cli } ) +cli + .command('preview [root]') + .option('--port ', `[number] specify port`) + .action( + async (root: string, options: { port?: number } & GlobalCLIOptions) => { + try { + const config = await resolveConfig( + { + root, + base: options.base, + configFile: options.config, + logLevel: options.logLevel + }, + 'serve', + 'development' + ) + await serve(config, options.port) + } catch (e) { + createLogger(options.logLevel).error( + chalk.red(`error when starting preview server:\n${e.stack}`) + ) + process.exit(1) + } + } + ) + cli.help() cli.version(require('../../package.json').version) diff --git a/packages/vite/src/node/serve.ts b/packages/vite/src/node/serve.ts new file mode 100644 index 00000000000000..e267e48445096c --- /dev/null +++ b/packages/vite/src/node/serve.ts @@ -0,0 +1,53 @@ +import os from 'os' +import path from 'path' +import sirv from 'sirv' +import chalk from 'chalk' +import connect from 'connect' +import compression from 'compression' +import { ResolvedConfig } from '.' +import { Connect } from 'types/connect' +import { resolveHttpServer } from './server/http' + +export async function serve(config: ResolvedConfig, port = 5000) { + const app = connect() as Connect.Server + + app.use(compression()) + + const distDir = path.resolve(config.root, config.build.outDir) + app.use( + config.base, + sirv(distDir, { + etag: true, + single: true + }) + ) + + const server = await resolveHttpServer(config.server, app) + + const options = config.server || {} + const hostname = options.host || 'localhost' + const protocol = options.https ? 'https' : 'http' + const info = config.logger.info + const base = config.base + + server.listen(port, () => { + info(`\n Build preview server running at:\n`) + const interfaces = os.networkInterfaces() + Object.keys(interfaces).forEach((key) => + (interfaces[key] || []) + .filter((details) => details.family === 'IPv4') + .map((detail) => { + return { + type: detail.address.includes('127.0.0.1') + ? 'Local: ' + : 'Network: ', + host: detail.address.replace('127.0.0.1', hostname) + } + }) + .forEach(({ type, host }) => { + const url = `${protocol}://${host}:${chalk.bold(port)}${base}` + info(` > ${type} ${chalk.cyan(url)}`) + }) + ) + }) +} diff --git a/packages/vite/src/node/server/https.ts b/packages/vite/src/node/server/http.ts similarity index 77% rename from packages/vite/src/node/server/https.ts rename to packages/vite/src/node/server/http.ts index 916d872be8d0a2..d701525807b064 100644 --- a/packages/vite/src/node/server/https.ts +++ b/packages/vite/src/node/server/http.ts @@ -1,6 +1,34 @@ import fs from 'fs' import path from 'path' +import { Server as HttpServer } from 'http' import { ServerOptions as HttpsServerOptions } from 'https' +import { ServerOptions } from '..' +import { Connect } from 'types/connect' + +export async function resolveHttpServer( + { https = false, proxy }: ServerOptions, + app: Connect.Server +): Promise { + if (!https) { + return require('http').createServer(app) + } + + const httpsOptions = await resolveHttpsConfig( + typeof https === 'boolean' ? {} : https + ) + if (proxy) { + // #484 fallback to http1 when proxy is needed. + return require('https').createServer(httpsOptions, app) + } else { + return require('http2').createSecureServer( + { + ...httpsOptions, + allowHTTP1: true + }, + app + ) + } +} export async function resolveHttpsConfig(httpsOption: HttpsServerOptions) { const { ca, cert, key, pfx } = httpsOption diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 5dd30944e1e384..8c2bdec68f8b57 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -9,13 +9,13 @@ import corsMiddleware from 'cors' import chalk from 'chalk' import { AddressInfo } from 'net' import chokidar from 'chokidar' +import { resolveHttpServer } from './http' import { resolveConfig, InlineConfig, ResolvedConfig } from '../config' import { createPluginContainer, PluginContainer } from '../server/pluginContainer' import { FSWatcher, WatchOptions } from 'types/chokidar' -import { resolveHttpsConfig } from '../server/https' import { createWebSocketServer, WebSocketServer } from '../server/ws' import { baseMiddleware } from './middlewares/base' import { proxyMiddleware, ProxyOptions } from './middlewares/proxy' @@ -471,31 +471,6 @@ export async function createServer( return server } -async function resolveHttpServer( - { https = false, proxy }: ServerOptions, - app: Connect.Server -): Promise { - if (!https) { - return require('http').createServer(app) - } - - const httpsOptions = await resolveHttpsConfig( - typeof https === 'boolean' ? {} : https - ) - if (proxy) { - // #484 fallback to http1 when proxy is needed. - return require('https').createServer(httpsOptions, app) - } else { - return require('http2').createSecureServer( - { - ...httpsOptions, - allowHTTP1: true - }, - app - ) - } -} - async function startServer( server: ViteDevServer, inlinePort?: number diff --git a/packages/vite/types/shims.d.ts b/packages/vite/types/shims.d.ts index e3533845957fa7..a0ee52a1c189d1 100644 --- a/packages/vite/types/shims.d.ts +++ b/packages/vite/types/shims.d.ts @@ -102,3 +102,8 @@ declare module 'minimatch' { function match(path: string, pattern: string): boolean export default match } + +declare module 'compression' { + function compression(): any + export default compression +} From 46bb853ceeb53376645d194384f685cf88a8059e Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 22:50:00 -0500 Subject: [PATCH 252/514] chore: export type --- packages/vite/src/node/index.ts | 3 ++- packages/vite/src/node/plugins/esbuild.ts | 4 ++-- packages/vite/src/node/server/index.ts | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/node/index.ts b/packages/vite/src/node/index.ts index 777fddbd86e857..cf00ed4d817018 100644 --- a/packages/vite/src/node/index.ts +++ b/packages/vite/src/node/index.ts @@ -24,7 +24,8 @@ export type { HtmlTagDescriptor } from './plugins/html' export type { CSSOptions, CSSModulesOptions } from './plugins/css' -export type { ESBuildOptions, EsbuildTransformResult } from './plugins/esbuild' +export type { JsonOptions } from './plugins/json' +export type { ESBuildOptions, ESBuildTransformResult } from './plugins/esbuild' export type { PackageData } from './plugins/resolve' export type { WebSocketServer } from './server/ws' export type { PluginContainer } from './server/pluginContainer' diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 82920a1ad6ed01..87c6bb49036f49 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -40,7 +40,7 @@ export async function stopService() { } } -export type EsbuildTransformResult = Omit & { +export type ESBuildTransformResult = Omit & { map: SourceMap } @@ -49,7 +49,7 @@ export async function transformWithEsbuild( filename: string, options?: TransformOptions, inMap?: object -): Promise { +): Promise { const service = await ensureService() // if the id ends with a valid ext, use it (e.g. vue blocks) // otherwise, cleanup the query before checking the ext diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 8c2bdec68f8b57..da32669afc0596 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -39,7 +39,7 @@ import { TransformResult } from 'rollup' import { TransformOptions, transformRequest } from './transformRequest' import { transformWithEsbuild, - EsbuildTransformResult + ESBuildTransformResult } from '../plugins/esbuild' import { TransformOptions as EsbuildTransformOptions } from 'esbuild' import { DepOptimizationMetadata, optimizeDeps } from '../optimizer' @@ -197,7 +197,7 @@ export interface ViteDevServer { filename: string, options?: EsbuildTransformOptions, inMap?: object - ): Promise + ): Promise /** * Load a given URL as an instantiated module for SSR. * @alpha From 60f9782a8481a4ce4d4c90ca246f5de44065d314 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 23:21:59 -0500 Subject: [PATCH 253/514] fix(hmr): preserve host when updating link CSS fix #1665 --- packages/vite/src/client/client.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/client/client.ts b/packages/vite/src/client/client.ts index 6af2ff8875792f..c1228efb1eaa24 100644 --- a/packages/vite/src/client/client.ts +++ b/packages/vite/src/client/client.ts @@ -88,12 +88,17 @@ async function handleMessage(payload: HMRPayload) { // this is only sent when a css file referenced with is updated let { path, timestamp } = update path = path.replace(/\?.*/, '') - const el = document.querySelector(`link[href*='${path}']`) + // can't use querySelector with `[href*=]` here since the link may be + // using relative paths so we need to use link.href to grab the full + // URL for the include check. + const el = ([].slice.call( + document.querySelectorAll(`link`) + ) as HTMLLinkElement[]).find((e) => e.href.includes(path)) if (el) { - el.setAttribute( - 'href', - `${path}${path.includes('?') ? '&' : '?'}t=${timestamp}` - ) + const newPath = `${path}${ + path.includes('?') ? '&' : '?' + }t=${timestamp}` + el.href = new URL(newPath, el.href).href } console.log(`[vite] css hot updated: ${path}`) } From 2950c3c278e20174184e44c194393b098c0d4305 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 00:20:28 -0500 Subject: [PATCH 254/514] fix(hmr): fix nested hmr accept calls with base --- packages/vite/src/client/client.ts | 10 ++++------ packages/vite/src/node/plugins/importAnalysis.ts | 14 ++++++++------ packages/vite/src/node/server/hmr.ts | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/vite/src/client/client.ts b/packages/vite/src/client/client.ts index c1228efb1eaa24..59de8d9f96f7f5 100644 --- a/packages/vite/src/client/client.ts +++ b/packages/vite/src/client/client.ts @@ -40,7 +40,6 @@ const socketProtocol = const socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__}` const socket = new WebSocket(`${socketProtocol}://${socketHost}`, 'vite-hmr') const base = __BASE__ || '/' -const baseNoSlash = base.replace(/\/$/, '') function warnFailedFetch(err: Error, path: string | string[]) { if (!err.message.match('fetch')) { @@ -115,7 +114,7 @@ async function handleMessage(payload: HMRPayload) { // if html file is edited, only reload the page if the browser is // currently on that page. const pagePath = location.pathname - const payloadPath = baseNoSlash + payload.path + const payloadPath = base + payload.path.slice(1) if ( pagePath === payloadPath || (pagePath.endsWith('/') && pagePath + 'index.html' === payloadPath) @@ -268,9 +267,6 @@ export function removeStyle(id: string) { } async function fetchUpdate({ path, acceptedPath, timestamp }: Update) { - path = baseNoSlash + path - acceptedPath = baseNoSlash + acceptedPath - const mod = hotModulesMap.get(path) if (!mod) { // In a code-splitting project, @@ -311,7 +307,9 @@ async function fetchUpdate({ path, acceptedPath, timestamp }: Update) { try { const newMod = await import( /* @vite-ignore */ - path + `?import&t=${timestamp}${query ? `&${query}` : ''}` + base + + path.slice(1) + + `?import&t=${timestamp}${query ? `&${query}` : ''}` ) moduleMap.set(dep, newMod) } catch (e) { diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 0cd1ba45e3ec80..62d3c2cf4521bd 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -205,9 +205,6 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { url = markExplicitImport(url) } - // prepend base path without trailing slash ( default empty string ) - url = path.posix.join(config.base, url) - // for relative js/css imports, inherit importer's version query // do not do this for unknown type imports, otherwise the appended // query can break 3rd party plugin's extension checks. @@ -233,6 +230,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { throw e } + // prepend base path without trailing slash ( default empty string ) + url = path.posix.join(config.base, url) return [url, resolved.id] } @@ -286,7 +285,9 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { ) str().prepend(importsString) str().overwrite(expStart, endIndex, exp) - imports.forEach((url) => importedUrls.add(url)) + imports.forEach((url) => + importedUrls.add(url.replace(config.base, '/')) + ) server._globImporters[importerModule.file!] = { module: importerModule, base, @@ -382,7 +383,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { } // record for HMR import chain analysis - importedUrls.add(url) + // make sure to normalize away base + importedUrls.add(url.replace(config.base, '/')) } else if (!importer.startsWith(clientDir) && !ssr) { if (!hasViteIgnore && !isSupportedDynamicImport(url)) { this.warn( @@ -428,7 +430,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { str().prepend( `import { createHotContext as __vite__createHotContext } from "${clientPublicPath}";` + `import.meta.hot = __vite__createHotContext(${JSON.stringify( - path.posix.join(config.base, importerModule.url) + importerModule.url )});` ) } diff --git a/packages/vite/src/node/server/hmr.ts b/packages/vite/src/node/server/hmr.ts index 836acbe3d213e4..b2b29ea4af8c56 100644 --- a/packages/vite/src/node/server/hmr.ts +++ b/packages/vite/src/node/server/hmr.ts @@ -77,7 +77,7 @@ export async function handleHMRUpdate( if (file.startsWith(normalizedClientDir)) { ws.send({ type: 'full-reload', - path: '/' + slash(path.relative(config.root, file)) + path: '*' }) return } From f2ca1bf83ae818d38bfd6e129481ea2b6b49e7ad Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 01:23:46 -0500 Subject: [PATCH 255/514] refactor: source map tweaks fix #1677 --- packages/plugin-vue/src/style.ts | 2 +- packages/vite/src/node/plugins/css.ts | 14 ++++++------- .../src/node/plugins/importAnaysisBuild.ts | 20 ++++++++++++++++++- .../vite/src/node/server/pluginContainer.ts | 5 +++++ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/packages/plugin-vue/src/style.ts b/packages/plugin-vue/src/style.ts index c65757871d43e5..c14866600953aa 100644 --- a/packages/plugin-vue/src/style.ts +++ b/packages/plugin-vue/src/style.ts @@ -37,6 +37,6 @@ export async function transformStyle( return { code: result.code, - map: result.map as any + map: result.map || ({ mappings: '' } as any) } } diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index dcfb561f7de83f..372a34ca7d7473 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -160,7 +160,11 @@ export function cssPlugin(config: ResolvedConfig): Plugin { } } - return css + return { + code: css, + // TODO CSS source map + map: { mappings: '' } + } } } } @@ -219,7 +223,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { return { code: modulesCode || `export default ${JSON.stringify(css)}`, - map: null, + map: { mappings: '' }, // avoid the css module from being tree-shaken so that we can retrieve // it in renderChunk() moduleSideEffects: 'no-treeshake' @@ -272,16 +276,12 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { return { code: injectCode + code } } } - return { - code, - map: null - } } else { const extractedCss = outputToExtractedCSSMap.get(opts) || '' chunkCSS = await processChunkCSS(chunkCSS, config, this, false) outputToExtractedCSSMap.set(opts, extractedCss + chunkCSS) - return null } + return null }, async generateBundle(opts, bundle) { diff --git a/packages/vite/src/node/plugins/importAnaysisBuild.ts b/packages/vite/src/node/plugins/importAnaysisBuild.ts index 91c4c049b5fae3..74ad05741d74b6 100644 --- a/packages/vite/src/node/plugins/importAnaysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnaysisBuild.ts @@ -157,7 +157,25 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { renderChunk(code, _, { format }) { // make sure we only perform the preload logic in modern builds. if (code.indexOf(isModernFlag) > -1) { - return code.replace(/__VITE_IS_MODERN__/g, String(format === 'es')) + const re = new RegExp(isModernFlag, 'g') + const isModern = String(format === 'es') + if (config.build.sourcemap) { + const s = new MagicString(code) + let match + while ((match = re.exec(code))) { + s.overwrite( + match.index, + match.index + isModernFlag.length, + isModern + ) + } + return { + code: s.toString(), + map: s.generateMap({ hires: true }) + } + } else { + return code.replace(re, isModern) + } } return null }, diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index e8d638196975dc..5bca2d20f28f5d 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -342,6 +342,11 @@ export async function createPluginContainer( let combinedMap = this.combinedMap for (let m of this.sourcemapChain) { if (typeof m === 'string') m = JSON.parse(m) + if (!('version' in (m as SourceMap))) { + // empty, nullified source map + combinedMap = null + break + } if (!combinedMap) { combinedMap = m as SourceMap } else { From 13da32e9ce22b1916a1b98bba7ad83bd145563c1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 01:33:50 -0500 Subject: [PATCH 256/514] fix(resolve): handle paths starting with slash in entry fields close #1676 --- packages/vite/src/node/plugins/resolve.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index d4371d7eba697e..c16a5539fc5846 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -475,7 +475,7 @@ export function resolvePackageEntry( // possible and check for hints of UMD. If it is UMD, prefer "module" // instead; Otherwise, assume it's ESM and use it. const resolvedBrowserEntry = tryFsResolve( - path.resolve(dir, browserEntry), + path.join(dir, browserEntry), isProduction ) if (resolvedBrowserEntry) { @@ -512,7 +512,7 @@ export function resolvePackageEntry( entryPoint = mapWithBrowserField(entryPoint, browserField) || entryPoint } - entryPoint = path.resolve(dir, entryPoint) + entryPoint = path.join(dir, entryPoint) const resolvedEntryPont = tryFsResolve(entryPoint, isProduction) if (resolvedEntryPont) { @@ -567,7 +567,7 @@ function resolveDeepImport( } if (relativeId) { - const resolved = tryFsResolve(path.resolve(dir, relativeId), !exportsField) + const resolved = tryFsResolve(path.join(dir, relativeId), !exportsField) if (resolved) { isDebug && debug(`[node/deep-import] ${chalk.cyan(id)} -> ${chalk.dim(resolved)}`) @@ -588,7 +588,7 @@ function tryResolveBrowserMapping( const mapId = isFilePath ? './' + slash(path.relative(pkg.dir, id)) : id const browserMappedPath = mapWithBrowserField(mapId, pkg.data.browser) if (browserMappedPath) { - const fsPath = path.resolve(pkg.dir, browserMappedPath) + const fsPath = path.join(pkg.dir, browserMappedPath) if ((res = tryFsResolve(fsPath, isProduction))) { isDebug && debug(`[browser mapped] ${chalk.cyan(id)} -> ${chalk.dim(res)}`) From 972b13e09f9f0d43de9b7fb1d7bd706b4a10984b Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 01:44:48 -0500 Subject: [PATCH 257/514] feat: source map for optimized deps --- packages/vite/src/node/optimizer/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 00e18251a23188..27e9c5614d340e 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -239,6 +239,7 @@ export async function optimizeDeps( format: 'esm', external, splitting: true, + sourcemap: true, outdir: cacheDir, metafile: esbuildMetaPath, define: { From bda8e3bdd831a45befcbc42becd4a9c18f811535 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 02:02:30 -0500 Subject: [PATCH 258/514] release: v2.0.0-beta.45 --- packages/vite/CHANGELOG.md | 26 ++++ packages/vite/LICENSE.md | 247 +++++++++++++++++++++++++++++++++++++ packages/vite/package.json | 2 +- 3 files changed, 274 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index b463b1e411a82e..f6988edc02ef8e 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,29 @@ +# [2.0.0-beta.45](https://github.com/vitejs/vite/compare/v2.0.0-beta.44...v2.0.0-beta.45) (2021-01-24) + + +### Bug Fixes + +* **hmr:** fix nested hmr accept calls with base ([2950c3c](https://github.com/vitejs/vite/commit/2950c3c278e20174184e44c194393b098c0d4305)) +* **hmr:** preserve host when updating link CSS ([60f9782](https://github.com/vitejs/vite/commit/60f9782a8481a4ce4d4c90ca246f5de44065d314)), closes [#1665](https://github.com/vitejs/vite/issues/1665) +* **html:** ensure quote in rebased asset urls in html ([7306610](https://github.com/vitejs/vite/commit/73066105727e669fe15d926fbe07d1788a469844)), closes [#1668](https://github.com/vitejs/vite/issues/1668) +* **import-anaysis:** markPos out-of-range for overwrite ([#1671](https://github.com/vitejs/vite/issues/1671)) ([226e984](https://github.com/vitejs/vite/commit/226e9849253677770f11f8a26e6ec205067dc902)) +* **optimizer:** repsect alias in pre-bundling ([2824d06](https://github.com/vitejs/vite/commit/2824d067d5239b506f93dc9c073c21d7e059bbe3)), closes [#1674](https://github.com/vitejs/vite/issues/1674) +* **resolve:** handle paths starting with slash in entry fields ([13da32e](https://github.com/vitejs/vite/commit/13da32e9ce22b1916a1b98bba7ad83bd145563c1)), closes [#1676](https://github.com/vitejs/vite/issues/1676) +* import analysis dynamic import check ([d4909b9](https://github.com/vitejs/vite/commit/d4909b936994d4fec37dfbafd27cd24494de8d14)) +* revert trailing slash handling + improve dev base usage ([01e9ac0](https://github.com/vitejs/vite/commit/01e9ac0222dcc36c075c25e3fe8f7e8881867e9c)), closes [#1664](https://github.com/vitejs/vite/issues/1664) +* support empty, relative and external base values ([00bc446](https://github.com/vitejs/vite/commit/00bc4466567bd5613d67abd1bdf46d9c9cb23a80)), closes [#1669](https://github.com/vitejs/vite/issues/1669) + + +### Features + +* default vendor chunk splitting ([f6b58a0](https://github.com/vitejs/vite/commit/f6b58a0f535b1c26f9c1dfda74c28c685402c3c9)) +* disable prompts and clearScreen on CI ([63dd1a2](https://github.com/vitejs/vite/commit/63dd1a2829ea0764c12e11f2f3510bc1c096febf)), closes [#1673](https://github.com/vitejs/vite/issues/1673) +* source map for optimized deps ([972b13e](https://github.com/vitejs/vite/commit/972b13e09f9f0d43de9b7fb1d7bd706b4a10984b)) +* support stringifying json ([98c321b](https://github.com/vitejs/vite/commit/98c321b3694dc77dd66e8064f14467e909832171)), closes [#1672](https://github.com/vitejs/vite/issues/1672) +* vite preview command for previewing build output ([a198990](https://github.com/vitejs/vite/commit/a198990efe4f96c2155928ac23264437d393d54e)), closes [#1627](https://github.com/vitejs/vite/issues/1627) + + + # [2.0.0-beta.44](https://github.com/vitejs/vite/compare/v2.0.0-beta.43...v2.0.0-beta.44) (2021-01-23) diff --git a/packages/vite/LICENSE.md b/packages/vite/LICENSE.md index 0d7b086382d65c..9981c9af93b25e 100644 --- a/packages/vite/LICENSE.md +++ b/packages/vite/LICENSE.md @@ -389,6 +389,37 @@ Repository: git+https://github.com/vuejs/vue-next.git --------------------------------------- +## accepts +License: MIT +By: Douglas Christopher Wilson, Jonathan Ong +Repository: jshttp/accepts + +> (The MIT License) +> +> Copyright (c) 2014 Jonathan Ong +> Copyright (c) 2015 Douglas Christopher Wilson +> +> Permission is hereby granted, free of charge, to any person obtaining +> a copy of this software and associated documentation files (the +> 'Software'), to deal in the Software without restriction, including +> without limitation the rights to use, copy, modify, merge, publish, +> distribute, sublicense, and/or sell copies of the Software, and to +> permit persons to whom the Software is furnished to do so, subject to +> the following conditions: +> +> The above copyright notice and this permission notice shall be +> included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +> CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +> TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +> SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + ## acorn License: MIT By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine @@ -736,6 +767,37 @@ Repository: sindresorhus/builtin-modules --------------------------------------- +## bytes +License: MIT +By: TJ Holowaychuk, Jed Watson, Théo FIDRY +Repository: visionmedia/bytes.js + +> (The MIT License) +> +> Copyright (c) 2012-2014 TJ Holowaychuk +> Copyright (c) 2015 Jed Watson +> +> Permission is hereby granted, free of charge, to any person obtaining +> a copy of this software and associated documentation files (the +> 'Software'), to deal in the Software without restriction, including +> without limitation the rights to use, copy, modify, merge, publish, +> distribute, sublicense, and/or sell copies of the Software, and to +> permit persons to whom the Software is furnished to do so, subject to +> the following conditions: +> +> The above copyright notice and this permission notice shall be +> included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +> CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +> TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +> SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + ## cac License: MIT By: egoist @@ -910,6 +972,69 @@ Repository: http://github.com/substack/node-commondir.git --------------------------------------- +## compressible +License: MIT +By: Douglas Christopher Wilson, Jonathan Ong, Jeremiah Senkpiel +Repository: jshttp/compressible + +> (The MIT License) +> +> Copyright (c) 2013 Jonathan Ong +> Copyright (c) 2014 Jeremiah Senkpiel +> Copyright (c) 2015 Douglas Christopher Wilson +> +> Permission is hereby granted, free of charge, to any person obtaining +> a copy of this software and associated documentation files (the +> 'Software'), to deal in the Software without restriction, including +> without limitation the rights to use, copy, modify, merge, publish, +> distribute, sublicense, and/or sell copies of the Software, and to +> permit persons to whom the Software is furnished to do so, subject to +> the following conditions: +> +> The above copyright notice and this permission notice shall be +> included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +> CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +> TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +> SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + +## compression +License: MIT +By: Douglas Christopher Wilson, Jonathan Ong +Repository: expressjs/compression + +> (The MIT License) +> +> Copyright (c) 2014 Jonathan Ong +> Copyright (c) 2014-2015 Douglas Christopher Wilson +> +> Permission is hereby granted, free of charge, to any person obtaining +> a copy of this software and associated documentation files (the +> 'Software'), to deal in the Software without restriction, including +> without limitation the rights to use, copy, modify, merge, publish, +> distribute, sublicense, and/or sell copies of the Software, and to +> permit persons to whom the Software is furnished to do so, subject to +> the following conditions: +> +> The above copyright notice and this permission notice shall be +> included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +> CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +> TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +> SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + ## concat-map License: MIT By: James Halliday @@ -2733,6 +2858,66 @@ Repository: https://github.com/broofa/mime --------------------------------------- +## mime-db +License: MIT +By: Douglas Christopher Wilson, Jonathan Ong, Robert Kieffer +Repository: jshttp/mime-db + +> The MIT License (MIT) +> +> Copyright (c) 2014 Jonathan Ong me@jongleberry.com +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. + +--------------------------------------- + +## mime-types +License: MIT +By: Douglas Christopher Wilson, Jeremiah Senkpiel, Jonathan Ong +Repository: jshttp/mime-types + +> (The MIT License) +> +> Copyright (c) 2014 Jonathan Ong +> Copyright (c) 2015 Douglas Christopher Wilson +> +> Permission is hereby granted, free of charge, to any person obtaining +> a copy of this software and associated documentation files (the +> 'Software'), to deal in the Software without restriction, including +> without limitation the rights to use, copy, modify, merge, publish, +> distribute, sublicense, and/or sell copies of the Software, and to +> permit persons to whom the Software is furnished to do so, subject to +> the following conditions: +> +> The above copyright notice and this permission notice shall be +> included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +> CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +> TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +> SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + ## mimic-fn License: MIT By: Sindre Sorhus @@ -2769,6 +2954,38 @@ Repository: zeit/ms --------------------------------------- +## negotiator +License: MIT +By: Douglas Christopher Wilson, Federico Romero, Isaac Z. Schlueter +Repository: jshttp/negotiator + +> (The MIT License) +> +> Copyright (c) 2012-2014 Federico Romero +> Copyright (c) 2012-2014 Isaac Z. Schlueter +> Copyright (c) 2014-2015 Douglas Christopher Wilson +> +> Permission is hereby granted, free of charge, to any person obtaining +> a copy of this software and associated documentation files (the +> 'Software'), to deal in the Software without restriction, including +> without limitation the rights to use, copy, modify, merge, publish, +> distribute, sublicense, and/or sell copies of the Software, and to +> permit persons to whom the Software is furnished to do so, subject to +> the following conditions: +> +> The above copyright notice and this permission notice shall be +> included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +> CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +> TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +> SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + ## node-forge License: (BSD-3-Clause OR GPL-2.0) By: Digital Bazaar, Inc., Dave Longley, David I. Lehn, Stefan Siegl, Christoph Dorn @@ -3210,6 +3427,36 @@ Repository: jshttp/on-finished --------------------------------------- +## on-headers +License: MIT +By: Douglas Christopher Wilson +Repository: jshttp/on-headers + +> (The MIT License) +> +> Copyright (c) 2014 Douglas Christopher Wilson +> +> Permission is hereby granted, free of charge, to any person obtaining +> a copy of this software and associated documentation files (the +> 'Software'), to deal in the Software without restriction, including +> without limitation the rights to use, copy, modify, merge, publish, +> distribute, sublicense, and/or sell copies of the Software, and to +> permit persons to whom the Software is furnished to do so, subject to +> the following conditions: +> +> The above copyright notice and this permission notice shall be +> included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +> CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +> TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +> SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + ## once License: ISC By: Isaac Z. Schlueter diff --git a/packages/vite/package.json b/packages/vite/package.json index c67356e833b21f..8d81b2780883c1 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.44", + "version": "2.0.0-beta.45", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 97c318640d65ede85e4954e6804199bc461674e9 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 02:03:25 -0500 Subject: [PATCH 259/514] release: plugin-vue@1.1.2 --- packages/plugin-vue/CHANGELOG.md | 4 ++++ packages/plugin-vue/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/plugin-vue/CHANGELOG.md b/packages/plugin-vue/CHANGELOG.md index 29f342b309b64f..2e316f0bf0e6ab 100644 --- a/packages/plugin-vue/CHANGELOG.md +++ b/packages/plugin-vue/CHANGELOG.md @@ -1,3 +1,7 @@ +## [1.1.2](https://github.com/vitejs/vite/compare/plugin-vue@1.1.1...plugin-vue@1.1.2) (2021-01-24) + + + ## [1.1.1](https://github.com/vitejs/vite/compare/plugin-vue@1.1.0...plugin-vue@1.1.1) (2021-01-23) diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index 81a56293a4408d..5638886ec6d792 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-vue", - "version": "1.1.1", + "version": "1.1.2", "license": "MIT", "author": "Evan You", "files": [ From 16b919e8790dfea863edc939ed1148143714a7a1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 02:05:45 -0500 Subject: [PATCH 260/514] release: create-app@1.4.0 --- packages/create-app/CHANGELOG.md | 4 ++++ packages/create-app/package.json | 2 +- packages/create-app/template-preact-ts/package.json | 5 +++-- packages/create-app/template-preact/package.json | 5 +++-- packages/create-app/template-react-ts/package.json | 5 +++-- packages/create-app/template-react/package.json | 5 +++-- packages/create-app/template-vanilla/package.json | 5 +++-- packages/create-app/template-vue-ts/package.json | 7 ++++--- packages/create-app/template-vue/package.json | 7 ++++--- 9 files changed, 28 insertions(+), 17 deletions(-) diff --git a/packages/create-app/CHANGELOG.md b/packages/create-app/CHANGELOG.md index e3408f5b7b8d17..f4fd55d948b074 100644 --- a/packages/create-app/CHANGELOG.md +++ b/packages/create-app/CHANGELOG.md @@ -1,3 +1,7 @@ +# [1.4.0](https://github.com/vitejs/vite/compare/create-app@1.3.0...create-app@1.4.0) (2021-01-24) + + + # [1.3.0](https://github.com/vitejs/vite/compare/create-app@1.1.0...create-app@1.3.0) (2021-01-23) diff --git a/packages/create-app/package.json b/packages/create-app/package.json index 1d5ebd03e3a44d..4b76d9c02d8cff 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/create-app", - "version": "1.3.0", + "version": "1.4.0", "license": "MIT", "author": "Evan You", "bin": { diff --git a/packages/create-app/template-preact-ts/package.json b/packages/create-app/template-preact-ts/package.json index 19934ef3510e5e..1a4619feb0eb23 100644 --- a/packages/create-app/template-preact-ts/package.json +++ b/packages/create-app/template-preact-ts/package.json @@ -3,7 +3,8 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "build": "tsc && vite build" + "build": "tsc && vite build", + "serve": "vite preview" }, "dependencies": { "preact": "^10.5.9" @@ -11,6 +12,6 @@ "devDependencies": { "@prefresh/vite": "^2.0.0", "typescript": "^4.1.3", - "vite": "^2.0.0-beta.44" + "vite": "^2.0.0-beta.45" } } \ No newline at end of file diff --git a/packages/create-app/template-preact/package.json b/packages/create-app/template-preact/package.json index eeae1444238521..4d14496fa58568 100644 --- a/packages/create-app/template-preact/package.json +++ b/packages/create-app/template-preact/package.json @@ -3,13 +3,14 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "build": "vite build" + "build": "vite build", + "serve": "vite preview" }, "dependencies": { "preact": "^10.5.9" }, "devDependencies": { "@prefresh/vite": "^2.0.0", - "vite": "^2.0.0-beta.44" + "vite": "^2.0.0-beta.45" } } \ No newline at end of file diff --git a/packages/create-app/template-react-ts/package.json b/packages/create-app/template-react-ts/package.json index 46a73396e1d467..162902044fcac8 100644 --- a/packages/create-app/template-react-ts/package.json +++ b/packages/create-app/template-react-ts/package.json @@ -3,7 +3,8 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "build": "tsc && vite build" + "build": "tsc && vite build", + "serve": "vite preview" }, "dependencies": { "react": "^17.0.0", @@ -14,6 +15,6 @@ "@types/react-dom": "^17.0.0", "@vitejs/plugin-react-refresh": "^1.1.0", "typescript": "^4.1.2", - "vite": "^2.0.0-beta.44" + "vite": "^2.0.0-beta.45" } } \ No newline at end of file diff --git a/packages/create-app/template-react/package.json b/packages/create-app/template-react/package.json index 958f5f184a2f85..32c81afcd226b6 100644 --- a/packages/create-app/template-react/package.json +++ b/packages/create-app/template-react/package.json @@ -3,7 +3,8 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "build": "vite build" + "build": "vite build", + "serve": "vite preview" }, "dependencies": { "react": "^17.0.0", @@ -11,6 +12,6 @@ }, "devDependencies": { "@vitejs/plugin-react-refresh": "^1.1.0", - "vite": "^2.0.0-beta.44" + "vite": "^2.0.0-beta.45" } } \ No newline at end of file diff --git a/packages/create-app/template-vanilla/package.json b/packages/create-app/template-vanilla/package.json index b78385fc15961a..213af9e4a9250e 100644 --- a/packages/create-app/template-vanilla/package.json +++ b/packages/create-app/template-vanilla/package.json @@ -3,9 +3,10 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "build": "vite build" + "build": "vite build", + "serve": "vite preview" }, "devDependencies": { - "vite": "^2.0.0-beta.44" + "vite": "^2.0.0-beta.45" } } \ No newline at end of file diff --git a/packages/create-app/template-vue-ts/package.json b/packages/create-app/template-vue-ts/package.json index 0ae26272525729..c3f361935917d1 100644 --- a/packages/create-app/template-vue-ts/package.json +++ b/packages/create-app/template-vue-ts/package.json @@ -3,17 +3,18 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "build": "vuedx-typecheck . && vite build" + "build": "vuedx-typecheck . && vite build", + "serve": "vite preview" }, "dependencies": { "vue": "^3.0.5" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.1.1", + "@vitejs/plugin-vue": "^1.1.2", "@vue/compiler-sfc": "^3.0.5", "@vuedx/typecheck": "^0.4.1", "@vuedx/typescript-plugin-vue": "^0.4.1", "typescript": "^4.1.3", - "vite": "^2.0.0-beta.44" + "vite": "^2.0.0-beta.45" } } \ No newline at end of file diff --git a/packages/create-app/template-vue/package.json b/packages/create-app/template-vue/package.json index f00beb9174e2d0..0e80534f6dc84f 100644 --- a/packages/create-app/template-vue/package.json +++ b/packages/create-app/template-vue/package.json @@ -3,14 +3,15 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "build": "vite build" + "build": "vite build", + "serve": "vite preview" }, "dependencies": { "vue": "^3.0.5" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.1.1", + "@vitejs/plugin-vue": "^1.1.2", "@vue/compiler-sfc": "^3.0.5", - "vite": "^2.0.0-beta.44" + "vite": "^2.0.0-beta.45" } } \ No newline at end of file From 4ac7e7ec9915bd044454f90a6a3d5a9676b3615c Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 03:06:01 -0500 Subject: [PATCH 261/514] fix(css): fix extract concurrency issue when disabling cssCodeSplit --- packages/vite/src/node/plugins/css.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 372a34ca7d7473..412200be02a2d6 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -277,9 +277,11 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } } } else { - const extractedCss = outputToExtractedCSSMap.get(opts) || '' - chunkCSS = await processChunkCSS(chunkCSS, config, this, false) - outputToExtractedCSSMap.set(opts, extractedCss + chunkCSS) + chunkCSS = await processChunkCSS(chunkCSS, config, this, false, false) + outputToExtractedCSSMap.set( + opts, + (outputToExtractedCSSMap.get(opts) || '') + chunkCSS + ) } return null }, @@ -738,7 +740,8 @@ async function processChunkCSS( css: string, config: ResolvedConfig, pluginCtx: PluginContext, - isInlined: boolean + isInlined: boolean, + minify = true ): Promise { // replace asset url references with resolved url. const isRelativeBase = config.base === '' || config.base.startsWith('.') @@ -753,7 +756,7 @@ async function processChunkCSS( return `./${path.posix.basename(filename)}` } }) - if (config.build.minify) { + if (minify && config.build.minify) { css = await minifyCSS(css, config) } return css From d884424bb93c371400b606541c19e0b426060b8b Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 03:09:49 -0500 Subject: [PATCH 262/514] release: v2.0.0-beta.46 --- packages/vite/CHANGELOG.md | 9 +++++++++ packages/vite/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index f6988edc02ef8e..369f9b2ea68eff 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,12 @@ +# [2.0.0-beta.46](https://github.com/vitejs/vite/compare/v2.0.0-beta.45...v2.0.0-beta.46) (2021-01-24) + + +### Bug Fixes + +* **css:** fix extract concurrency issue when disabling cssCodeSplit ([4ac7e7e](https://github.com/vitejs/vite/commit/4ac7e7ec9915bd044454f90a6a3d5a9676b3615c)) + + + # [2.0.0-beta.45](https://github.com/vitejs/vite/compare/v2.0.0-beta.44...v2.0.0-beta.45) (2021-01-24) diff --git a/packages/vite/package.json b/packages/vite/package.json index 8d81b2780883c1..1f0d7eedf1a9dc 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.45", + "version": "2.0.0-beta.46", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From a92f4303253c9423093bedad6b06744d66dd1d39 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 03:32:46 -0500 Subject: [PATCH 263/514] fix: do not apply json plugin to commonjs proxy close #1679 --- packages/vite/src/node/plugins/json.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/json.ts b/packages/vite/src/node/plugins/json.ts index e9e969f485cb35..cc0a8bf5027440 100644 --- a/packages/vite/src/node/plugins/json.ts +++ b/packages/vite/src/node/plugins/json.ts @@ -24,7 +24,7 @@ export interface JsonOptions { } // Custom json filter for vite -const jsonExtRE = new RegExp(`\\.json($|\\?)`) +const jsonExtRE = /\.json($|\?)(?!commonjs-proxy)/ export function jsonPlugin( options: JsonOptions = {}, From 33cffa3910600c5adfb10f2cab07029f1ff8f35f Mon Sep 17 00:00:00 2001 From: Florian Dreier Date: Sun, 24 Jan 2021 19:43:56 +0100 Subject: [PATCH 264/514] fix: fix server.watch option ignore overwriting defaults (#1680) --- packages/vite/src/node/server/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index da32669afc0596..c8c4429c34df14 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -255,12 +255,12 @@ export async function createServer( : await resolveHttpServer(serverConfig, middlewares) const ws = createWebSocketServer(httpServer, config) - const watchOptions = serverConfig.watch || {} + const { ignored = [], ...watchOptions } = serverConfig.watch || {} const watcher = chokidar.watch(root, { ignored: [ '**/node_modules/**', '**/.git/**', - ...(watchOptions.ignored || []) + ...ignored ], ignoreInitial: true, ignorePermissionErrors: true, From 9e17c9e11e088283ecd074bf69a9b4a94bdb2728 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 14:20:52 -0500 Subject: [PATCH 265/514] docs: improve index.html/project root explanation --- docs/guide/index.md | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/docs/guide/index.md b/docs/guide/index.md index 63962ea9169742..622d650d86fa71 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -40,6 +40,20 @@ Supported template presets include: See [@vitejs/create-app](https://github.com/vitejs/vite/tree/main/packages/create-app) for more details on each template. +## `index.html` and Project Root + +One thing you may have noticed is that in a Vite project, `index.html` is front-and-central instead of being tucked away inside `public`. This is intentional: during development Vite is a server, and `index.html` is the entry point to your application. + +Vite treats `index.html` as source code and part of the module graph. It resolves ` + + diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 369f9b2ea68eff..e87b31b635dcc2 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,20 @@ +# [2.0.0-beta.47](https://github.com/vitejs/vite/compare/v2.0.0-beta.46...v2.0.0-beta.47) (2021-01-24) + + +### Bug Fixes + +* do not apply json plugin to commonjs proxy ([a92f430](https://github.com/vitejs/vite/commit/a92f4303253c9423093bedad6b06744d66dd1d39)), closes [#1679](https://github.com/vitejs/vite/issues/1679) +* esbuild optimizer yarn 2 pnp compat ([028c3bb](https://github.com/vitejs/vite/commit/028c3bb1a6c5f56eaa7f8f122200d6262a1a8683)), closes [#1688](https://github.com/vitejs/vite/issues/1688) +* fix incorrect preload placeholder regex ([5ca43ef](https://github.com/vitejs/vite/commit/5ca43ef6e91e41f09e06d92adef79953a3df9782)), closes [#1686](https://github.com/vitejs/vite/issues/1686) +* fix server.watch option ignore overwriting defaults ([#1680](https://github.com/vitejs/vite/issues/1680)) ([33cffa3](https://github.com/vitejs/vite/commit/33cffa3910600c5adfb10f2cab07029f1ff8f35f)) + + +### Performance Improvements + +* **build:** improve performance of default vendor chunk splitting ([#1690](https://github.com/vitejs/vite/issues/1690)) ([0bed9c4](https://github.com/vitejs/vite/commit/0bed9c44b2c89ad4fb7439907959f78d946b42cd)) + + + # [2.0.0-beta.46](https://github.com/vitejs/vite/compare/v2.0.0-beta.45...v2.0.0-beta.46) (2021-01-24) diff --git a/packages/vite/package.json b/packages/vite/package.json index 1f0d7eedf1a9dc..b91c1b34a3912d 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.46", + "version": "2.0.0-beta.47", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 6cd2d35d791311de953b7a832a877b1c98e2b2ed Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 21:19:29 -0500 Subject: [PATCH 271/514] fix: remove preload markers in all cases fix #1694 --- packages/vite/src/node/plugins/importAnaysisBuild.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnaysisBuild.ts b/packages/vite/src/node/plugins/importAnaysisBuild.ts index b7f7e1dc94f0aa..6b8b43f55a60bf 100644 --- a/packages/vite/src/node/plugins/importAnaysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnaysisBuild.ts @@ -249,10 +249,11 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { } chunk.code = s.toString() // TODO source map - } else { - // inlined dynamic import, remove the marker - chunk.code = code.replace(preloadMarkerRE, 'void 0') } + + // there may still be markers due to inlined dynamic imports, remove + // all the markers regardless + chunk.code = code.replace(preloadMarkerRE, 'void 0') } } } From 02a0324a56fcc3659ace4b62f96b2a8b10979f4c Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 21:27:01 -0500 Subject: [PATCH 272/514] fix: externalize known css types during dep-prebundling fix #1695 --- .../vite/src/node/optimizer/esbuildDepPlugin.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index cd873a512feb4e..a270e707f0da15 100644 --- a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -7,7 +7,19 @@ import { deepImportRE, isBuiltin, isRunningWithYarnPnp } from '../utils' import { tryNodeResolve } from '../plugins/resolve' import { PluginContainer } from '../server/pluginContainer' -const externalTypes = ['css', 'vue', 'svelte', ...knownAssetTypes] +const externalTypes = [ + 'css', + // supported pre-processor types + 'less', + 'sass', + 'scss', + 'style', + 'stylus', + // known SFC types + 'vue', + 'svelte', + ...knownAssetTypes +] export function esbuildDepPlugin( qualified: Record, From 2096309bee0f4ad838cde2a9dd9114b819e462c4 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 21:29:11 -0500 Subject: [PATCH 273/514] fix: fallback to static middleware on unfound source maps --- packages/vite/src/node/server/middlewares/transform.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/vite/src/node/server/middlewares/transform.ts b/packages/vite/src/node/server/middlewares/transform.ts index 6b9a57684de06c..bd06213a15ab56 100644 --- a/packages/vite/src/node/server/middlewares/transform.ts +++ b/packages/vite/src/node/server/middlewares/transform.ts @@ -65,8 +65,7 @@ export function transformMiddleware( if (map) { return send(req, res, JSON.stringify(map), 'json') } else { - res.statusCode = 404 - return res.end() + return next() } } From 7f83deb7fe5add6117f8f715fc3165511761d07b Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 21:31:33 -0500 Subject: [PATCH 274/514] fix: preload marker incorrect replacement --- packages/vite/src/node/plugins/importAnaysisBuild.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/importAnaysisBuild.ts b/packages/vite/src/node/plugins/importAnaysisBuild.ts index 6b8b43f55a60bf..099fc3b64218e9 100644 --- a/packages/vite/src/node/plugins/importAnaysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnaysisBuild.ts @@ -253,7 +253,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { // there may still be markers due to inlined dynamic imports, remove // all the markers regardless - chunk.code = code.replace(preloadMarkerRE, 'void 0') + chunk.code = chunk.code.replace(preloadMarkerRE, 'void 0') } } } From b0b0b236320d10ae593eb927bf5ad5586a198413 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 21:33:01 -0500 Subject: [PATCH 275/514] release: plugin-legacy@1.2.2 --- packages/plugin-legacy/CHANGELOG.md | 15 +++++++++++++++ packages/plugin-legacy/package.json | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/plugin-legacy/CHANGELOG.md b/packages/plugin-legacy/CHANGELOG.md index a03c8de58d4712..9a342d57882e0c 100644 --- a/packages/plugin-legacy/CHANGELOG.md +++ b/packages/plugin-legacy/CHANGELOG.md @@ -1,3 +1,18 @@ +## [1.2.2](https://github.com/vitejs/vite/compare/plugin-legacy@1.2.1...plugin-legacy@1.2.2) (2021-01-25) + + +### Bug Fixes + +* **plugin-legacy:** throw error when using esbuild minify with legacy plugin ([8fb2511](https://github.com/vitejs/vite/commit/8fb2511a02c163d85f60dfab0bef104756768e35)) + + +### Features + +* default vendor chunk splitting ([f6b58a0](https://github.com/vitejs/vite/commit/f6b58a0f535b1c26f9c1dfda74c28c685402c3c9)) +* support `base` option during dev, deprecate `build.base` ([#1556](https://github.com/vitejs/vite/issues/1556)) ([809d4bd](https://github.com/vitejs/vite/commit/809d4bd3bf62d3bc6b35f182178922d2ab2175f1)) + + + ## [1.2.1](https://github.com/vitejs/vite/compare/plugin-legacy@1.2.0...plugin-legacy@1.2.1) (2021-01-14) diff --git a/packages/plugin-legacy/package.json b/packages/plugin-legacy/package.json index e40c51a236c3e6..7c6fe489e76395 100644 --- a/packages/plugin-legacy/package.json +++ b/packages/plugin-legacy/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-legacy", - "version": "1.2.1", + "version": "1.2.2", "license": "MIT", "author": "Evan You", "files": [ From e2137b71a5a82580b2cf45e84ead136052014ac7 Mon Sep 17 00:00:00 2001 From: Matias Capeletto Date: Mon, 25 Jan 2021 03:40:44 +0100 Subject: [PATCH 276/514] feat: resolved ids rollup compat for win32 (#1693) fix #1522 --- packages/vite/src/node/plugins/resolve.ts | 3 ++- packages/vite/src/node/utils.ts | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index c16a5539fc5846..88e39dddfc9ff9 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -13,6 +13,7 @@ import { isObject, normalizePath, fsPathFromId, + ensureVolumeInPath, resolveFrom, isDataUrl, cleanUrl, @@ -262,7 +263,7 @@ function tryResolveFile( if (index) return normalizePath(index) + query } } else { - return normalizePath(file) + query + return normalizePath(ensureVolumeInPath(file)) + query } } } diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 37700978637884..e8744b2cb67d48 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -60,15 +60,18 @@ const isWindows = os.platform() === 'win32' const VOLUME_RE = /^[A-Z]:/i export function normalizePath(id: string): string { - if (isWindows) { - return path.posix.normalize(slash(id.replace(VOLUME_RE, ''))) - } - return path.posix.normalize(id) + return path.posix.normalize(isWindows ? slash(id) : id) } export function fsPathFromId(id: string): string { const fsPath = normalizePath(id.slice(FS_PREFIX.length)) - return fsPath.startsWith('/') ? fsPath : `/${fsPath}` + return fsPath.startsWith('/') || fsPath.match(VOLUME_RE) + ? fsPath + : `/${fsPath}` +} + +export function ensureVolumeInPath(file: string): string { + return isWindows ? path.resolve(file) : file } export const queryRE = /\?.*$/ From 3240db19d33f0816e3c52a5042161a94753879d9 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 22:45:05 -0500 Subject: [PATCH 277/514] fix: resolve library entry --- packages/vite/src/node/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 55d2e749fd304e..873cb919c75055 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -289,7 +289,7 @@ async function doBuild( const resolve = (p: string) => path.resolve(config.root, p) const input = libOptions - ? libOptions.entry + ? resolve(libOptions.entry) : options.rollupOptions?.input || resolve('index.html') if (ssr && typeof input === 'string' && input.endsWith('.html')) { From 830f3d34f58cfa7680e1b2d753a023bcb1018ba2 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 23:07:03 -0500 Subject: [PATCH 278/514] feat: lit-element templates close #1684 --- packages/create-app/index.js | 13 ++++- .../template-lit-element-ts/_gitignore | 5 ++ .../template-lit-element-ts/index.html | 14 +++++ .../template-lit-element-ts/package.json | 24 ++++++++ .../template-lit-element-ts/src/my-element.ts | 55 ++++++++++++++++++ .../template-lit-element-ts/tsconfig.json | 22 ++++++++ .../template-lit-element-ts/vite.config.ts | 13 +++++ .../template-lit-element/_gitignore | 5 ++ .../template-lit-element/index.html | 14 +++++ .../template-lit-element/package.json | 21 +++++++ .../template-lit-element/src/my-element.js | 56 +++++++++++++++++++ .../template-lit-element/vite.config.js | 14 +++++ 12 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 packages/create-app/template-lit-element-ts/_gitignore create mode 100644 packages/create-app/template-lit-element-ts/index.html create mode 100644 packages/create-app/template-lit-element-ts/package.json create mode 100644 packages/create-app/template-lit-element-ts/src/my-element.ts create mode 100644 packages/create-app/template-lit-element-ts/tsconfig.json create mode 100644 packages/create-app/template-lit-element-ts/vite.config.ts create mode 100644 packages/create-app/template-lit-element/_gitignore create mode 100644 packages/create-app/template-lit-element/index.html create mode 100644 packages/create-app/template-lit-element/package.json create mode 100644 packages/create-app/template-lit-element/src/my-element.js create mode 100644 packages/create-app/template-lit-element/vite.config.js diff --git a/packages/create-app/index.js b/packages/create-app/index.js index d3b2f56118ca26..20476ca51d5755 100755 --- a/packages/create-app/index.js +++ b/packages/create-app/index.js @@ -5,7 +5,14 @@ const fs = require('fs') const path = require('path') const argv = require('minimist')(process.argv.slice(2)) const { prompt } = require('enquirer') -const { yellow, green, cyan, magenta, stripColors } = require('kolorist') +const { + yellow, + green, + cyan, + magenta, + lightRed, + stripColors +} = require('kolorist') const cwd = process.cwd() @@ -16,7 +23,9 @@ const TEMPLATES = [ cyan('react'), cyan('react-ts'), magenta('preact'), - magenta('preact-ts') + magenta('preact-ts'), + lightRed('lit-element'), + lightRed('lit-element-ts') ] const renameFiles = { diff --git a/packages/create-app/template-lit-element-ts/_gitignore b/packages/create-app/template-lit-element-ts/_gitignore new file mode 100644 index 00000000000000..759ef536c80bce --- /dev/null +++ b/packages/create-app/template-lit-element-ts/_gitignore @@ -0,0 +1,5 @@ +node_modules +.DS_Store +dist +types +*.local diff --git a/packages/create-app/template-lit-element-ts/index.html b/packages/create-app/template-lit-element-ts/index.html new file mode 100644 index 00000000000000..b00bc926b11fa6 --- /dev/null +++ b/packages/create-app/template-lit-element-ts/index.html @@ -0,0 +1,14 @@ + + + + + + Vite + Lit-Element App + + + + +

This is child content

+
+ + diff --git a/packages/create-app/template-lit-element-ts/package.json b/packages/create-app/template-lit-element-ts/package.json new file mode 100644 index 00000000000000..c4c4234f47e176 --- /dev/null +++ b/packages/create-app/template-lit-element-ts/package.json @@ -0,0 +1,24 @@ +{ + "name": "my-vite-element", + "version": "0.0.0", + "main": "dist/my-vite-element.es.js", + "exports": { + ".": "./dist/my-vite-element.es.js" + }, + "types": "types/my-element.d.ts", + "files": [ + "dist", + "types" + ], + "scripts": { + "dev": "vite", + "build": "tsc --emitDeclarationOnly && vite build" + }, + "dependencies": { + "lit-element": "^2.4.0" + }, + "devDependencies": { + "vite": "^2.0.0-beta.45", + "typescript": "^4.1.3" + } +} diff --git a/packages/create-app/template-lit-element-ts/src/my-element.ts b/packages/create-app/template-lit-element-ts/src/my-element.ts new file mode 100644 index 00000000000000..e7bceb52b0e78f --- /dev/null +++ b/packages/create-app/template-lit-element-ts/src/my-element.ts @@ -0,0 +1,55 @@ +import { LitElement, html, customElement, property, css } from 'lit-element' + +/** + * An example element. + * + * @slot - This element has a slot + * @csspart button - The button + */ +@customElement('my-element') +export class MyElement extends LitElement { + static styles = css` + :host { + display: block; + border: solid 1px gray; + padding: 16px; + max-width: 800px; + } + ` + + /** + * The name to say "Hello" to. + */ + @property() + name = 'World' + + /** + * The number of times the button has been clicked. + */ + @property({ type: Number }) + count = 0 + + render() { + return html` +

Hello, ${this.name}!

+ + + ` + } + + private _onClick() { + this.count++ + } + + foo(): string { + return 'foo' + } +} + +declare global { + interface HTMLElementTagNameMap { + 'my-element': MyElement + } +} diff --git a/packages/create-app/template-lit-element-ts/tsconfig.json b/packages/create-app/template-lit-element-ts/tsconfig.json new file mode 100644 index 00000000000000..18408e59ebca10 --- /dev/null +++ b/packages/create-app/template-lit-element-ts/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "esnext", + "lib": ["es2017", "dom", "dom.iterable"], + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "outDir": "./types", + "rootDir": "./src", + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "moduleResolution": "node", + "allowSyntheticDefaultImports": true, + "experimentalDecorators": true, + "forceConsistentCasingInFileNames": true + }, + "include": ["src/**/*.ts"], + "exclude": [] +} diff --git a/packages/create-app/template-lit-element-ts/vite.config.ts b/packages/create-app/template-lit-element-ts/vite.config.ts new file mode 100644 index 00000000000000..21ecab08cec62f --- /dev/null +++ b/packages/create-app/template-lit-element-ts/vite.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from 'vite' + +export default defineConfig({ + build: { + lib: { + entry: 'src/my-element.ts', + formats: ['es'] + }, + rollupOptions: { + external: /^lit-element/ + } + } +}) diff --git a/packages/create-app/template-lit-element/_gitignore b/packages/create-app/template-lit-element/_gitignore new file mode 100644 index 00000000000000..d451ff16c1010b --- /dev/null +++ b/packages/create-app/template-lit-element/_gitignore @@ -0,0 +1,5 @@ +node_modules +.DS_Store +dist +dist-ssr +*.local diff --git a/packages/create-app/template-lit-element/index.html b/packages/create-app/template-lit-element/index.html new file mode 100644 index 00000000000000..697460cac07c22 --- /dev/null +++ b/packages/create-app/template-lit-element/index.html @@ -0,0 +1,14 @@ + + + + + + Vite + Lit-Element App + + + + +

This is child content

+
+ + diff --git a/packages/create-app/template-lit-element/package.json b/packages/create-app/template-lit-element/package.json new file mode 100644 index 00000000000000..69156948bd0756 --- /dev/null +++ b/packages/create-app/template-lit-element/package.json @@ -0,0 +1,21 @@ +{ + "name": "my-vite-element", + "version": "0.0.0", + "main": "dist/my-vite-element.es.js", + "exports": { + ".": "./dist/my-vite-element.es.js" + }, + "files": [ + "dist" + ], + "scripts": { + "dev": "vite", + "build": "vite build" + }, + "dependencies": { + "lit-element": "^2.4.0" + }, + "devDependencies": { + "vite": "^2.0.0-beta.45" + } +} diff --git a/packages/create-app/template-lit-element/src/my-element.js b/packages/create-app/template-lit-element/src/my-element.js new file mode 100644 index 00000000000000..cc9236118dfb6a --- /dev/null +++ b/packages/create-app/template-lit-element/src/my-element.js @@ -0,0 +1,56 @@ +import { LitElement, html, css } from 'lit-element' + +/** + * An example element. + * + * @slot - This element has a slot + * @csspart button - The button + */ +export class MyElement extends LitElement { + static get styles() { + return css` + :host { + display: block; + border: solid 1px gray; + padding: 16px; + max-width: 800px; + } + ` + } + + static get properties() { + return { + /** + * The name to say "Hello" to. + */ + name: { type: String }, + + /** + * The number of times the button has been clicked. + */ + count: { type: Number } + } + } + + constructor() { + super() + this.name = 'World' + this.count = 0 + } + + render() { + return html` +

Hello, ${this.name}!

+ + + ` + } + + _onClick() { + this.count++ + } +} + +window.customElements.define('my-element', MyElement) diff --git a/packages/create-app/template-lit-element/vite.config.js b/packages/create-app/template-lit-element/vite.config.js new file mode 100644 index 00000000000000..4580223e12b4c6 --- /dev/null +++ b/packages/create-app/template-lit-element/vite.config.js @@ -0,0 +1,14 @@ +/** + * @type {import('vite').UserConfig} + */ +export default { + build: { + lib: { + entry: 'src/my-element.js', + formats: ['es'] + }, + rollupOptions: { + external: /^lit-element/ + } + } +} From e734e21967d63f1e62bd2bb2b8463b595087b23c Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 23:11:23 -0500 Subject: [PATCH 279/514] chore: tweak lit-element template --- docs/guide/index.md | 2 ++ packages/create-app/template-lit-element-ts/package.json | 2 +- packages/create-app/template-lit-element-ts/tsconfig.json | 5 ++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/guide/index.md b/docs/guide/index.md index 622d650d86fa71..49499abf5d287b 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -37,6 +37,8 @@ Supported template presets include: - `react-ts` - `preact` - `preact-ts` +- `lit-element` +- `lit-element-ts` See [@vitejs/create-app](https://github.com/vitejs/vite/tree/main/packages/create-app) for more details on each template. diff --git a/packages/create-app/template-lit-element-ts/package.json b/packages/create-app/template-lit-element-ts/package.json index c4c4234f47e176..efbf838b349dac 100644 --- a/packages/create-app/template-lit-element-ts/package.json +++ b/packages/create-app/template-lit-element-ts/package.json @@ -12,7 +12,7 @@ ], "scripts": { "dev": "vite", - "build": "tsc --emitDeclarationOnly && vite build" + "build": "tsc && vite build" }, "dependencies": { "lit-element": "^2.4.0" diff --git a/packages/create-app/template-lit-element-ts/tsconfig.json b/packages/create-app/template-lit-element-ts/tsconfig.json index 18408e59ebca10..6e0c0fa49b2748 100644 --- a/packages/create-app/template-lit-element-ts/tsconfig.json +++ b/packages/create-app/template-lit-element-ts/tsconfig.json @@ -2,9 +2,8 @@ "compilerOptions": { "module": "esnext", "lib": ["es2017", "dom", "dom.iterable"], - "declaration": true, - "declarationMap": true, - "sourceMap": true, + "types": ["vite/client"], + "emitDeclarationOnly": true, "outDir": "./types", "rootDir": "./src", "strict": true, From 1ddbc57b70881a2681ae5fa6ce4cbbc3714c1740 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 23:12:10 -0500 Subject: [PATCH 280/514] release: v2.0.0-beta.48 --- packages/vite/CHANGELOG.md | 18 ++++++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index e87b31b635dcc2..8934a49c15626a 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,21 @@ +# [2.0.0-beta.48](https://github.com/vitejs/vite/compare/v2.0.0-beta.47...v2.0.0-beta.48) (2021-01-25) + + +### Bug Fixes + +* externalize known css types during dep-prebundling ([02a0324](https://github.com/vitejs/vite/commit/02a0324a56fcc3659ace4b62f96b2a8b10979f4c)), closes [#1695](https://github.com/vitejs/vite/issues/1695) +* fallback to static middleware on unfound source maps ([2096309](https://github.com/vitejs/vite/commit/2096309bee0f4ad838cde2a9dd9114b819e462c4)) +* preload marker incorrect replacement ([7f83deb](https://github.com/vitejs/vite/commit/7f83deb7fe5add6117f8f715fc3165511761d07b)) +* remove preload markers in all cases ([6cd2d35](https://github.com/vitejs/vite/commit/6cd2d35d791311de953b7a832a877b1c98e2b2ed)), closes [#1694](https://github.com/vitejs/vite/issues/1694) +* resolve library entry ([3240db1](https://github.com/vitejs/vite/commit/3240db19d33f0816e3c52a5042161a94753879d9)) + + +### Features + +* resolved ids rollup compat for win32 ([#1693](https://github.com/vitejs/vite/issues/1693)) ([e2137b7](https://github.com/vitejs/vite/commit/e2137b71a5a82580b2cf45e84ead136052014ac7)), closes [#1522](https://github.com/vitejs/vite/issues/1522) + + + # [2.0.0-beta.47](https://github.com/vitejs/vite/compare/v2.0.0-beta.46...v2.0.0-beta.47) (2021-01-24) diff --git a/packages/vite/package.json b/packages/vite/package.json index b91c1b34a3912d..da4707d14d88de 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.47", + "version": "2.0.0-beta.48", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From fa1229abc5602f14cf88470b7337e085164a989e Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 23:13:24 -0500 Subject: [PATCH 281/514] feat: bump vuedx versions --- packages/create-app/template-vue-ts/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/create-app/template-vue-ts/package.json b/packages/create-app/template-vue-ts/package.json index c3f361935917d1..bd8a9b5c52af06 100644 --- a/packages/create-app/template-vue-ts/package.json +++ b/packages/create-app/template-vue-ts/package.json @@ -12,8 +12,8 @@ "devDependencies": { "@vitejs/plugin-vue": "^1.1.2", "@vue/compiler-sfc": "^3.0.5", - "@vuedx/typecheck": "^0.4.1", - "@vuedx/typescript-plugin-vue": "^0.4.1", + "@vuedx/typecheck": "^0.6.0", + "@vuedx/typescript-plugin-vue": "^0.6.0", "typescript": "^4.1.3", "vite": "^2.0.0-beta.45" } From 784bf3bdc33161a4adb087e54d3becb40055b72c Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 24 Jan 2021 23:13:43 -0500 Subject: [PATCH 282/514] release: create-app@1.5.0 --- packages/create-app/CHANGELOG.md | 10 ++++++++++ packages/create-app/package.json | 2 +- .../create-app/template-lit-element-ts/package.json | 4 ++-- packages/create-app/template-lit-element/package.json | 4 ++-- packages/create-app/template-preact-ts/package.json | 2 +- packages/create-app/template-preact/package.json | 2 +- packages/create-app/template-react-ts/package.json | 2 +- packages/create-app/template-react/package.json | 2 +- packages/create-app/template-vanilla/package.json | 2 +- packages/create-app/template-vue-ts/package.json | 2 +- packages/create-app/template-vue/package.json | 2 +- 11 files changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/create-app/CHANGELOG.md b/packages/create-app/CHANGELOG.md index f4fd55d948b074..368a17c26d8da5 100644 --- a/packages/create-app/CHANGELOG.md +++ b/packages/create-app/CHANGELOG.md @@ -1,3 +1,13 @@ +# [1.5.0](https://github.com/vitejs/vite/compare/create-app@1.4.0...create-app@1.5.0) (2021-01-25) + + +### Features + +* bump vuedx versions ([fa1229a](https://github.com/vitejs/vite/commit/fa1229abc5602f14cf88470b7337e085164a989e)) +* lit-element templates ([830f3d3](https://github.com/vitejs/vite/commit/830f3d34f58cfa7680e1b2d753a023bcb1018ba2)), closes [#1684](https://github.com/vitejs/vite/issues/1684) + + + # [1.4.0](https://github.com/vitejs/vite/compare/create-app@1.3.0...create-app@1.4.0) (2021-01-24) diff --git a/packages/create-app/package.json b/packages/create-app/package.json index 4b76d9c02d8cff..a43e1a0f8ff9ae 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/create-app", - "version": "1.4.0", + "version": "1.5.0", "license": "MIT", "author": "Evan You", "bin": { diff --git a/packages/create-app/template-lit-element-ts/package.json b/packages/create-app/template-lit-element-ts/package.json index efbf838b349dac..9f92025b3a24b9 100644 --- a/packages/create-app/template-lit-element-ts/package.json +++ b/packages/create-app/template-lit-element-ts/package.json @@ -18,7 +18,7 @@ "lit-element": "^2.4.0" }, "devDependencies": { - "vite": "^2.0.0-beta.45", + "vite": "^2.0.0-beta.48", "typescript": "^4.1.3" } -} +} \ No newline at end of file diff --git a/packages/create-app/template-lit-element/package.json b/packages/create-app/template-lit-element/package.json index 69156948bd0756..e1cbdd1bdc547d 100644 --- a/packages/create-app/template-lit-element/package.json +++ b/packages/create-app/template-lit-element/package.json @@ -16,6 +16,6 @@ "lit-element": "^2.4.0" }, "devDependencies": { - "vite": "^2.0.0-beta.45" + "vite": "^2.0.0-beta.48" } -} +} \ No newline at end of file diff --git a/packages/create-app/template-preact-ts/package.json b/packages/create-app/template-preact-ts/package.json index 1a4619feb0eb23..06d3c32c204c54 100644 --- a/packages/create-app/template-preact-ts/package.json +++ b/packages/create-app/template-preact-ts/package.json @@ -12,6 +12,6 @@ "devDependencies": { "@prefresh/vite": "^2.0.0", "typescript": "^4.1.3", - "vite": "^2.0.0-beta.45" + "vite": "^2.0.0-beta.48" } } \ No newline at end of file diff --git a/packages/create-app/template-preact/package.json b/packages/create-app/template-preact/package.json index 4d14496fa58568..3d60432c661360 100644 --- a/packages/create-app/template-preact/package.json +++ b/packages/create-app/template-preact/package.json @@ -11,6 +11,6 @@ }, "devDependencies": { "@prefresh/vite": "^2.0.0", - "vite": "^2.0.0-beta.45" + "vite": "^2.0.0-beta.48" } } \ No newline at end of file diff --git a/packages/create-app/template-react-ts/package.json b/packages/create-app/template-react-ts/package.json index 162902044fcac8..eb47f8ec2d7e02 100644 --- a/packages/create-app/template-react-ts/package.json +++ b/packages/create-app/template-react-ts/package.json @@ -15,6 +15,6 @@ "@types/react-dom": "^17.0.0", "@vitejs/plugin-react-refresh": "^1.1.0", "typescript": "^4.1.2", - "vite": "^2.0.0-beta.45" + "vite": "^2.0.0-beta.48" } } \ No newline at end of file diff --git a/packages/create-app/template-react/package.json b/packages/create-app/template-react/package.json index 32c81afcd226b6..18b0cc5ecce5dc 100644 --- a/packages/create-app/template-react/package.json +++ b/packages/create-app/template-react/package.json @@ -12,6 +12,6 @@ }, "devDependencies": { "@vitejs/plugin-react-refresh": "^1.1.0", - "vite": "^2.0.0-beta.45" + "vite": "^2.0.0-beta.48" } } \ No newline at end of file diff --git a/packages/create-app/template-vanilla/package.json b/packages/create-app/template-vanilla/package.json index 213af9e4a9250e..3f56e6351e32c8 100644 --- a/packages/create-app/template-vanilla/package.json +++ b/packages/create-app/template-vanilla/package.json @@ -7,6 +7,6 @@ "serve": "vite preview" }, "devDependencies": { - "vite": "^2.0.0-beta.45" + "vite": "^2.0.0-beta.48" } } \ No newline at end of file diff --git a/packages/create-app/template-vue-ts/package.json b/packages/create-app/template-vue-ts/package.json index bd8a9b5c52af06..493aae70ea9567 100644 --- a/packages/create-app/template-vue-ts/package.json +++ b/packages/create-app/template-vue-ts/package.json @@ -15,6 +15,6 @@ "@vuedx/typecheck": "^0.6.0", "@vuedx/typescript-plugin-vue": "^0.6.0", "typescript": "^4.1.3", - "vite": "^2.0.0-beta.45" + "vite": "^2.0.0-beta.48" } } \ No newline at end of file diff --git a/packages/create-app/template-vue/package.json b/packages/create-app/template-vue/package.json index 0e80534f6dc84f..5c209e55937c94 100644 --- a/packages/create-app/template-vue/package.json +++ b/packages/create-app/template-vue/package.json @@ -12,6 +12,6 @@ "devDependencies": { "@vitejs/plugin-vue": "^1.1.2", "@vue/compiler-sfc": "^3.0.5", - "vite": "^2.0.0-beta.45" + "vite": "^2.0.0-beta.48" } } \ No newline at end of file From 6c96883d794d3396e890907df6b799d79a027420 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 25 Jan 2021 10:58:24 -0500 Subject: [PATCH 283/514] fix(optimizer): fix output to entry matching logic close #1704 --- packages/vite/src/node/optimizer/index.ts | 24 ++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 27e9c5614d340e..81e4fadb26a203 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -258,27 +258,33 @@ export async function optimizeDeps( const meta = JSON.parse(fs.readFileSync(esbuildMetaPath, 'utf-8')) await init + const entryToIdMap: Record = {} + for (const id in qualified) { + entryToIdMap[qualified[id]] = id + } + for (const output in meta.outputs) { - if (/chunk\.\w+\.js$/.test(output)) continue - const absolute = normalizePath(path.resolve(output)) - const relative = normalizePath(path.relative(cacheDir, absolute)) - const generateExports = meta.outputs[output].exports - for (const id in qualified) { - const entry = qualified[id] - if (entry.replace(/\.mjs$/, '.js').endsWith(relative)) { + if (/\.vite[\/\\]chunk\.\w+\.js$/.test(output) || output.endsWith('.map')) + continue + const { inputs, exports: generatedExports } = meta.outputs[output] + for (const input in inputs) { + const entry = normalizePath(path.resolve(input)) + const id = entryToIdMap[entry] + if (id) { // check if this is a cjs dep. const [imports, exports] = parse(fs.readFileSync(entry, 'utf-8')) data.optimized[id] = { - file: absolute, + file: normalizePath(path.resolve(output)), needsInterop: // entry has no ESM syntax - likely CJS or UMD (!exports.length && !imports.length) || // if a peer dep used require() on a ESM dep, esbuild turns the // ESM dep's entry chunk into a single default export... detect // such cases by checking exports mismatch, and force interop. - (isSingleDefaultExport(generateExports) && + (isSingleDefaultExport(generatedExports) && !isSingleDefaultExport(exports)) } + break } } } From cbeb9ba7c7a192e61279fb00b543b81843663bc1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 25 Jan 2021 11:13:25 -0500 Subject: [PATCH 284/514] fix: fix hmr.path option normalization close #1705 --- packages/vite/src/node/config.ts | 17 +++++------------ .../vite/src/node/plugins/clientInjections.ts | 3 ++- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 880db15f445c99..dbef6a630129c1 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -251,6 +251,10 @@ export async function resolveConfig( } const BASE_URL = resolveBaseUrl(config.base, command === 'build', logger) + // adjust hmr path config + if (isObject(config.server?.hmr) && config.server?.hmr.path) { + config.server.hmr.path = path.posix.join(BASE_URL, config.server.hmr.path) + } const resolvedBuildOptions = resolveBuildOptions(config.build) @@ -281,17 +285,6 @@ export async function resolveConfig( ? createFilter(config.assetsInclude) : () => false - let hmr = config.server?.hmr === true ? {} : config.server?.hmr - hmr = { - ...hmr, - path: BASE_URL !== '/' ? BASE_URL.substr(1) : undefined - } - - const server = { - ...config.server, - hmr - } - const resolved = { ...config, configFile: configFile ? normalizePath(configFile) : undefined, @@ -303,7 +296,7 @@ export async function resolveConfig( optimizeCacheDir, alias: resolvedAlias, plugins: userPlugins, - server, + server: config.server || {}, build: resolvedBuildOptions, env: { ...userEnv, diff --git a/packages/vite/src/node/plugins/clientInjections.ts b/packages/vite/src/node/plugins/clientInjections.ts index ee7e03f5818e72..4df23fa12dd6cc 100644 --- a/packages/vite/src/node/plugins/clientInjections.ts +++ b/packages/vite/src/node/plugins/clientInjections.ts @@ -1,3 +1,4 @@ +import path from 'path' import { Plugin } from '../plugin' import { ResolvedConfig } from '../config' import { CLIENT_ENTRY } from '../constants' @@ -31,7 +32,7 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin { port = String(options.port || config.server.port!) } if (options.path) { - port = `${port}/${options.path}` + port = path.posix.normalize(`${port}/${options.path}`) } return code From 68960f7867be13cfdce9ea49a8cc05448dff5e60 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 25 Jan 2021 11:30:51 -0500 Subject: [PATCH 285/514] fix(ssr): generate same asset url links for ssr build fix #1711 --- packages/playground/ssr/src/assets/asset.png | Bin 0 -> 12772 bytes packages/playground/ssr/src/vue/Async.vue | 1 + packages/vite/src/node/build.ts | 14 ++++++-------- 3 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 packages/playground/ssr/src/assets/asset.png diff --git a/packages/playground/ssr/src/assets/asset.png b/packages/playground/ssr/src/assets/asset.png new file mode 100644 index 0000000000000000000000000000000000000000..1b3356a746b8bb5510aaee51f7df5aea4378ee8d GIT binary patch literal 12772 zcmch82T)Ym)-H$&N*olL90vnANET3%3IdXIY@%ek$x$T;2*MyJ*+y~(p$Scr3=&#V zauARp&>%U(zmMb0?|pUet@~cpyH;6pHhZnL_ln2ZQ@20&bcI#; zRb1q(Z0+v)xLIlXsA|D|?BU{;Y%QIg6L0gA+o+ON#9WUkUItw9LoG z@?#6qUW)C{L+PnJV3BinvtkkE73P8S3*2B473UQY7PuiMz|A7aFCfInFT^Jx#3LXm z!7nZ$Ak6af4;zr?W@#;0kvqd6ZB>4C|Jw16ng?OFaZ1@Dk#l`vf1^EO8 zdB6@HgtrsY+>6Hv!TuKqc`F3m&CUgB=j_A+aWuDZc1KFFfs_7u1xFVZmA@G~A$}?f zsEp6c+=Wkom!Hqk5xUop-3X+H)&CyjpYBFzdAnHgX;>kg-QD289@gxC5d+=*dqL1f za2g4DXSlngl@s!wyc8Q);kC50l(;P_D#|Y+&o3r=TUJ0oK}c4VUtU3hUkF;26A%>o zi}s!q0%`69xB83L?r&N-#eYjHA?Idgj&yd@a&~t3%X$xNosrH6TW1#*IXRYVD&}xI zC+PV)q}!iIwQ{rbu(DKib9Q9;p&SXje{uj3VUgPcf}-N0BI1J3;l%~S#Kq*r`DGQw z

g*im?5pwfrX+|4DoMU()h{!|*|t{l(IMEdlp|e*D{S!NcF4Z{-Bs-3|CP!Zr*9 z8L#d=`P*7vqbn1>&n!RtU;S=qT#~jM$vQmzE;@a9c-rnezm%%pNUCL4Z?Ol5^T|`4 zavjWJM`*UqD*=L#ruSwfkpg`dg+WwAgBG)AJMJnzGINiKeO4G0eE->l82+&`B7#WJ+>uienjpS%Cf@_)wnS8@Lt-(ODwuJ9`ZNaR1c#{VzAzli%c zdieFczi910Q_uf9Ump#H3qJ49?XDdJEVgU0^-nuX>)vnly30Cxol4=jV*B(2W#5Q= zZoyqw)~|Z99vkShEvcZ%Gul9NJXmfqlB33(l=X+jS8v;gb!7^)K4G4vKK&sm{RpAY zXa|RLM59D+?B_$C1m;mhzR|W9s)a8;N9a~BS?g4pNK%w~aZQtaEyGUaQzjA|;I=b% zPAV^cc(RIern)a4 zhI(|wR30|9!CyKW7Euzj4~l&9N>-|XEj&zlYZ+NWMQTM+Dn>Sa|7#Z3UzI};wxS)M z5iocG$XR&=j~^L|KB-jVe&BB^c~JCVHeabiS7tMKFok0*ep-0e3Ze}V4cW;Q{F;|i zS$nM{@47r;N7}?`S6OPDO>XN^gfMC4@e4?t?VN*ih6ihdqMrioS?+n3lvoDhiA<%h z#p78S=zV$jMN1#_jm?eU)+~D8>Zr&$YG>4s?$aA0;vM3?Ri43*6b~&tl=Uo8va~MT z<>ks>Gs>e#6&&0ooD@PIXPo9!ZnA&c5Gu>&{9rQ2$Q7}1n7}39u$DbUbe3Dtk+hdq zDSK)7{F|d{*}-@89lT@N8WW)f4_Y3)=PQt3&`leqPLEq@F54On3Q{O`3Ek*NVbnPU z3HRC!)K5#DyF3No?si6u5Okc#a@1b3r+N6zae!OadVQefsha>mB{P0x2xXtyPVg#Sd}jsP;8~gz zYK^AUM8?3mAz{VD%2h0EqGie+}5cS z>3_AuW9^jOkayxhI^GLWCW2BtRp*eX>kO{Zk+g}I{px$AXrD-ryTauP;u;cGAfLT- zSD?0wa8lBaDV0a%bnCmP)=Y2PXe(WwysvAq@G|dvY)E8FQlK92Q))iT3C3DNZ8pT0 z^xBNvl&{jZjB>4M1k9s#@C})~){+R}@JjXYof(EmM3e)0b|n*jq=LwAqt8G<_*=l$ zy-rc})-+~(40YP90onyuio3BUUB~A!jMgE_o8VAUF4miGu-@zM8IP`hju<5zye^-k zeG=bdFRG?$R6^-YRJk`*b_GQE*?9u{$k?j=qd=I`1^c7fZWgmLBpnK;9ohqXv^hkb zm1KwQ+FCun1mc|jpv1JDF4(}xQXT}J7S8V~pYc=sgE@#MxS6((3x$#85G*RZy#4l= z_D$T#lY#h=bjIUB>=5fGmcizywk5(jI-HuY;=A^eXQ-7|3Q$rg5^qkMVqV3;15L#r z`WA&tUhStHJSIO3&?$Tri=9^B=*bex>D-yE$OcCG)STFdTs#_K)2-3^B#Lp6yEE{% zttT?<)JM-#X610Il@4oS&l~UWn@J4I5@y7YWV)bF9=ysF-`S(Lrmv$F=$j>r?AAMV z`~IQ~2Rq(1A6u*LH=mlaIty;}AVt{{bG2}8N)veY{ON#G| zpCH<$CHM1gPc&9Ln={MI->rfzD5VHlM%r%=#e?)i9xR0NdRcKHzH@*(KBAU<*+aze z@&F$b-7qY4u%U)i?v875tGFCGyuzB@?88-7t~9C%6lLP2+0-`*xO)4`8BY>llBHIA zFSj;Le1vbJ!xhIx?^M@|-I+0B9W%|Uq{EMtz9bVlw|0=2pF9N1%D?`xYb%W)s_Z?Q zw5Muirs2MfXOsUIiKmDb;NInp-@WzmBTp{(Jxk;B6XG~MXQ`5vo8EAnRpQlzXQ9a9 z!3Rk~>%iuQR)06kG5g-AN+{?GTIg`}Q)j6CSCmmTXr=6K@q)-$Z4-Hk!~l=eM*6Xu zZMowHW>@B!2C)oA6S3x$r-&yGYB`m(_>loreKFC&PRUA^`O%lRRiq;Z?rjb`*v;pJ zt*!1J6CHjRbv0%9u(Ombf}TG=g3g9$q{;QCE~FkBT5$%tc&mFKUJO|@JJ=^+9tWYV zcHn;4f)12eX~~PW^mXNZA!93zoPJb#1>;;8)P`4cE$uaz+&t~!@CAiw|EQfL^B}3f zF9jg>mND)ePKe>1#%q514fPsH#9t%qzh?rglEk>QZ_Q#S3MmsyxInBQwrxZ*1USKb)hd<8YTnSfa_5l-8xQ*+|7iP4f1;m58I6Nje@ z!&YMl^N!J_Ma#1yl5UKug3ZIv5kU?mnZh*qk+(1PrR;?b)S+&<0enT%apJ5 zFK^?Xjd`uq9H+aqjz+>8{MtD~I$=ZOhM?wI1ceCYe#08)QhFz`XJtsE)mbGH?Wl$L z7*BNiovp{)?b03AGKJ^gH_UwqA#NF6R#rSiEk{w#L^3hK87po#Sznl&R;~ej;^gI% zH3rOHhRpJ3T;v#a)rZ)Je9_xt^IaaE28iEEX(-3!BnwHr9~!E08R{0!6!W&V+>ZAmd&NGX)_GdboJJOVB122jrQcpF>VkQf(3Jxylq^JlpORzG5QuFIt@&2KB@ zJ(O@4thYJs1F_F@pwK#lXkYL+E0Mw-EWpqqII@#fdHF2&Bt>7f3CV;uXY77+MXkoC zK4krCRqI{Gg1!citzw11$)V@~A?Yf1tjX~+(xS5a=+pQ?4T{n|DpNAtb>N9o_U`H? zxTM>u_tz#*!{9HSq#VoA_@s5c`eZcrcV>o*QtAy@H`*#U`{VKPBc~|(>Y_uP3Y5NH zDU8hsXm~Gz{CHEuFv&vli0+?0^Lwi4IRkjY%4SG~_2VD~-|71+UD%0CN^hmBgAt=) zewPa366^2i2$M4ymby|i9rn*6a*<(|9%~L&wsVi1s2K>|ZknlXU8bsse4g3V@Y%E4 z-n$)|rxS!HW5DlKQ`S17p3^cN2Ijhi!Gib|3z7kDXm~kbaN!Jf$JLbBV{RlV09AEH zpZeBqUaDG?tGu)^O+6*A>*#p)yr`K`_3R9daq)d)+u+I#VXIqB7R3$JqwwyS9Jhn~ zjJipxGN|G_+U(#>92Ycw4rAt$&hAFTI;o$leDtaOy+aI?|P%Z*CS zB}?tO5t#@h?;VSBwK0+Kv+=t>TF_A@KC?t+T+I*B#8Q)2uX(Ju zt7e{|IKArp0#W`xSZCnr$%P-R9p{qyFtO4Awwo4xEpA4X3lN zdb=ZLd;C%Vb7M5mp|;G4lOIX^%4^CgeRsng-quQ&FhLfx50x(2I}VG*n&CIIwm)Z_ z{KjXS+EW*Rtf*NVcC2Y+4iuFRRRUMCV2HEC@D_!GEAbVRI#z+In~JHW(Vtc*ii7vB z9&RNlS2fraH^KrICe}T*OIsc@x0^9UT8^a-%2JfRVxE4+)47e_ps(nN0;Xw4GM-Vei=p_ z%18j{E+aje{#=GW@Xj2_v?UwnyIm{Ia;!!ZStJ1XV@j)A*BVUqF0Za86rimDv`o*c z=dZOk5!-v&aX4F)F3dK@RWGoU#PNhLPzyaMO;M^>8bifb>{*~>sajn%6ghf0#3@fW zAR|>5usIlRFL7*il(_enbC7j7OaRuwG~%RU&kP`G?t3|e@6-FAH;1UQlJbTGEOFAM zjw|Jk&immjd(P`NTKV;2gEOz#$L#HT2>^(v>icTKIsWCw={aX@P~+za)>3?Yt&%`Flm`>GwnnfRwZA4mCH0QH?>inQ6e#or?<}UtLS9g z!{aKumsX3J!tLGNpF+AS1|J2rW&F}I^6>p1Eo1-D(P_si<7sktg|2r;#2^j(SiN1; z6YebQf!*XT&v(a|N#@$Xi@i4Hf;|m>6=Hk6r?8VSg9_3&%S(iuYX+YW42QOa4o%WW zd|S_@N~B2eo%ZKkW~V=u~H>S$Fw2t>iEi6CblqEt7CkUl4B`YEIKDFpY zz#|;^vV=*`awq7B4fskysB)m(Ok(uAjb}2vG9t7M?nf|A%)Dr ztE%yxDbI4AQGcFtRlmE@T6U>}Vr2EcJq?hM$%taq3ca~qwymHpz?1lf-`W5kW<)qJ zdJeF^o`S!6VL}-6w~m!GQWL}+2$FfImGkKIP%*%OK}C+gK!pvcv~zI#h}d`&Zt*^a zo6q7$#S1R8nHm)o>w?JlF%i3T^KxyZHk+nZ35dFhK?GYXt%U*MI9MfAAF%{E35Z zX5|IIU{qJmR~C#2`izX96>jISe9T~Mmu0wQ>C0Ah52UQA=END~BCkgH{W%Twsg-il zI+QSVcf&Dcj4QyMZv__;%6dNkF#+M`%5SXKU=1~5AaLc5!KIZ_`>WAXl+xTVl#|RS z@t)D$P@b%zF<2kQ{Mq_|G01skF@&E4QZ!e7o_Hnnp}J(RXh*1sSs0wT18>CXt~~|7 zsG0p?JCC7R4hDUV2VwXEMLab9O1Gu#>KL&d4qWlw|>3KC=>ab>^T*Vw@5Dvyf*0YD0(l5oL(wz-)k2H=yMsg79uKt zwHCpIPUd7CH<%2|rBVl}0Tb0}lFhq|=sajhpgx7nkRW+=kR4S7S4KP9IRXWs$bR$; zPyV-OprKgTOORRg@|b>9ksTCt?wtav7j%jTP-l>QbX@WxnxkfhPB0JnX-u$CA9L8M zHGp5n(s??c)V8DEHjsBu)3n3yp_2y;&YYn>`h!c>R~z_+uY5hVRtPw2Q#Yw8C%p#%icDkL6PMXS?@wH)LTUh(4_hS`{p- zr4&sq1`Itk8h!QErL3}Kx5B*&X9U>CChU5_q&T`|2TKMlF`96xj{PHfvp{}S&4fCP zET{6!S#B|=>1SJ4QHL2yU#}OHP`_c;FQKSs3T_eLbac@VJp?a<|;Qqe0 zjJ@bL7PH%-&cQpSkh7vQuB9&$e5%i`bJbrSj=@b=hyX)~H`6|R>or?Ws`B|2=5Lr> zpLw}4xU|gOp_6_Pb*yhdf2-*+uk0W@3ZudyXxgt<46EEdC{!zX+L3WY277{Qb~IP< z(gOZv7GOj-Dh;(_bq&|FRdzYZG1D}y@Y`sAJ075tc{wq-zW`Dfz#HPjB_(yqf$f9@ z0|?uKEd?J9@Xk>8yx|Mmc>&!Snv{C8W4bko+HwqBAxIDz0>qmV_j~_$_8E}&tTorqq&Q*YYqIn zYYq2|tXxpHW^=%fKq(ItBYoLoZ}+V;`T zC-{zURz5G`QB<7Bwt5E}elWX~?S3(quWy|T#9`V3o^m-(6#>S6 zi|3}FiJs`2W0bzy4Zc@6zWLH|QK!(nkOP3Y8j>^ATQPg)yO8w#ig<;&s)XzE*?Jf~ zxpJw?&7Y0Cf%8dS;qL3j8q*kP3U7QuJ8)l2_e{rVk$V&FHBD>YcfWgWJcHD$rbNk3$AQj`y23cVG zWrV2Hc@k*X^!t7)5c71@_|4TMD4bq#nVd0QPmceU-5e}}= z0SdsCU#kTR&A?H~TH)hgA8^K{ zup*pP0%LUpfHCXsqM;qO_O^X7LfW%Z+l7?QwQhsxy%YmjUCXnebI05%tfz=YC#~?F za~ANT+(55-*`p-AI6eCE37YwNO-Mb*j=HuDSugSq)+^gObH^HwmNRG{{$?+We)%!w zEI#ppzL;jfKLDJ-V(mz)Gd3`fY;n-zkOch$uwguqXr*g4h{46)fC1&+rs#WRL%b`o zY>{>C2db%j$Ujp~V*KhZ;v^eB$%!VoxS7)!J*Z4U9e%@HzN?F6v;-$rdL$ zQhX0V4w##nlHh1TlGqG6{n-(N=^BOVCkDG&D?C~^_zGv9#?f6b3F;!!AEmgXs!|!eW&kmK)gabz4456L! zwqX99vlAYrAkeAHeXVB7?4|Wb2IyD!#NM8$FFI+5_q5Gs8mJ#O)xIN*F`oi3#`E>& z#2@njvhfH1IW?wmgJ2AOoz?HFn&YD7ZQ|}VP~gT~v>7f5UcCs~$8wEN{Y-T-Zz^}L zuh5Sa-$f9E3tE_x;x7D{6uAqOd$^pupx)(Jy)=?`7Xcs=jrH_>UkM}(lux(3TxX_~ z_aYTLSt|igAl-xCgYm;Z4tcGn*6xglRr7&yZcop!bOR9AG{v~GgcpFf4!Sd_T$#&Dw*QoqaeotqG2jp+=t)vim+_bDcQPGES4UZ5Bzk_Esy>HLT<&-M#?VfembeX2e*SJT z4^`E5C;E{zRRjTGu-Z&}5Q}xx48Q+5HlrbLmv;<1nw>vaLOk|y9K6r%{1dtqK+r`2 zj5{OJM$)QzT$4L@ZY5m;$1}!UtAJdWSrT>4XIhCUtAgii1j0;%7Wkz1Z+*jo47JJN zwbW3G7S~b^@3H^IS&>#p*0EkYUZ}Pu|BYK*G)-&AKC~`GkKID+4ln@8uVkis{GERk z422pRDc^4=H-~&ysa8dYLllz;fauNDK`fIlNLNC-RCDgzU^=vyvR>0g-EqXz4VZI3 zbvZA?SWB$UriRGW`qV*vT28tyK8uLMHS_QIcM*V^hmF}bTU^x%?@?HocptHJoePHh zG4=T!AeJ5iz@i$5VuaFt8L5K0NwDXOW<*6=q*2&_9wDIintpcj6R|kvQUS!WN6*u- z@U&k6z5M5f8$-e9JJ1_dL(LZneB-?dv+#}u7DI+H09AnI)kB01e;NHvHv4~(lJ7A zSr%KD=ofaSL#E4S;O!k()=GnSZ0sDMYv_0S{En>3lecF2F~5@xOplLvPQ@JOP!%F@ zoGS=)S^wpiN!{qN+ht~UX=*T(D}##SRx|BsBnqR%A^7A204XwW4wtptI-WjP01!nF zV24H8pW`=iUod`44eZU|!>kK*?r71qK&;tQ_L)g1bmBX;7_ToaESREE+Zb(S1K5=T z8i=?iW_toVkwckC{PFN5EIw`_z&m75avi*vHl@MrazZgOuy!_Bq=>|O$x!vxSoe)T z0>X?2?0Nw3-73yoZ;wM^?tyx(T1d66Im8&qLJWo>VGg2M0>prHvzP>D1>vuXVj5bU zUvl!E(7H|6jvHM8bTsFOb?XLyW0HaW{(z!%{Z){8Y%|L)0&3A;CtN2*C7n#CJSQY0 zOv>=fpdbd`j}o<(6Gc(h6lmtj*lKtm|ibroh%QL_Ev>4=NQL-!n@YWXFnB7j_AG#{>=QMhW zdA|*W&uR2&l*7=U8+LykKB+ra?lpFyC8HDo;}cQg$)|w{BgH@F%IY#}!8(zr$qr)! zdS|Ki@F&DfOBrNc>fDY3IalT{22uDc)){or1ZJpGbExdW6#KGe`Vc|)yJeMcN)cx^xJrGGfNNBMK zM$rOD;KKY!l$`@aP-KkSPk?RCW!=bzwhw*sn%&0Yz=p2AKUXGkD5(q*sP!ucps3V{^8cW7WfI#v`F+z_MpS<8|i^b{}<`S*bHs(-P zteX+(HkOcJeSr$=xlGXJinLzDLLth&Kz>gzI4~F$C~$ZYS7i#EA<}DNFlHJxvHCK! zq5=m=IH)Fx&bf}VmP_lgDMEpc9?)1GJhWB2M$mQ1?moz6F+e8*#(Vrijr_6gXIaef zjYA99Lcohp8lTQ0DCHLZK&}9QuE%0ZjtlGNzY*{%S{#TVwt86i+ZuMYoU{eb z#)trlq877k^Auiv5dO&Xj>I5f!u`jde&KO9f9VcP+L`bSb!j#5*!5&9-GbJpS_wut zL^JYI7U7urZWAeihA7ZL?2mHu=q(SU;cK<{Bo$NDM*+~}>_i%wt`+|1`z<2fbdB?i z&XeyRzvHI`FU7a&6Or7|2_I_CM*V1o7kx!@;2=b9J+Ee~(2Ykq*C$1TMi#%`0(>wd z3dY!rhEYfoK(Z)M6}(d|xRu&5PzEyo>mi_*nXpVgt?&kfxr7He(Uxte4?ohgKz^!P zl2Hhp*k}Alo7yj#5={lMbOP=ehczytlv+DL76R{ByktrQy3nmcsc$sEJF$G=(uA^A zavVN`(a2}e2B9e;oVnGaIC&17faIE}Zzw)=zrKqTGVS}tbW*ImwF}@JOxhP|jKC%F zUz&6}Ylf$}CcA+77e5Uzsbjhzca8ryJz#n48sN?sy2=@^=cbzl#|Nek+HwY#Ij|6{;EtnMn>5~^3_?j|usez*SXjmlq*%sG1+l z-hh_67df3O2b|)a2nb$5q-b7iM$Prl3}6M{)5?~QtL3q;_-8uscpKyqFCL&!J(nmg zdmt^ebx79tJ}q?*Jg*&Sk0cV<(_!(7mc_gKnRKAm@LRGjAEGeI9P<;#d630P^1!f9 zBh(vl?K8-kLFQ1p5J3**wbs?}{#ar4bhO39qwF!7JiuTy9>B(XHbpqj50$vQgr*n- zpX?V?W0%w7y>}}D@tqqFh;$8K;6DXnc2rI*hZq$0?A4M4O5f84gkG*ahT0Z=PAZj9 zREa{FYR&D)L|OR9BXk##sb*@b1wWI3yNn(v*{Xqe+-lhdK(Dua0fQg?P4pGbA`nDh zz-K@HD2y)0fV@Y!^WgU4D#Hxr zc;Z7muz&O69b3XMmqzkze*iOs_JQh#K^qb3GE{Q!kPK`fo;kp#(PkX`U%?3h2Hekp zF{ZJ`H{~&YuA??VvpNq&lJoI;MxYPT!m!7aL2L6*SdESw-jMdhdzJ1*Qn#{!s9)h~as!ad0K%@fDpf90I<4(3eq`@}GcpOMwk}t)^u{)$dg$b=- zI%yHKvk+dP2C=vSSPZn8`P2BZ;UIX(ZP$5VvbahcWL$FDIzR z8<0Yy1G!mmU4gIHr4rRKBA`tFIc3!LOl4M@>ezYkcns2?>+i@hAD01imLq{41sL(a zvEi|en^K}cQ6veV@*c(PhbVvl z1j}B4%FrVcee%%NRRzCp%m4zaBDcnvMyD0L(ptXNKrBmvLj_RQF2kntiq-nh0iJTx z#3-D8Q^!>V2NiTdD;@jyvx%_*|kRtWKpG%IZ+;g${P-g=xg>)s zMpIibKaDC@dJf4y3xHuBZ@_8Z77eh}ts9_>($#kHGFb>pop1VMlSlS-ju8m$M&b$P zp7o(s;^`%FZSqB`$#-XbR6wTkA(N3YM(*~(AbmiU13*1HvPL(}14f|H*HK(@zWZVU zt8-g#A?}jEq(ibpV$sZwnd#@iC!WzQAXgRkHp(OfoCmiTV*(q%0I6a>HhfD6P&6^f z4(`f%4kaHA7=N1r8Vn+ll$G34K0SSK;0$q$1|q>UX!YgEfcv*bkR$Mnt3@g%@{9`@ zZj~Sk7+&*1r&sF;0Iu@#A)vr(idnxZ`=5Lk`(OBc6{zU{@~dH>r2pV+-dUp^217t6nVH5`QcetM1u@7n`oi#fYSDd_)Q+*44MFP1fX{69{$*5UvF literal 0 HcmV?d00001 diff --git a/packages/playground/ssr/src/vue/Async.vue b/packages/playground/ssr/src/vue/Async.vue index 1f77609a1e641e..fb66f574b9f1c3 100644 --- a/packages/playground/ssr/src/vue/Async.vue +++ b/packages/playground/ssr/src/vue/Async.vue @@ -1,5 +1,6 @@ ` - : '' + function getIndexTemplate(url) { + if (isProd) { + return indexProd + } - // during dev, inject vite client + always read fresh index.html - return ( - `` + - reactPreamble + - fs.readFileSync('index.html', 'utf-8') - ) -} + // TODO handle plugin indexHtmlTransforms? + const reactPreamble = url.startsWith('/react') + ? `` + : '' + + // during dev, inject vite client + always read fresh index.html + return ( + `` + + reactPreamble + + fs.readFileSync(toAbsolute('index.html'), 'utf-8') + ) + } -async function startServer() { const app = express() /** @@ -42,6 +48,8 @@ async function startServer() { let vite if (!isProd) { vite = await require('vite').createServer({ + root, + logLevel: isTest ? 'error' : 'info', server: { middlewareMode: true } @@ -50,7 +58,11 @@ async function startServer() { app.use(vite.middlewares) } else { app.use(require('compression')()) - app.use(require('serve-static')('dist/client', { index: false })) + app.use( + require('serve-static')(toAbsolute('dist/client'), { + index: false + }) + ) } app.use('*', async (req, res, next) => { @@ -75,9 +87,16 @@ async function startServer() { } }) - app.listen(3000, () => { - console.log('http://localhost:3000') - }) + return { app, vite } +} + +if (!isTest) { + createServer().then(({ app }) => + app.listen(3000, () => { + console.log('http://localhost:3000') + }) + ) } -startServer() +// for test use +exports.createServer = createServer diff --git a/packages/playground/ssr/src/vue/Async.vue b/packages/playground/ssr/src/vue/Async.vue index fb66f574b9f1c3..fe3ba5fe6c3382 100644 --- a/packages/playground/ssr/src/vue/Async.vue +++ b/packages/playground/ssr/src/vue/Async.vue @@ -1,12 +1,16 @@ \ No newline at end of file diff --git a/packages/playground/ssr-vue/src/assets/logo.png b/packages/playground/ssr-vue/src/assets/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..f3d2503fc2a44b5053b0837ebea6e87a2d339a43 GIT binary patch literal 6849 zcmaKRcUV(fvo}bjDT-7nLI_nlK}sT_69H+`qzVWDA|yaU?}j417wLi^B1KB1SLsC& zL0ag7$U(XW5YR7p&Ux?sP$d4lvMt8C^+TcQu4F zQqv!UF!I+kw)c0jhd6+g6oCr9P?7)?!qX1ui*iL{p}sKCAGuJ{{W)0z1pLF|=>h}& zt(2Lr0Z`2ig8<5i%Zk}cO5Fm=LByqGWaS`oqChZdEFmc`0hSb#gg|Aap^{+WKOYcj zHjINK)KDG%&s?Mt4CL(T=?;~U@bU2x_mLKN!#GJuK_CzbNw5SMEJorG!}_5;?R>@1 zSl)jns3WlU7^J%=(hUtfmuUCU&C3%8B5C^f5>W2Cy8jW3#{Od{lF1}|?c61##3dzA zsPlFG;l_FzBK}8>|H_Ru_H#!_7$UH4UKo3lKOA}g1(R&|e@}GINYVzX?q=_WLZCgh z)L|eJMce`D0EIwgRaNETDsr+?vQknSGAi=7H00r`QnI%oQnFxm`G2umXso9l+8*&Q z7WqF|$p49js$mdzo^BXpH#gURy=UO;=IMrYc5?@+sR4y_?d*~0^YP7d+y0{}0)zBM zIKVM(DBvICK#~7N0a+PY6)7;u=dutmNqK3AlsrUU9U`d;msiucB_|8|2kY=(7XA;G zwDA8AR)VCA#JOkxm#6oHNS^YVuOU;8p$N)2{`;oF|rQ?B~K$%rHDxXs+_G zF5|-uqHZvSzq}L;5Kcy_P+x0${33}Ofb6+TX&=y;;PkEOpz%+_bCw_{<&~ zeLV|!bP%l1qxywfVr9Z9JI+++EO^x>ZuCK);=$VIG1`kxK8F2M8AdC$iOe3cj1fo(ce4l-9 z7*zKy3={MixvUk=enQE;ED~7tv%qh&3lR<0m??@w{ILF|e#QOyPkFYK!&Up7xWNtL zOW%1QMC<3o;G9_S1;NkPB6bqbCOjeztEc6TsBM<(q9((JKiH{01+Ud=uw9B@{;(JJ z-DxI2*{pMq`q1RQc;V8@gYAY44Z!%#W~M9pRxI(R?SJ7sy7em=Z5DbuDlr@*q|25V)($-f}9c#?D%dU^RS<(wz?{P zFFHtCab*!rl(~j@0(Nadvwg8q|4!}L^>d?0al6}Rrv9$0M#^&@zjbfJy_n!%mVHK4 z6pLRIQ^Uq~dnyy$`ay51Us6WaP%&O;@49m&{G3z7xV3dLtt1VTOMYl3UW~Rm{Eq4m zF?Zl_v;?7EFx1_+#WFUXxcK78IV)FO>42@cm@}2I%pVbZqQ}3;p;sDIm&knay03a^ zn$5}Q$G!@fTwD$e(x-~aWP0h+4NRz$KlnO_H2c< z(XX#lPuW_%H#Q+c&(nRyX1-IadKR-%$4FYC0fsCmL9ky3 zKpxyjd^JFR+vg2!=HWf}2Z?@Td`0EG`kU?{8zKrvtsm)|7>pPk9nu@2^z96aU2<#` z2QhvH5w&V;wER?mopu+nqu*n8p~(%QkwSs&*0eJwa zMXR05`OSFpfyRb!Y_+H@O%Y z0=K^y6B8Gcbl?SA)qMP3Z+=C(?8zL@=74R=EVnE?vY!1BQy2@q*RUgRx4yJ$k}MnL zs!?74QciNb-LcG*&o<9=DSL>1n}ZNd)w1z3-0Pd^4ED1{qd=9|!!N?xnXjM!EuylY z5=!H>&hSofh8V?Jofyd!h`xDI1fYAuV(sZwwN~{$a}MX^=+0TH*SFp$vyxmUv7C*W zv^3Gl0+eTFgBi3FVD;$nhcp)ka*4gSskYIqQ&+M}xP9yLAkWzBI^I%zR^l1e?bW_6 zIn{mo{dD=)9@V?s^fa55jh78rP*Ze<3`tRCN4*mpO$@7a^*2B*7N_|A(Ve2VB|)_o z$=#_=aBkhe(ifX}MLT()@5?OV+~7cXC3r!%{QJxriXo9I%*3q4KT4Xxzyd{ z9;_%=W%q!Vw$Z7F3lUnY+1HZ*lO;4;VR2+i4+D(m#01OYq|L_fbnT;KN<^dkkCwtd zF7n+O7KvAw8c`JUh6LmeIrk4`F3o|AagKSMK3))_5Cv~y2Bb2!Ibg9BO7Vkz?pAYX zoI=B}+$R22&IL`NCYUYjrdhwjnMx_v=-Qcx-jmtN>!Zqf|n1^SWrHy zK|MwJ?Z#^>)rfT5YSY{qjZ&`Fjd;^vv&gF-Yj6$9-Dy$<6zeP4s+78gS2|t%Z309b z0^fp~ue_}i`U9j!<|qF92_3oB09NqgAoehQ`)<)dSfKoJl_A6Ec#*Mx9Cpd-p#$Ez z={AM*r-bQs6*z$!*VA4|QE7bf@-4vb?Q+pPKLkY2{yKsw{&udv_2v8{Dbd zm~8VAv!G~s)`O3|Q6vFUV%8%+?ZSVUa(;fhPNg#vab@J*9XE4#D%)$UU-T5`fwjz! z6&gA^`OGu6aUk{l*h9eB?opVdrHK>Q@U>&JQ_2pR%}TyOXGq_6s56_`U(WoOaAb+K zXQr#6H}>a-GYs9^bGP2Y&hSP5gEtW+GVC4=wy0wQk=~%CSXj=GH6q z-T#s!BV`xZVxm{~jr_ezYRpqqIcXC=Oq`b{lu`Rt(IYr4B91hhVC?yg{ol4WUr3v9 zOAk2LG>CIECZ-WIs0$N}F#eoIUEtZudc7DPYIjzGqDLWk_A4#(LgacooD z2K4IWs@N`Bddm-{%oy}!k0^i6Yh)uJ1S*90>|bm3TOZxcV|ywHUb(+CeX-o1|LTZM zwU>dY3R&U)T(}5#Neh?-CWT~@{6Ke@sI)uSuzoah8COy)w)B)aslJmp`WUcjdia-0 zl2Y}&L~XfA`uYQboAJ1;J{XLhYjH){cObH3FDva+^8ioOQy%Z=xyjGLmWMrzfFoH; zEi3AG`_v+%)&lDJE;iJWJDI@-X9K5O)LD~j*PBe(wu+|%ar~C+LK1+-+lK=t# z+Xc+J7qp~5q=B~rD!x78)?1+KUIbYr^5rcl&tB-cTtj+e%{gpZZ4G~6r15+d|J(ky zjg@@UzMW0k9@S#W(1H{u;Nq(7llJbq;;4t$awM;l&(2s+$l!Ay9^Ge|34CVhr7|BG z?dAR83smef^frq9V(OH+a+ki#q&-7TkWfFM=5bsGbU(8mC;>QTCWL5ydz9s6k@?+V zcjiH`VI=59P-(-DWXZ~5DH>B^_H~;4$)KUhnmGo*G!Tq8^LjfUDO)lASN*=#AY_yS zqW9UX(VOCO&p@kHdUUgsBO0KhXxn1sprK5h8}+>IhX(nSXZKwlNsjk^M|RAaqmCZB zHBolOHYBas@&{PT=R+?d8pZu zUHfyucQ`(umXSW7o?HQ3H21M`ZJal+%*)SH1B1j6rxTlG3hx1IGJN^M7{$j(9V;MZ zRKybgVuxKo#XVM+?*yTy{W+XHaU5Jbt-UG33x{u(N-2wmw;zzPH&4DE103HV@ER86 z|FZEmQb|&1s5#`$4!Cm}&`^{(4V}OP$bk`}v6q6rm;P!H)W|2i^e{7lTk2W@jo_9q z*aw|U7#+g59Fv(5qI`#O-qPj#@_P>PC#I(GSp3DLv7x-dmYK=C7lPF8a)bxb=@)B1 zUZ`EqpXV2dR}B&r`uM}N(TS99ZT0UB%IN|0H%DcVO#T%L_chrgn#m6%x4KE*IMfjX zJ%4veCEqbXZ`H`F_+fELMC@wuy_ch%t*+Z+1I}wN#C+dRrf2X{1C8=yZ_%Pt6wL_~ zZ2NN-hXOT4P4n$QFO7yYHS-4wF1Xfr-meG9Pn;uK51?hfel`d38k{W)F*|gJLT2#T z<~>spMu4(mul-8Q3*pf=N4DcI)zzjqAgbE2eOT7~&f1W3VsdD44Ffe;3mJp-V@8UC z)|qnPc12o~$X-+U@L_lWqv-RtvB~%hLF($%Ew5w>^NR82qC_0FB z)=hP1-OEx?lLi#jnLzH}a;Nvr@JDO-zQWd}#k^an$Kwml;MrD&)sC5b`s0ZkVyPkb zt}-jOq^%_9>YZe7Y}PhW{a)c39G`kg(P4@kxjcYfgB4XOOcmezdUI7j-!gs7oAo2o zx(Ph{G+YZ`a%~kzK!HTAA5NXE-7vOFRr5oqY$rH>WI6SFvWmahFav!CfRMM3%8J&c z*p+%|-fNS_@QrFr(at!JY9jCg9F-%5{nb5Bo~z@Y9m&SHYV`49GAJjA5h~h4(G!Se zZmK{Bo7ivCfvl}@A-ptkFGcWXAzj3xfl{evi-OG(TaCn1FAHxRc{}B|x+Ua1D=I6M z!C^ZIvK6aS_c&(=OQDZfm>O`Nxsw{ta&yiYPA~@e#c%N>>#rq)k6Aru-qD4(D^v)y z*>Rs;YUbD1S8^D(ps6Jbj0K3wJw>L4m)0e(6Pee3Y?gy9i0^bZO?$*sv+xKV?WBlh zAp*;v6w!a8;A7sLB*g-^<$Z4L7|5jXxxP1}hQZ<55f9<^KJ>^mKlWSGaLcO0=$jem zWyZkRwe~u{{tU63DlCaS9$Y4CP4f?+wwa(&1ou)b>72ydrFvm`Rj-0`kBJgK@nd(*Eh!(NC{F-@=FnF&Y!q`7){YsLLHf0_B6aHc# z>WIuHTyJwIH{BJ4)2RtEauC7Yq7Cytc|S)4^*t8Va3HR zg=~sN^tp9re@w=GTx$;zOWMjcg-7X3Wk^N$n;&Kf1RgVG2}2L-(0o)54C509C&77i zrjSi{X*WV=%C17((N^6R4Ya*4#6s_L99RtQ>m(%#nQ#wrRC8Y%yxkH;d!MdY+Tw@r zjpSnK`;C-U{ATcgaxoEpP0Gf+tx);buOMlK=01D|J+ROu37qc*rD(w`#O=3*O*w9?biwNoq3WN1`&Wp8TvKj3C z3HR9ssH7a&Vr<6waJrU zdLg!ieYz%U^bmpn%;(V%%ugMk92&?_XX1K@mwnVSE6!&%P%Wdi7_h`CpScvspMx?N zQUR>oadnG17#hNc$pkTp+9lW+MBKHRZ~74XWUryd)4yd zj98$%XmIL4(9OnoeO5Fnyn&fpQ9b0h4e6EHHw*l68j;>(ya`g^S&y2{O8U>1*>4zR zq*WSI_2o$CHQ?x0!wl9bpx|Cm2+kFMR)oMud1%n2=qn5nE&t@Fgr#=Zv2?}wtEz^T z9rrj=?IH*qI5{G@Rn&}^Z{+TW}mQeb9=8b<_a`&Cm#n%n~ zU47MvCBsdXFB1+adOO)03+nczfWa#vwk#r{o{dF)QWya9v2nv43Zp3%Ps}($lA02*_g25t;|T{A5snSY?3A zrRQ~(Ygh_ebltHo1VCbJb*eOAr;4cnlXLvI>*$-#AVsGg6B1r7@;g^L zFlJ_th0vxO7;-opU@WAFe;<}?!2q?RBrFK5U{*ai@NLKZ^};Ul}beukveh?TQn;$%9=R+DX07m82gP$=}Uo_%&ngV`}Hyv8g{u z3SWzTGV|cwQuFIs7ZDOqO_fGf8Q`8MwL}eUp>q?4eqCmOTcwQuXtQckPy|4F1on8l zP*h>d+cH#XQf|+6c|S{7SF(Lg>bR~l(0uY?O{OEVlaxa5@e%T&xju=o1`=OD#qc16 zSvyH*my(dcp6~VqR;o(#@m44Lug@~_qw+HA=mS#Z^4reBy8iV?H~I;{LQWk3aKK8$bLRyt$g?- { + app.mount('#app') +}) diff --git a/packages/playground/ssr-vue/src/entry-server.js b/packages/playground/ssr-vue/src/entry-server.js new file mode 100644 index 00000000000000..b94f2d988d9964 --- /dev/null +++ b/packages/playground/ssr-vue/src/entry-server.js @@ -0,0 +1,51 @@ +import { createApp } from './main' +import { renderToString } from '@vue/server-renderer' + +export async function render(url, manifest) { + const { app, router } = createApp() + + // set the router to the desired URL before rendering + router.push(url) + await router.isReady() + + // passing SSR context object which will be available via useSSRContext() + // @vitejs/plugin-vue injects code into a component's setup() that registers + // itself on ctx.modules. After the render, ctx.modules would contain all the + // components that have been instantiated during this render call. + const ctx = {} + const html = await renderToString(app, ctx) + + // the SSR manifest generated by Vite contains module -> chunk/asset mapping + // which we can then use to determine what files need to be preloaded for this + // request. + const preloadLinks = renderPreloadLinks(ctx.modules, manifest) + return [html, preloadLinks] +} + +function renderPreloadLinks(modules, manifest) { + let links = '' + const seen = new Set() + modules.forEach((id) => { + const files = manifest[id] + if (files) { + files.forEach((file) => { + if (!seen.has(file)) { + seen.add(file) + links += renderPreloadLink(file) + } + }) + } + }) + return links +} + +function renderPreloadLink(file) { + if (file.endsWith('.js')) { + return `` + } else if (file.endsWith('.css')) { + return `` + } else { + // TODO + return '' + } +} diff --git a/packages/playground/ssr-vue/src/main.js b/packages/playground/ssr-vue/src/main.js new file mode 100644 index 00000000000000..dbf4287b0baf3c --- /dev/null +++ b/packages/playground/ssr-vue/src/main.js @@ -0,0 +1,13 @@ +import App from './App.vue' +import { createSSRApp } from 'vue' +import { createRouter } from './router' + +// SSR requires a fresh app instance per request, therefore we export a function +// that creates a fresh app instance. If using Vuex, we'd also be creating a +// fresh store here. +export function createApp() { + const app = createSSRApp(App) + const router = createRouter() + app.use(router) + return { app, router } +} diff --git a/packages/playground/ssr-vue/src/pages/About.vue b/packages/playground/ssr-vue/src/pages/About.vue new file mode 100644 index 00000000000000..fd0876306c509b --- /dev/null +++ b/packages/playground/ssr-vue/src/pages/About.vue @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/packages/playground/ssr-vue/src/pages/Home.vue b/packages/playground/ssr-vue/src/pages/Home.vue new file mode 100644 index 00000000000000..f1b3c4742b721a --- /dev/null +++ b/packages/playground/ssr-vue/src/pages/Home.vue @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/packages/playground/ssr-vue/src/router.js b/packages/playground/ssr-vue/src/router.js new file mode 100644 index 00000000000000..b80b76b0bf4e2a --- /dev/null +++ b/packages/playground/ssr-vue/src/router.js @@ -0,0 +1,26 @@ +import { + createMemoryHistory, + createRouter as _createRouter, + createWebHistory +} from 'vue-router' + +// Auto generates routes from vue files under ./pages +// https://vitejs.dev/guide/features.html#glob-import +const pages = import.meta.glob('./pages/*.vue') + +const routes = Object.keys(pages).map((path) => { + const name = path.match(/\.\/pages(.*)\.vue$/)[1].toLowerCase() + return { + path: name === '/home' ? '/' : name, + component: pages[path] // () => import('./pages/*.vue') + } +}) + +export function createRouter() { + return _createRouter({ + // use appropriate history implementation for server/client + // import.meta.env.SSR is injected by Vite. + history: import.meta.env.SSR ? createMemoryHistory() : createWebHistory(), + routes + }) +} diff --git a/packages/playground/ssr-vue/vite.config.js b/packages/playground/ssr-vue/vite.config.js new file mode 100644 index 00000000000000..d20f4dd734e760 --- /dev/null +++ b/packages/playground/ssr-vue/vite.config.js @@ -0,0 +1,11 @@ +const vuePlugin = require('@vitejs/plugin-vue') + +/** + * @type {import('vite').UserConfig} + */ +module.exports = { + plugins: [vuePlugin()], + build: { + minify: false + } +} diff --git a/packages/playground/ssr/__tests__/ssr.spec.ts b/packages/playground/ssr/__tests__/ssr.spec.ts deleted file mode 100644 index 027fef090b3395..00000000000000 --- a/packages/playground/ssr/__tests__/ssr.spec.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { editFile, getColor, isBuild, untilUpdated } from '../../testUtils' -import { port } from './serve' -import fetch from 'node-fetch' - -const url = `http://localhost:${port}` -const vueUrl = `${url}/vue` -const reactUrl = `${url}/react` - -test('should work', async () => { - await page.goto(url) - const html = await page.innerHTML('#app') - expect(html).toMatch(``) - expect(html).toMatch(``) -}) - -describe('Vue', () => { - beforeAll(async () => { - await page.goto(vueUrl) - }) - - test('should render correctly on server', async () => { - const html = await (await fetch(vueUrl)).text() - expect(html).toMatch('Hello from Vue') - if (isBuild) { - // assert correct preload directive generation for async chunks and CSS - expect(html).toMatch( - /link rel="modulepreload".*?href="\/assets\/Async\.\w{8}\.js"/ - ) - expect(html).toMatch( - /link rel="stylesheet".*?href="\/assets\/Async\.\w{8}\.css"/ - ) - } - }) - - test('should render correctly on client', async () => { - expect(await page.textContent('h1')).toMatch('Hello from Vue') - }) - - test('css', async () => { - // the CSS is loaded from async chunk and we may have to wait when the test - // runs concurrently. - await untilUpdated(() => getColor('h1'), 'green') - }) - - test('asset', async () => { - // should have no 404s - browserLogs.forEach((msg) => { - expect(msg).not.toMatch('404') - }) - const img = await page.$('img') - expect(await img.getAttribute('src')).toMatch( - isBuild ? /\/assets\/asset\.\w{8}\.png/ : '/src/assets/asset.png' - ) - }) - - test('hydration', async () => { - // should not have hydration mismatch! - browserLogs.forEach((msg) => { - expect(msg).not.toMatch('mismatch') - }) - expect(await page.textContent('button')).toBe('0') - await page.click('button') - expect(await page.textContent('button')).toBe('1') - }) - - test('hmr', async () => { - editFile('src/vue/Async.vue', (code) => - code.replace('Hello from Vue', 'changed') - ) - await untilUpdated(() => page.textContent('h1'), 'changed') - }) -}) - -describe('React', () => { - beforeAll(async () => { - await page.goto(reactUrl) - }) - - test('should render correctly on server', async () => { - const html = await (await fetch(reactUrl)).text() - expect(html).toMatch('Hello from React') - }) - - test('should render correctly on client', async () => { - expect(await page.textContent('h1')).toMatch('Hello from React') - expect( - await page.evaluate(() => - document.querySelector('h1')!.hasAttribute('data-reactroot') - ) - ).toBe(true) - }) - - test('hmr', async () => { - editFile('src/react/Child.jsx', (code) => - code.replace('Hello from React', 'changed') - ) - await untilUpdated(() => page.textContent('h1'), 'changed') - }) -}) diff --git a/packages/playground/ssr/index.html b/packages/playground/ssr/index.html deleted file mode 100644 index e0034414216c4b..00000000000000 --- a/packages/playground/ssr/index.html +++ /dev/null @@ -1,2 +0,0 @@ -

- diff --git a/packages/playground/ssr/src/assets/asset.png b/packages/playground/ssr/src/assets/asset.png deleted file mode 100644 index 1b3356a746b8bb5510aaee51f7df5aea4378ee8d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12772 zcmch82T)Ym)-H$&N*olL90vnANET3%3IdXIY@%ek$x$T;2*MyJ*+y~(p$Scr3=&#V zauARp&>%U(zmMb0?|pUet@~cpyH;6pHhZnL_ln2ZQ@20&bcI#; zRb1q(Z0+v)xLIlXsA|D|?BU{;Y%QIg6L0gA+o+ON#9WUkUItw9LoG z@?#6qUW)C{L+PnJV3BinvtkkE73P8S3*2B473UQY7PuiMz|A7aFCfInFT^Jx#3LXm z!7nZ$Ak6af4;zr?W@#;0kvqd6ZB>4C|Jw16ng?OFaZ1@Dk#l`vf1^EO8 zdB6@HgtrsY+>6Hv!TuKqc`F3m&CUgB=j_A+aWuDZc1KFFfs_7u1xFVZmA@G~A$}?f zsEp6c+=Wkom!Hqk5xUop-3X+H)&CyjpYBFzdAnHgX;>kg-QD289@gxC5d+=*dqL1f za2g4DXSlngl@s!wyc8Q);kC50l(;P_D#|Y+&o3r=TUJ0oK}c4VUtU3hUkF;26A%>o zi}s!q0%`69xB83L?r&N-#eYjHA?Idgj&yd@a&~t3%X$xNosrH6TW1#*IXRYVD&}xI zC+PV)q}!iIwQ{rbu(DKib9Q9;p&SXje{uj3VUgPcf}-N0BI1J3;l%~S#Kq*r`DGQw z

g*im?5pwfrX+|4DoMU()h{!|*|t{l(IMEdlp|e*D{S!NcF4Z{-Bs-3|CP!Zr*9 z8L#d=`P*7vqbn1>&n!RtU;S=qT#~jM$vQmzE;@a9c-rnezm%%pNUCL4Z?Ol5^T|`4 zavjWJM`*UqD*=L#ruSwfkpg`dg+WwAgBG)AJMJnzGINiKeO4G0eE->l82+&`B7#WJ+>uienjpS%Cf@_)wnS8@Lt-(ODwuJ9`ZNaR1c#{VzAzli%c zdieFczi910Q_uf9Ump#H3qJ49?XDdJEVgU0^-nuX>)vnly30Cxol4=jV*B(2W#5Q= zZoyqw)~|Z99vkShEvcZ%Gul9NJXmfqlB33(l=X+jS8v;gb!7^)K4G4vKK&sm{RpAY zXa|RLM59D+?B_$C1m;mhzR|W9s)a8;N9a~BS?g4pNK%w~aZQtaEyGUaQzjA|;I=b% zPAV^cc(RIern)a4 zhI(|wR30|9!CyKW7Euzj4~l&9N>-|XEj&zlYZ+NWMQTM+Dn>Sa|7#Z3UzI};wxS)M z5iocG$XR&=j~^L|KB-jVe&BB^c~JCVHeabiS7tMKFok0*ep-0e3Ze}V4cW;Q{F;|i zS$nM{@47r;N7}?`S6OPDO>XN^gfMC4@e4?t?VN*ih6ihdqMrioS?+n3lvoDhiA<%h z#p78S=zV$jMN1#_jm?eU)+~D8>Zr&$YG>4s?$aA0;vM3?Ri43*6b~&tl=Uo8va~MT z<>ks>Gs>e#6&&0ooD@PIXPo9!ZnA&c5Gu>&{9rQ2$Q7}1n7}39u$DbUbe3Dtk+hdq zDSK)7{F|d{*}-@89lT@N8WW)f4_Y3)=PQt3&`leqPLEq@F54On3Q{O`3Ek*NVbnPU z3HRC!)K5#DyF3No?si6u5Okc#a@1b3r+N6zae!OadVQefsha>mB{P0x2xXtyPVg#Sd}jsP;8~gz zYK^AUM8?3mAz{VD%2h0EqGie+}5cS z>3_AuW9^jOkayxhI^GLWCW2BtRp*eX>kO{Zk+g}I{px$AXrD-ryTauP;u;cGAfLT- zSD?0wa8lBaDV0a%bnCmP)=Y2PXe(WwysvAq@G|dvY)E8FQlK92Q))iT3C3DNZ8pT0 z^xBNvl&{jZjB>4M1k9s#@C})~){+R}@JjXYof(EmM3e)0b|n*jq=LwAqt8G<_*=l$ zy-rc})-+~(40YP90onyuio3BUUB~A!jMgE_o8VAUF4miGu-@zM8IP`hju<5zye^-k zeG=bdFRG?$R6^-YRJk`*b_GQE*?9u{$k?j=qd=I`1^c7fZWgmLBpnK;9ohqXv^hkb zm1KwQ+FCun1mc|jpv1JDF4(}xQXT}J7S8V~pYc=sgE@#MxS6((3x$#85G*RZy#4l= z_D$T#lY#h=bjIUB>=5fGmcizywk5(jI-HuY;=A^eXQ-7|3Q$rg5^qkMVqV3;15L#r z`WA&tUhStHJSIO3&?$Tri=9^B=*bex>D-yE$OcCG)STFdTs#_K)2-3^B#Lp6yEE{% zttT?<)JM-#X610Il@4oS&l~UWn@J4I5@y7YWV)bF9=ysF-`S(Lrmv$F=$j>r?AAMV z`~IQ~2Rq(1A6u*LH=mlaIty;}AVt{{bG2}8N)veY{ON#G| zpCH<$CHM1gPc&9Ln={MI->rfzD5VHlM%r%=#e?)i9xR0NdRcKHzH@*(KBAU<*+aze z@&F$b-7qY4u%U)i?v875tGFCGyuzB@?88-7t~9C%6lLP2+0-`*xO)4`8BY>llBHIA zFSj;Le1vbJ!xhIx?^M@|-I+0B9W%|Uq{EMtz9bVlw|0=2pF9N1%D?`xYb%W)s_Z?Q zw5Muirs2MfXOsUIiKmDb;NInp-@WzmBTp{(Jxk;B6XG~MXQ`5vo8EAnRpQlzXQ9a9 z!3Rk~>%iuQR)06kG5g-AN+{?GTIg`}Q)j6CSCmmTXr=6K@q)-$Z4-Hk!~l=eM*6Xu zZMowHW>@B!2C)oA6S3x$r-&yGYB`m(_>loreKFC&PRUA^`O%lRRiq;Z?rjb`*v;pJ zt*!1J6CHjRbv0%9u(Ombf}TG=g3g9$q{;QCE~FkBT5$%tc&mFKUJO|@JJ=^+9tWYV zcHn;4f)12eX~~PW^mXNZA!93zoPJb#1>;;8)P`4cE$uaz+&t~!@CAiw|EQfL^B}3f zF9jg>mND)ePKe>1#%q514fPsH#9t%qzh?rglEk>QZ_Q#S3MmsyxInBQwrxZ*1USKb)hd<8YTnSfa_5l-8xQ*+|7iP4f1;m58I6Nje@ z!&YMl^N!J_Ma#1yl5UKug3ZIv5kU?mnZh*qk+(1PrR;?b)S+&<0enT%apJ5 zFK^?Xjd`uq9H+aqjz+>8{MtD~I$=ZOhM?wI1ceCYe#08)QhFz`XJtsE)mbGH?Wl$L z7*BNiovp{)?b03AGKJ^gH_UwqA#NF6R#rSiEk{w#L^3hK87po#Sznl&R;~ej;^gI% zH3rOHhRpJ3T;v#a)rZ)Je9_xt^IaaE28iEEX(-3!BnwHr9~!E08R{0!6!W&V+>ZAmd&NGX)_GdboJJOVB122jrQcpF>VkQf(3Jxylq^JlpORzG5QuFIt@&2KB@ zJ(O@4thYJs1F_F@pwK#lXkYL+E0Mw-EWpqqII@#fdHF2&Bt>7f3CV;uXY77+MXkoC zK4krCRqI{Gg1!citzw11$)V@~A?Yf1tjX~+(xS5a=+pQ?4T{n|DpNAtb>N9o_U`H? zxTM>u_tz#*!{9HSq#VoA_@s5c`eZcrcV>o*QtAy@H`*#U`{VKPBc~|(>Y_uP3Y5NH zDU8hsXm~Gz{CHEuFv&vli0+?0^Lwi4IRkjY%4SG~_2VD~-|71+UD%0CN^hmBgAt=) zewPa366^2i2$M4ymby|i9rn*6a*<(|9%~L&wsVi1s2K>|ZknlXU8bsse4g3V@Y%E4 z-n$)|rxS!HW5DlKQ`S17p3^cN2Ijhi!Gib|3z7kDXm~kbaN!Jf$JLbBV{RlV09AEH zpZeBqUaDG?tGu)^O+6*A>*#p)yr`K`_3R9daq)d)+u+I#VXIqB7R3$JqwwyS9Jhn~ zjJipxGN|G_+U(#>92Ycw4rAt$&hAFTI;o$leDtaOy+aI?|P%Z*CS zB}?tO5t#@h?;VSBwK0+Kv+=t>TF_A@KC?t+T+I*B#8Q)2uX(Ju zt7e{|IKArp0#W`xSZCnr$%P-R9p{qyFtO4Awwo4xEpA4X3lN zdb=ZLd;C%Vb7M5mp|;G4lOIX^%4^CgeRsng-quQ&FhLfx50x(2I}VG*n&CIIwm)Z_ z{KjXS+EW*Rtf*NVcC2Y+4iuFRRRUMCV2HEC@D_!GEAbVRI#z+In~JHW(Vtc*ii7vB z9&RNlS2fraH^KrICe}T*OIsc@x0^9UT8^a-%2JfRVxE4+)47e_ps(nN0;Xw4GM-Vei=p_ z%18j{E+aje{#=GW@Xj2_v?UwnyIm{Ia;!!ZStJ1XV@j)A*BVUqF0Za86rimDv`o*c z=dZOk5!-v&aX4F)F3dK@RWGoU#PNhLPzyaMO;M^>8bifb>{*~>sajn%6ghf0#3@fW zAR|>5usIlRFL7*il(_enbC7j7OaRuwG~%RU&kP`G?t3|e@6-FAH;1UQlJbTGEOFAM zjw|Jk&immjd(P`NTKV;2gEOz#$L#HT2>^(v>icTKIsWCw={aX@P~+za)>3?Yt&%`Flm`>GwnnfRwZA4mCH0QH?>inQ6e#or?<}UtLS9g z!{aKumsX3J!tLGNpF+AS1|J2rW&F}I^6>p1Eo1-D(P_si<7sktg|2r;#2^j(SiN1; z6YebQf!*XT&v(a|N#@$Xi@i4Hf;|m>6=Hk6r?8VSg9_3&%S(iuYX+YW42QOa4o%WW zd|S_@N~B2eo%ZKkW~V=u~H>S$Fw2t>iEi6CblqEt7CkUl4B`YEIKDFpY zz#|;^vV=*`awq7B4fskysB)m(Ok(uAjb}2vG9t7M?nf|A%)Dr ztE%yxDbI4AQGcFtRlmE@T6U>}Vr2EcJq?hM$%taq3ca~qwymHpz?1lf-`W5kW<)qJ zdJeF^o`S!6VL}-6w~m!GQWL}+2$FfImGkKIP%*%OK}C+gK!pvcv~zI#h}d`&Zt*^a zo6q7$#S1R8nHm)o>w?JlF%i3T^KxyZHk+nZ35dFhK?GYXt%U*MI9MfAAF%{E35Z zX5|IIU{qJmR~C#2`izX96>jISe9T~Mmu0wQ>C0Ah52UQA=END~BCkgH{W%Twsg-il zI+QSVcf&Dcj4QyMZv__;%6dNkF#+M`%5SXKU=1~5AaLc5!KIZ_`>WAXl+xTVl#|RS z@t)D$P@b%zF<2kQ{Mq_|G01skF@&E4QZ!e7o_Hnnp}J(RXh*1sSs0wT18>CXt~~|7 zsG0p?JCC7R4hDUV2VwXEMLab9O1Gu#>KL&d4qWlw|>3KC=>ab>^T*Vw@5Dvyf*0YD0(l5oL(wz-)k2H=yMsg79uKt zwHCpIPUd7CH<%2|rBVl}0Tb0}lFhq|=sajhpgx7nkRW+=kR4S7S4KP9IRXWs$bR$; zPyV-OprKgTOORRg@|b>9ksTCt?wtav7j%jTP-l>QbX@WxnxkfhPB0JnX-u$CA9L8M zHGp5n(s??c)V8DEHjsBu)3n3yp_2y;&YYn>`h!c>R~z_+uY5hVRtPw2Q#Yw8C%p#%icDkL6PMXS?@wH)LTUh(4_hS`{p- zr4&sq1`Itk8h!QErL3}Kx5B*&X9U>CChU5_q&T`|2TKMlF`96xj{PHfvp{}S&4fCP zET{6!S#B|=>1SJ4QHL2yU#}OHP`_c;FQKSs3T_eLbac@VJp?a<|;Qqe0 zjJ@bL7PH%-&cQpSkh7vQuB9&$e5%i`bJbrSj=@b=hyX)~H`6|R>or?Ws`B|2=5Lr> zpLw}4xU|gOp_6_Pb*yhdf2-*+uk0W@3ZudyXxgt<46EEdC{!zX+L3WY277{Qb~IP< z(gOZv7GOj-Dh;(_bq&|FRdzYZG1D}y@Y`sAJ075tc{wq-zW`Dfz#HPjB_(yqf$f9@ z0|?uKEd?J9@Xk>8yx|Mmc>&!Snv{C8W4bko+HwqBAxIDz0>qmV_j~_$_8E}&tTorqq&Q*YYqIn zYYq2|tXxpHW^=%fKq(ItBYoLoZ}+V;`T zC-{zURz5G`QB<7Bwt5E}elWX~?S3(quWy|T#9`V3o^m-(6#>S6 zi|3}FiJs`2W0bzy4Zc@6zWLH|QK!(nkOP3Y8j>^ATQPg)yO8w#ig<;&s)XzE*?Jf~ zxpJw?&7Y0Cf%8dS;qL3j8q*kP3U7QuJ8)l2_e{rVk$V&FHBD>YcfWgWJcHD$rbNk3$AQj`y23cVG zWrV2Hc@k*X^!t7)5c71@_|4TMD4bq#nVd0QPmceU-5e}}= z0SdsCU#kTR&A?H~TH)hgA8^K{ zup*pP0%LUpfHCXsqM;qO_O^X7LfW%Z+l7?QwQhsxy%YmjUCXnebI05%tfz=YC#~?F za~ANT+(55-*`p-AI6eCE37YwNO-Mb*j=HuDSugSq)+^gObH^HwmNRG{{$?+We)%!w zEI#ppzL;jfKLDJ-V(mz)Gd3`fY;n-zkOch$uwguqXr*g4h{46)fC1&+rs#WRL%b`o zY>{>C2db%j$Ujp~V*KhZ;v^eB$%!VoxS7)!J*Z4U9e%@HzN?F6v;-$rdL$ zQhX0V4w##nlHh1TlGqG6{n-(N=^BOVCkDG&D?C~^_zGv9#?f6b3F;!!AEmgXs!|!eW&kmK)gabz4456L! zwqX99vlAYrAkeAHeXVB7?4|Wb2IyD!#NM8$FFI+5_q5Gs8mJ#O)xIN*F`oi3#`E>& z#2@njvhfH1IW?wmgJ2AOoz?HFn&YD7ZQ|}VP~gT~v>7f5UcCs~$8wEN{Y-T-Zz^}L zuh5Sa-$f9E3tE_x;x7D{6uAqOd$^pupx)(Jy)=?`7Xcs=jrH_>UkM}(lux(3TxX_~ z_aYTLSt|igAl-xCgYm;Z4tcGn*6xglRr7&yZcop!bOR9AG{v~GgcpFf4!Sd_T$#&Dw*QoqaeotqG2jp+=t)vim+_bDcQPGES4UZ5Bzk_Esy>HLT<&-M#?VfembeX2e*SJT z4^`E5C;E{zRRjTGu-Z&}5Q}xx48Q+5HlrbLmv;<1nw>vaLOk|y9K6r%{1dtqK+r`2 zj5{OJM$)QzT$4L@ZY5m;$1}!UtAJdWSrT>4XIhCUtAgii1j0;%7Wkz1Z+*jo47JJN zwbW3G7S~b^@3H^IS&>#p*0EkYUZ}Pu|BYK*G)-&AKC~`GkKID+4ln@8uVkis{GERk z422pRDc^4=H-~&ysa8dYLllz;fauNDK`fIlNLNC-RCDgzU^=vyvR>0g-EqXz4VZI3 zbvZA?SWB$UriRGW`qV*vT28tyK8uLMHS_QIcM*V^hmF}bTU^x%?@?HocptHJoePHh zG4=T!AeJ5iz@i$5VuaFt8L5K0NwDXOW<*6=q*2&_9wDIintpcj6R|kvQUS!WN6*u- z@U&k6z5M5f8$-e9JJ1_dL(LZneB-?dv+#}u7DI+H09AnI)kB01e;NHvHv4~(lJ7A zSr%KD=ofaSL#E4S;O!k()=GnSZ0sDMYv_0S{En>3lecF2F~5@xOplLvPQ@JOP!%F@ zoGS=)S^wpiN!{qN+ht~UX=*T(D}##SRx|BsBnqR%A^7A204XwW4wtptI-WjP01!nF zV24H8pW`=iUod`44eZU|!>kK*?r71qK&;tQ_L)g1bmBX;7_ToaESREE+Zb(S1K5=T z8i=?iW_toVkwckC{PFN5EIw`_z&m75avi*vHl@MrazZgOuy!_Bq=>|O$x!vxSoe)T z0>X?2?0Nw3-73yoZ;wM^?tyx(T1d66Im8&qLJWo>VGg2M0>prHvzP>D1>vuXVj5bU zUvl!E(7H|6jvHM8bTsFOb?XLyW0HaW{(z!%{Z){8Y%|L)0&3A;CtN2*C7n#CJSQY0 zOv>=fpdbd`j}o<(6Gc(h6lmtj*lKtm|ibroh%QL_Ev>4=NQL-!n@YWXFnB7j_AG#{>=QMhW zdA|*W&uR2&l*7=U8+LykKB+ra?lpFyC8HDo;}cQg$)|w{BgH@F%IY#}!8(zr$qr)! zdS|Ki@F&DfOBrNc>fDY3IalT{22uDc)){or1ZJpGbExdW6#KGe`Vc|)yJeMcN)cx^xJrGGfNNBMK zM$rOD;KKY!l$`@aP-KkSPk?RCW!=bzwhw*sn%&0Yz=p2AKUXGkD5(q*sP!ucps3V{^8cW7WfI#v`F+z_MpS<8|i^b{}<`S*bHs(-P zteX+(HkOcJeSr$=xlGXJinLzDLLth&Kz>gzI4~F$C~$ZYS7i#EA<}DNFlHJxvHCK! zq5=m=IH)Fx&bf}VmP_lgDMEpc9?)1GJhWB2M$mQ1?moz6F+e8*#(Vrijr_6gXIaef zjYA99Lcohp8lTQ0DCHLZK&}9QuE%0ZjtlGNzY*{%S{#TVwt86i+ZuMYoU{eb z#)trlq877k^Auiv5dO&Xj>I5f!u`jde&KO9f9VcP+L`bSb!j#5*!5&9-GbJpS_wut zL^JYI7U7urZWAeihA7ZL?2mHu=q(SU;cK<{Bo$NDM*+~}>_i%wt`+|1`z<2fbdB?i z&XeyRzvHI`FU7a&6Or7|2_I_CM*V1o7kx!@;2=b9J+Ee~(2Ykq*C$1TMi#%`0(>wd z3dY!rhEYfoK(Z)M6}(d|xRu&5PzEyo>mi_*nXpVgt?&kfxr7He(Uxte4?ohgKz^!P zl2Hhp*k}Alo7yj#5={lMbOP=ehczytlv+DL76R{ByktrQy3nmcsc$sEJF$G=(uA^A zavVN`(a2}e2B9e;oVnGaIC&17faIE}Zzw)=zrKqTGVS}tbW*ImwF}@JOxhP|jKC%F zUz&6}Ylf$}CcA+77e5Uzsbjhzca8ryJz#n48sN?sy2=@^=cbzl#|Nek+HwY#Ij|6{;EtnMn>5~^3_?j|usez*SXjmlq*%sG1+l z-hh_67df3O2b|)a2nb$5q-b7iM$Prl3}6M{)5?~QtL3q;_-8uscpKyqFCL&!J(nmg zdmt^ebx79tJ}q?*Jg*&Sk0cV<(_!(7mc_gKnRKAm@LRGjAEGeI9P<;#d630P^1!f9 zBh(vl?K8-kLFQ1p5J3**wbs?}{#ar4bhO39qwF!7JiuTy9>B(XHbpqj50$vQgr*n- zpX?V?W0%w7y>}}D@tqqFh;$8K;6DXnc2rI*hZq$0?A4M4O5f84gkG*ahT0Z=PAZj9 zREa{FYR&D)L|OR9BXk##sb*@b1wWI3yNn(v*{Xqe+-lhdK(Dua0fQg?P4pGbA`nDh zz-K@HD2y)0fV@Y!^WgU4D#Hxr zc;Z7muz&O69b3XMmqzkze*iOs_JQh#K^qb3GE{Q!kPK`fo;kp#(PkX`U%?3h2Hekp zF{ZJ`H{~&YuA??VvpNq&lJoI;MxYPT!m!7aL2L6*SdESw-jMdhdzJ1*Qn#{!s9)h~as!ad0K%@fDpf90I<4(3eq`@}GcpOMwk}t)^u{)$dg$b=- zI%yHKvk+dP2C=vSSPZn8`P2BZ;UIX(ZP$5VvbahcWL$FDIzR z8<0Yy1G!mmU4gIHr4rRKBA`tFIc3!LOl4M@>ezYkcns2?>+i@hAD01imLq{41sL(a zvEi|en^K}cQ6veV@*c(PhbVvl z1j}B4%FrVcee%%NRRzCp%m4zaBDcnvMyD0L(ptXNKrBmvLj_RQF2kntiq-nh0iJTx z#3-D8Q^!>V2NiTdD;@jyvx%_*|kRtWKpG%IZ+;g${P-g=xg>)s zMpIibKaDC@dJf4y3xHuBZ@_8Z77eh}ts9_>($#kHGFb>pop1VMlSlS-ju8m$M&b$P zp7o(s;^`%FZSqB`$#-XbR6wTkA(N3YM(*~(AbmiU13*1HvPL(}14f|H*HK(@zWZVU zt8-g#A?}jEq(ibpV$sZwnd#@iC!WzQAXgRkHp(OfoCmiTV*(q%0I6a>HhfD6P&6^f z4(`f%4kaHA7=N1r8Vn+ll$G34K0SSK;0$q$1|q>UX!YgEfcv*bkR$Mnt3@g%@{9`@ zZj~Sk7+&*1r&sF;0Iu@#A)vr(idnxZ`=5Lk`(OBc6{zU{@~dH>r2pV+-dUp^217t6nVH5`QcetM1u@7n`oi#fYSDd_)Q+*44MFP1fX{69{$*5UvF diff --git a/packages/playground/ssr/src/entry-client.ts b/packages/playground/ssr/src/entry-client.ts deleted file mode 100644 index 6ef2ef6d4effc2..00000000000000 --- a/packages/playground/ssr/src/entry-client.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { createVueApp, createReactApp } from './main' - -if (location.pathname.startsWith('/vue')) { - createVueApp().then((app) => app.mount('#app')) -} else if (location.pathname.startsWith('/react')) { - Promise.all([import('react-dom'), createReactApp()]).then( - ([ReactDOM, app]) => { - ReactDOM.hydrate(app, document.getElementById('app')) - } - ) -} diff --git a/packages/playground/ssr/src/entry-server.ts b/packages/playground/ssr/src/entry-server.ts deleted file mode 100644 index d06ce49bb06ca3..00000000000000 --- a/packages/playground/ssr/src/entry-server.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { createVueApp, createReactApp } from './main' -import { renderToString } from '@vue/server-renderer' -import ReacDOMServer from 'react-dom/server' - -interface Manifest { - [key: string]: string[] -} - -export async function render( - url: string, - manifest: Manifest -): Promise<[string, string]> { - if (url.startsWith('/vue')) { - return renderVue(manifest) - } else if (url.startsWith('/react')) { - return renderReact() - } else { - return [`Vue React`, ``] - } -} - -async function renderReact(): Promise<[string, string]> { - const app = await createReactApp() - return [ReacDOMServer.renderToString(app), ``] -} - -async function renderVue(manifest: Manifest): Promise<[string, string]> { - const ctx: any = {} - const app = await createVueApp() - const html = await renderToString(app, ctx) - const preloadLinks = renderPreloadLinks(ctx.modules, manifest) - return [html, preloadLinks] -} - -function renderPreloadLinks(modules: Set, manifest: Manifest): string { - let links = '' - const seen = new Set() - modules.forEach((id) => { - const files = manifest[id] - if (files) { - files.forEach((file) => { - if (!seen.has(file)) { - seen.add(file) - links += renderPreloadLink(file) - } - }) - } - }) - return links -} - -function renderPreloadLink(file: string): string { - if (file.endsWith('.js')) { - return `` - } else if (file.endsWith('.css')) { - return `` - } else { - // TODO - return '' - } -} diff --git a/packages/playground/ssr/src/main.ts b/packages/playground/ssr/src/main.ts deleted file mode 100644 index bf291c11832914..00000000000000 --- a/packages/playground/ssr/src/main.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function createVueApp() { - return import('./vue/index').then(({ createVueApp }) => createVueApp()) -} - -export function createReactApp() { - return import('./react/index').then(({ createReactApp }) => createReactApp()) -} diff --git a/packages/playground/ssr/src/react/Child.jsx b/packages/playground/ssr/src/react/Child.jsx deleted file mode 100644 index 9360b64ba44269..00000000000000 --- a/packages/playground/ssr/src/react/Child.jsx +++ /dev/null @@ -1,5 +0,0 @@ -import React from 'react' - -export default function Child() { - return

Hello from React

-} diff --git a/packages/playground/ssr/src/react/index.ts b/packages/playground/ssr/src/react/index.ts deleted file mode 100644 index 1146613af99cb4..00000000000000 --- a/packages/playground/ssr/src/react/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import React from 'react' -import ReactApp from './App' - -export function createReactApp() { - return React.createElement(ReactApp) -} diff --git a/packages/playground/ssr/src/vue/App.vue b/packages/playground/ssr/src/vue/App.vue deleted file mode 100644 index 1355a2987a0bf5..00000000000000 --- a/packages/playground/ssr/src/vue/App.vue +++ /dev/null @@ -1,9 +0,0 @@ - - - \ No newline at end of file diff --git a/packages/playground/ssr/src/vue/Async.vue b/packages/playground/ssr/src/vue/Async.vue deleted file mode 100644 index fe3ba5fe6c3382..00000000000000 --- a/packages/playground/ssr/src/vue/Async.vue +++ /dev/null @@ -1,20 +0,0 @@ - - - - - \ No newline at end of file diff --git a/packages/playground/ssr/src/vue/index.ts b/packages/playground/ssr/src/vue/index.ts deleted file mode 100644 index c0840adcce8b90..00000000000000 --- a/packages/playground/ssr/src/vue/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import VueApp from './App.vue' -import { createSSRApp } from 'vue' - -export function createVueApp() { - return createSSRApp(VueApp) -} diff --git a/yarn.lock b/yarn.lock index b0c94b8b06f0c5..34491703d8d426 100644 --- a/yarn.lock +++ b/yarn.lock @@ -375,7 +375,7 @@ "@babel/helper-plugin-utils" "^7.10.4" "@babel/plugin-syntax-typescript" "^7.12.1" -"@babel/runtime@^7.12.5": +"@babel/runtime@^7.1.2", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.5": version "7.12.5" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.5.tgz#410e7e487441e1b360c29be715d870d9b985882e" integrity sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg== @@ -3713,6 +3713,25 @@ hash-sum@^2.0.0: resolved "https://registry.yarnpkg.com/hash-sum/-/hash-sum-2.0.0.tgz#81d01bb5de8ea4a214ad5d6ead1b523460b0b45a" integrity sha512-WdZTbAByD+pHfl/g9QSsBIIwy8IT+EsPiKDs0KNX+zSHhdDLFKdZu0BQHljvO+0QI/BasbMSUa8wYNCZTvhslg== +history@^4.9.0: + version "4.10.1" + resolved "https://registry.yarnpkg.com/history/-/history-4.10.1.tgz#33371a65e3a83b267434e2b3f3b1b4c58aad4cf3" + integrity sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew== + dependencies: + "@babel/runtime" "^7.1.2" + loose-envify "^1.2.0" + resolve-pathname "^3.0.0" + tiny-invariant "^1.0.2" + tiny-warning "^1.0.0" + value-equal "^1.0.1" + +hoist-non-react-statics@^3.1.0: + version "3.3.2" + resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45" + integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw== + dependencies: + react-is "^16.7.0" + hosted-git-info@^2.1.4: version "2.8.8" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488" @@ -4219,6 +4238,11 @@ is-wsl@^2.1.1, is-wsl@^2.2.0: dependencies: is-docker "^2.0.0" +isarray@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" + integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8= + isarray@1.0.0, isarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" @@ -5090,7 +5114,7 @@ log-update@^4.0.0: slice-ansi "^4.0.0" wrap-ansi "^6.2.0" -loose-envify@^1.1.0: +loose-envify@^1.1.0, loose-envify@^1.2.0, loose-envify@^1.3.1, loose-envify@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== @@ -5380,6 +5404,14 @@ min-indent@^1.0.0: resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.1.tgz#a63f681673b30571fbe8bc25686ae746eefa9869" integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg== +mini-create-react-context@^0.4.0: + version "0.4.1" + resolved "https://registry.yarnpkg.com/mini-create-react-context/-/mini-create-react-context-0.4.1.tgz#072171561bfdc922da08a60c2197a497cc2d1d5e" + integrity sha512-YWCYEmd5CQeHGSAKrYvXgmzzkrvssZcuuQDDeqkT+PziKGMgE+0MCCtcKbROzocGBG1meBLl2FotlRwf4gAzbQ== + dependencies: + "@babel/runtime" "^7.12.1" + tiny-warning "^1.0.3" + minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" @@ -5923,6 +5955,13 @@ path-to-regexp@0.1.7: resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" integrity sha1-32BBeABfUi8V60SQ5yR6G/qmf4w= +path-to-regexp@^1.7.0: + version "1.8.0" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.8.0.tgz#887b3ba9d84393e87a0a0b9f4cb756198b53548a" + integrity sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA== + dependencies: + isarray "0.0.1" + path-type@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441" @@ -6269,6 +6308,15 @@ prompts@^2.0.1: kleur "^3.0.3" sisteransi "^1.0.5" +prop-types@^15.6.2: + version "15.7.2" + resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" + integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ== + dependencies: + loose-envify "^1.4.0" + object-assign "^4.1.1" + react-is "^16.8.1" + proper-lockfile@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/proper-lockfile/-/proper-lockfile-4.1.1.tgz#284cf9db9e30a90e647afad69deb7cb06881262c" @@ -6471,6 +6519,11 @@ react-dom@^17.0.1: object-assign "^4.1.1" scheduler "^0.20.1" +react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1: + version "16.13.1" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" + integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== + react-is@^17.0.1: version "17.0.1" resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.1.tgz#5b3531bd76a645a4c9fb6e693ed36419e3301339" @@ -6481,6 +6534,35 @@ react-refresh@^0.9.0: resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.9.0.tgz#71863337adc3e5c2f8a6bfddd12ae3bfe32aafbf" integrity sha512-Gvzk7OZpiqKSkxsQvO/mbTN1poglhmAV7gR/DdIrRrSMXraRQQlfikRJOr3Nb9GTMPC5kof948Zy6jJZIFtDvQ== +react-router-dom@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-5.2.0.tgz#9e65a4d0c45e13289e66c7b17c7e175d0ea15662" + integrity sha512-gxAmfylo2QUjcwxI63RhQ5G85Qqt4voZpUXSEqCwykV0baaOTQDR1f0PmY8AELqIyVc0NEZUj0Gov5lNGcXgsA== + dependencies: + "@babel/runtime" "^7.1.2" + history "^4.9.0" + loose-envify "^1.3.1" + prop-types "^15.6.2" + react-router "5.2.0" + tiny-invariant "^1.0.2" + tiny-warning "^1.0.0" + +react-router@5.2.0, react-router@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/react-router/-/react-router-5.2.0.tgz#424e75641ca8747fbf76e5ecca69781aa37ea293" + integrity sha512-smz1DUuFHRKdcJC0jobGo8cVbhO3x50tCL4icacOlcwDOEQPq4TMqwx3sY1TP+DvtTgz4nm3thuo7A+BK2U0Dw== + dependencies: + "@babel/runtime" "^7.1.2" + history "^4.9.0" + hoist-non-react-statics "^3.1.0" + loose-envify "^1.3.1" + mini-create-react-context "^0.4.0" + path-to-regexp "^1.7.0" + prop-types "^15.6.2" + react-is "^16.6.0" + tiny-invariant "^1.0.2" + tiny-warning "^1.0.0" + react@17.0.0: version "17.0.0" resolved "https://registry.yarnpkg.com/react/-/react-17.0.0.tgz#ad96d5fa1a33bb9b06d0cc52672f7992d84aa662" @@ -6743,6 +6825,11 @@ resolve-from@^5.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== +resolve-pathname@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-3.0.0.tgz#99d02224d3cf263689becbb393bc560313025dcd" + integrity sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng== + resolve-url@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a" @@ -7578,6 +7665,16 @@ tiny-emitter@^2.0.0: resolved "https://registry.yarnpkg.com/tiny-emitter/-/tiny-emitter-2.1.0.tgz#1d1a56edfc51c43e863cbb5382a72330e3555423" integrity sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q== +tiny-invariant@^1.0.2: + version "1.1.0" + resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.1.0.tgz#634c5f8efdc27714b7f386c35e6760991d230875" + integrity sha512-ytxQvrb1cPc9WBEI/HSeYYoGD0kWnGEOR8RY6KomWLBVhqz0RgTwVO9dLrGz7dC+nN9llyI7OKAgRq8Vq4ZBSw== + +tiny-warning@^1.0.0, tiny-warning@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.3.tgz#94a30db453df4c643d0fd566060d60a875d84754" + integrity sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA== + tmpl@1.0.x: version "1.0.4" resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1" @@ -7917,6 +8014,11 @@ validator@^8.0.0: resolved "https://registry.yarnpkg.com/validator/-/validator-8.2.0.tgz#3c1237290e37092355344fef78c231249dab77b9" integrity sha512-Yw5wW34fSv5spzTXNkokD6S6/Oq92d8q/t14TqsS3fAiA1RYnxSFSIZ+CY3n6PGGRCq5HhJTSepQvFUS2QUDxA== +value-equal@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-1.0.1.tgz#1e0b794c734c5c0cade179c437d356d931a34d6c" + integrity sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw== + vary@^1, vary@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" @@ -7969,6 +8071,11 @@ void-elements@^3.1.0: resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-3.1.0.tgz#614f7fbf8d801f0bb5f0661f5b2f5785750e4f09" integrity sha1-YU9/v42AHwu18GYfWy9XhXUOTwk= +vue-router@^4.0.3: + version "4.0.3" + resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.0.3.tgz#8b26050c88b2dec7e27a88835f71046b365823ec" + integrity sha512-AD1OjtVPyQHTSpoRsEGfPpxRQwhAhxcacOYO3zJ3KNkYP/r09mileSp6kdMQKhZWP2cFsPR3E2M3PZguSN5/ww== + vue@^3.0.5: version "3.0.5" resolved "https://registry.yarnpkg.com/vue/-/vue-3.0.5.tgz#de1b82eba24abfe71e0970fc9b8d4b2babdc3fe1" From 0fe2634756b6311f0489613460eeadc6c8280192 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 2 Feb 2021 21:01:58 -0500 Subject: [PATCH 455/514] feat(ssr): graduate ssr method types --- packages/vite/src/node/server/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 47dd9dc03a9922..628731b2541617 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -208,7 +208,6 @@ export interface ViteDevServer { ): Promise /** * Load a given URL as an instantiated module for SSR. - * @alpha */ ssrLoadModule( url: string, @@ -216,7 +215,6 @@ export interface ViteDevServer { ): Promise> /** * Fix ssr error stacktrace - * @alpha */ ssrFixStacktrace(e: Error): void /** From 3f6d1296cccfb947d42df57408efd3e983cbe0ce Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 2 Feb 2021 21:20:53 -0500 Subject: [PATCH 456/514] chore: fix less type --- packages/vite/types/shims.d.ts | 4 + yarn.lock | 1450 ++++++++++++++------------------ 2 files changed, 642 insertions(+), 812 deletions(-) diff --git a/packages/vite/types/shims.d.ts b/packages/vite/types/shims.d.ts index 6a1eb3af27358f..8a0e94ee8ee10e 100644 --- a/packages/vite/types/shims.d.ts +++ b/packages/vite/types/shims.d.ts @@ -113,3 +113,7 @@ declare module 'compression' { function compression(): any export default compression } + +// LESS' types somewhat references this which doesn't make sense in Node, +// so we have to shim it +declare interface HTMLLinkElement {} diff --git a/yarn.lock b/yarn.lock index 34491703d8d426..f8500fe122abf5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,135 +2,135 @@ # yarn lockfile v1 -"@algolia/cache-browser-local-storage@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.8.3.tgz#79cc502892c83f378b8f1a87f78020268806f5c3" - integrity sha512-Cwc03hikHSUI+xvgUdN+H+f6jFyoDsC9fegzXzJ2nPn1YSN9EXzDMBnbrgl0sbl9iLGXe0EIGMYqR2giCv1wMQ== - dependencies: - "@algolia/cache-common" "4.8.3" - -"@algolia/cache-common@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/cache-common/-/cache-common-4.8.3.tgz#7aca2644159ec791921dc8b296817e5b532b3464" - integrity sha512-Cf7zZ2i6H+tLSBTkFePHhYvlgc9fnMPKsF9qTmiU38kFIGORy/TN2Fx5n1GBuRLIzaSXvcf+oHv1HvU0u1gE1g== - -"@algolia/cache-in-memory@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/cache-in-memory/-/cache-in-memory-4.8.3.tgz#3d2692b895e9b8da47249b2b8dc638f53d6328ee" - integrity sha512-+N7tkvmijXiDy2E7u1mM73AGEgGPWFmEmPeJS96oT46I98KXAwVPNYbcAqBE79YlixdXpkYJk41cFcORzNh+Iw== - dependencies: - "@algolia/cache-common" "4.8.3" - -"@algolia/client-account@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/client-account/-/client-account-4.8.3.tgz#4abc270dbd136644e69cc6b1ca1d0d14c9822aaf" - integrity sha512-Uku8LqnXBwfDCtsTCDYTUOz2/2oqcAQCKgaO0uGdIR8DTQENBXFQvzziambHdn9KuFuY+6Et9k1+cjpTPBDTBg== - dependencies: - "@algolia/client-common" "4.8.3" - "@algolia/client-search" "4.8.3" - "@algolia/transporter" "4.8.3" - -"@algolia/client-analytics@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/client-analytics/-/client-analytics-4.8.3.tgz#578b6e6fa33818a0417298438066642e584e1de9" - integrity sha512-9ensIWmjYJprZ+YjAVSZdWUG05xEnbytENXp508X59tf34IMIX8BR2xl0RjAQODtxBdAteGxuKt5THX6U9tQLA== - dependencies: - "@algolia/client-common" "4.8.3" - "@algolia/client-search" "4.8.3" - "@algolia/requester-common" "4.8.3" - "@algolia/transporter" "4.8.3" - -"@algolia/client-common@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/client-common/-/client-common-4.8.3.tgz#d8ea3368a5b98ce907e4be0eed804c3301cd91de" - integrity sha512-TU3623AEFAWUQlDTznkgAMSYo8lfS9pNs5QYDQzkvzWdqK0GBDWthwdRfo9iIsfxiR9qdCMHqwEu+AlZMVhNSA== - dependencies: - "@algolia/requester-common" "4.8.3" - "@algolia/transporter" "4.8.3" - -"@algolia/client-recommendation@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/client-recommendation/-/client-recommendation-4.8.3.tgz#fc15688bf9d0fc0111a6c56d247e33dc3fcf8190" - integrity sha512-qysGbmkcc6Agt29E38KWJq9JuxjGsyEYoKuX9K+P5HyQh08yR/BlRYrA8mB7vT/OIUHRGFToGO6Vq/rcg0NIOQ== - dependencies: - "@algolia/client-common" "4.8.3" - "@algolia/requester-common" "4.8.3" - "@algolia/transporter" "4.8.3" - -"@algolia/client-search@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/client-search/-/client-search-4.8.3.tgz#c70e09935e2cf25da356d59794e6a5a95f9a4cc8" - integrity sha512-rAnvoy3GAhbzOQVniFcKVn1eM2NX77LearzYNCbtFrFYavG+hJI187bNVmajToiuGZ10FfJvK99X2OB1AzzezQ== - dependencies: - "@algolia/client-common" "4.8.3" - "@algolia/requester-common" "4.8.3" - "@algolia/transporter" "4.8.3" - -"@algolia/logger-common@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/logger-common/-/logger-common-4.8.3.tgz#449e8767863466528de7d18017417b319e4782d3" - integrity sha512-03wksHRbhl2DouEKnqWuUb64s1lV6kDAAabMCQ2Du1fb8X/WhDmxHC4UXMzypeOGlH5BZBsgVwSB7vsZLP3MZg== - -"@algolia/logger-console@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/logger-console/-/logger-console-4.8.3.tgz#e4bcda8ac6477ecf143a1d536be2b747b84b7047" - integrity sha512-Npt+hI4UF8t3TLMluL5utr9Gc11BjL5kDnGZOhDOAz5jYiSO2nrHMFmnpLT4Cy/u7a5t7EB5dlypuC4/AGStkA== - dependencies: - "@algolia/logger-common" "4.8.3" - -"@algolia/requester-browser-xhr@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/requester-browser-xhr/-/requester-browser-xhr-4.8.3.tgz#f2fe880d261e33bce1c6d613be074fd87af9f7e6" - integrity sha512-/LTTIpgEmEwkyhn8yXxDdBWqXqzlgw5w2PtTpIwkSlP2/jDwdR/9w1TkFzhNbJ81ki6LAEQM5mSwoTTnbIIecg== - dependencies: - "@algolia/requester-common" "4.8.3" - -"@algolia/requester-common@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/requester-common/-/requester-common-4.8.3.tgz#633b6782ae3fcf1743507c0ef207db5c62737443" - integrity sha512-+Yo9vBkofoKR1SCqqtMnmnfq9yt/BiaDewY/6bYSMNxSYCnu2Fw1JKSIaf/4zos09PMSsxGpLohZwGas3+0GDQ== - -"@algolia/requester-node-http@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/requester-node-http/-/requester-node-http-4.8.3.tgz#81c8e5d02f16a57cebfa2309a931fad6de84eb6d" - integrity sha512-k2fiKIeMIFqgC01FnzII6kqC2GQBAfbNaUX4k7QCPa6P8t4sp2xE6fImOUiztLnnL3C9X9ZX6Fw3L+cudi7jvQ== - dependencies: - "@algolia/requester-common" "4.8.3" - -"@algolia/transporter@4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@algolia/transporter/-/transporter-4.8.3.tgz#6ad10b4be16653d667bb4727df27478931631fe8" - integrity sha512-nU7fy2iU8snxATlsks0MjMyv97QJWQmOVwTjDc+KZ4+nue8CLcgm4LA4dsTBqvxeCQIoEtt3n72GwXcaqiJSjQ== - dependencies: - "@algolia/cache-common" "4.8.3" - "@algolia/logger-common" "4.8.3" - "@algolia/requester-common" "4.8.3" +"@algolia/cache-browser-local-storage@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.8.4.tgz#6a03ffc6b0b5b5aa7f74732bf8091a0f3d2b0986" + integrity sha512-qSS3VMP3oMhcLrYIFveRyt3F5XB6MqWogF4Vooj8KvOvqv6jBmYwkAueSXCF5pkJEaA72VL9+9NbBpfC8ez2ww== + dependencies: + "@algolia/cache-common" "4.8.4" + +"@algolia/cache-common@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/cache-common/-/cache-common-4.8.4.tgz#b105bdfe3fa0ba15db936177c4db420befed2ab7" + integrity sha512-5+dLmj6qFy4WOtnNQuFRfWTIIDdpUigv+dXaKMFplNPBvZHGFy3hcRjWqYzGcqaeLqcXbN8cU5r75mvrlJIxcw== + +"@algolia/cache-in-memory@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/cache-in-memory/-/cache-in-memory-4.8.4.tgz#e978935dd8c4bbd555820e9b9fc863a24f3d38dd" + integrity sha512-PBN4YKxn/L+HjVKqUE5rtLiFKqzm4qnUoF7QvCFFmFAViCdYwZSMFVmDobstqWY3KULfsEqaeD4eU4jxZbKhEA== + dependencies: + "@algolia/cache-common" "4.8.4" + +"@algolia/client-account@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/client-account/-/client-account-4.8.4.tgz#a0af429e3587b33a988fec98ce0c739fd16143aa" + integrity sha512-mrsOnGV4O2b+t1CumUH72+Psw9d9qwngBEp2le7IMSceJQywQvNCyJ4B4qyoozHsIGapXfcVAOhRxqUsNQ6U6g== + dependencies: + "@algolia/client-common" "4.8.4" + "@algolia/client-search" "4.8.4" + "@algolia/transporter" "4.8.4" + +"@algolia/client-analytics@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/client-analytics/-/client-analytics-4.8.4.tgz#77c81b699909b50ecd9bf97997f014cfeb358fc3" + integrity sha512-Xy70njSUgG/QTv5+rPjsTIzBF/bjxseS5h9SawrQGzovTosbJbu9JBlg4YwVJnYvjovzpr7S39+gPIPc8M7+Rg== + dependencies: + "@algolia/client-common" "4.8.4" + "@algolia/client-search" "4.8.4" + "@algolia/requester-common" "4.8.4" + "@algolia/transporter" "4.8.4" + +"@algolia/client-common@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/client-common/-/client-common-4.8.4.tgz#a1b35645253c7f96925bfe91bac486e755329b77" + integrity sha512-sQlRa+KWFn+D8AOEZb4kj6RE/i6DnPwVOF4AnNf9IjNB0mUUhLWw96cQN6GDx0KE4lhW67t+qR39ZuuDBgR9ww== + dependencies: + "@algolia/requester-common" "4.8.4" + "@algolia/transporter" "4.8.4" + +"@algolia/client-recommendation@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/client-recommendation/-/client-recommendation-4.8.4.tgz#1aaa9735e96865ff06321a8bc850829445c945d1" + integrity sha512-CE0CVqLGWotVOaUXyU33FVD9FZ/7rqcbwFPH5MgSjVdE0B1YWVedhR0s2BNKodXLcIGVLVYfXR05CLdvOlTw+A== + dependencies: + "@algolia/client-common" "4.8.4" + "@algolia/requester-common" "4.8.4" + "@algolia/transporter" "4.8.4" + +"@algolia/client-search@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/client-search/-/client-search-4.8.4.tgz#0320c4a109d2cc220a9d1002f9ec64655a4494dc" + integrity sha512-eH2tRPnDU3tqpp0BSqP6coRRQe8fceqsupuf/1ho+Mcs5DM13mEuFmNOyPywHRlYLVPmbbCPRhDr5rB8QoN7XQ== + dependencies: + "@algolia/client-common" "4.8.4" + "@algolia/requester-common" "4.8.4" + "@algolia/transporter" "4.8.4" + +"@algolia/logger-common@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/logger-common/-/logger-common-4.8.4.tgz#42ecab3c92388a0d81b8532cefb47670da46cdd3" + integrity sha512-6hOaFG75Onmant9adcaeCZgvPYfnif7n0H1ycbixm6/WH3SmxqPMG+CMiW8mTNTRrrAEceQVrq6tDHD8jdnOOw== + +"@algolia/logger-console@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/logger-console/-/logger-console-4.8.4.tgz#adfac58df84848443bff1326986a0ca98db866b9" + integrity sha512-+9T3t/eB9vseANFz9YbFHG0cHjzVP/DVfGqzTAkeSlvMHP69JzJga9Wb0Ai6J3xXE3d4k9K+k6t+kkjCQjzEqg== + dependencies: + "@algolia/logger-common" "4.8.4" + +"@algolia/requester-browser-xhr@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/requester-browser-xhr/-/requester-browser-xhr-4.8.4.tgz#30c5c9d129fafd863b7c9c7a988c36ec5754b973" + integrity sha512-BYa8O/pht0UL2bcm0ZkLZiyC+5dHrbc6gvKIo+OgqxmDb/K4KrVo6RIof3BVpR8fgcfxQJohjNVHKXHxEUhBCQ== + dependencies: + "@algolia/requester-common" "4.8.4" + +"@algolia/requester-common@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/requester-common/-/requester-common-4.8.4.tgz#670f5e43e4d09ff9a3b9bfda7ac0c03476a9e4b1" + integrity sha512-br3LXb6srfAy7F04axwExmrkPOlXCDckgTFoLFv/RT9Oo28SpoyvHqktyBovQLdzdTs+Laglf+LtOHr0iUrZJg== + +"@algolia/requester-node-http@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/requester-node-http/-/requester-node-http-4.8.4.tgz#8af2cceb45e5bb2b9e7ed3b7daa34f3c2580912a" + integrity sha512-o5Cc4UxYPn3IBHQSDBNFFhq1LQLv40eYvCvK0FPJ8xZkrnNXhjPvaLCu/lQTHpk/HX7DaE6fQ/KboU0OSPKevQ== + dependencies: + "@algolia/requester-common" "4.8.4" + +"@algolia/transporter@4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@algolia/transporter/-/transporter-4.8.4.tgz#09452334e380ff0706676303e6642e76b72ae0bf" + integrity sha512-EvXFYICxrr9QEO6m6awUeNOBstOxePQ2Fy0jtYlS1v9TY2P5HqKRzkxmaZjeYRBsXOImpVjgQIzTzj1Au4br2w== + dependencies: + "@algolia/cache-common" "4.8.4" + "@algolia/logger-common" "4.8.4" + "@algolia/requester-common" "4.8.4" "@arr/every@^1.0.0": version "1.0.1" resolved "https://registry.yarnpkg.com/@arr/every/-/every-1.0.1.tgz#22fe1f8e6355beca6c7c7bde965eb15cf994387b" integrity sha512-UQFQ6SgyJ6LX42W8rHCs8KVc0JS0tzVL9ct4XYedJukskYVWTo49tNiMEK9C2HTyarbNiT/RVIRSY82vH+6sTg== -"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.11": - version "7.12.11" - resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f" - integrity sha512-Zt1yodBx1UcyiePMSkWnU4hPqhwq7hGi2nFL1LeA3EUl+q2LQx16MISgJ0+z7dnmgvP9QtIleuETGOiOH1RcIw== +"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.13.tgz#dcfc826beef65e75c50e21d3837d7d95798dd658" + integrity sha512-HV1Cm0Q3ZrpCR93tkWOYiuYIgLxZXZFVG2VgK+MBWjUqZTundupbfx2aXarXuw5Ko5aMcjtJgbSs4vUGBS5v6g== dependencies: - "@babel/highlight" "^7.10.4" + "@babel/highlight" "^7.12.13" "@babel/core@^7.1.0", "@babel/core@^7.12.10", "@babel/core@^7.7.5": - version "7.12.10" - resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.12.10.tgz#b79a2e1b9f70ed3d84bbfb6d8c4ef825f606bccd" - integrity sha512-eTAlQKq65zHfkHZV0sIVODCPGVgoo1HdBlbSLi9CqOzuZanMv2ihzY+4paiKr1mH+XmYESMAmJ/dpZ68eN6d8w== - dependencies: - "@babel/code-frame" "^7.10.4" - "@babel/generator" "^7.12.10" - "@babel/helper-module-transforms" "^7.12.1" - "@babel/helpers" "^7.12.5" - "@babel/parser" "^7.12.10" - "@babel/template" "^7.12.7" - "@babel/traverse" "^7.12.10" - "@babel/types" "^7.12.10" + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.12.13.tgz#b73a87a3a3e7d142a66248bf6ad88b9ceb093425" + integrity sha512-BQKE9kXkPlXHPeqissfxo0lySWJcYdEP0hdtJOH/iJfDdhOCcgtNCjftCJg3qqauB4h+lz2N6ixM++b9DN1Tcw== + dependencies: + "@babel/code-frame" "^7.12.13" + "@babel/generator" "^7.12.13" + "@babel/helper-module-transforms" "^7.12.13" + "@babel/helpers" "^7.12.13" + "@babel/parser" "^7.12.13" + "@babel/template" "^7.12.13" + "@babel/traverse" "^7.12.13" + "@babel/types" "^7.12.13" convert-source-map "^1.7.0" debug "^4.1.0" gensync "^1.0.0-beta.1" @@ -139,134 +139,134 @@ semver "^5.4.1" source-map "^0.5.0" -"@babel/generator@^7.12.10", "@babel/generator@^7.12.11": - version "7.12.11" - resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.12.11.tgz#98a7df7b8c358c9a37ab07a24056853016aba3af" - integrity sha512-Ggg6WPOJtSi8yYQvLVjG8F/TlpWDlKx0OpS4Kt+xMQPs5OaGYWy+v1A+1TvxI6sAMGZpKWWoAQ1DaeQbImlItA== +"@babel/generator@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.12.13.tgz#5f6ebe6c85db99886db2d7b044409196f872a503" + integrity sha512-9qQ8Fgo8HaSvHEt6A5+BATP7XktD/AdAnObUeTRz5/e2y3kbrxZgz32qUJJsdmwUvBJzF4AeV21nGTNwv05Mpw== dependencies: - "@babel/types" "^7.12.11" + "@babel/types" "^7.12.13" jsesc "^2.5.1" source-map "^0.5.0" -"@babel/helper-create-class-features-plugin@^7.12.1": - version "7.12.1" - resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.12.1.tgz#3c45998f431edd4a9214c5f1d3ad1448a6137f6e" - integrity sha512-hkL++rWeta/OVOBTRJc9a5Azh5mt5WgZUGAKMD8JM141YsE08K//bp1unBBieO6rUKkIPyUE0USQ30jAy3Sk1w== +"@babel/helper-create-class-features-plugin@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.12.13.tgz#0f1707c2eec1a4604f2a22a6fb209854ef2a399a" + integrity sha512-Vs/e9wv7rakKYeywsmEBSRC9KtmE7Px+YBlESekLeJOF0zbGUicGfXSNi3o+tfXSNS48U/7K9mIOOCR79Cl3+Q== dependencies: - "@babel/helper-function-name" "^7.10.4" - "@babel/helper-member-expression-to-functions" "^7.12.1" - "@babel/helper-optimise-call-expression" "^7.10.4" - "@babel/helper-replace-supers" "^7.12.1" - "@babel/helper-split-export-declaration" "^7.10.4" + "@babel/helper-function-name" "^7.12.13" + "@babel/helper-member-expression-to-functions" "^7.12.13" + "@babel/helper-optimise-call-expression" "^7.12.13" + "@babel/helper-replace-supers" "^7.12.13" + "@babel/helper-split-export-declaration" "^7.12.13" -"@babel/helper-function-name@^7.10.4", "@babel/helper-function-name@^7.12.11": - version "7.12.11" - resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.12.11.tgz#1fd7738aee5dcf53c3ecff24f1da9c511ec47b42" - integrity sha512-AtQKjtYNolKNi6nNNVLQ27CP6D9oFR6bq/HPYSizlzbp7uC1M59XJe8L+0uXjbIaZaUJF99ruHqVGiKXU/7ybA== +"@babel/helper-function-name@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.12.13.tgz#93ad656db3c3c2232559fd7b2c3dbdcbe0eb377a" + integrity sha512-TZvmPn0UOqmvi5G4vvw0qZTpVptGkB1GL61R6lKvrSdIxGm5Pky7Q3fpKiIkQCAtRCBUwB0PaThlx9vebCDSwA== dependencies: - "@babel/helper-get-function-arity" "^7.12.10" - "@babel/template" "^7.12.7" - "@babel/types" "^7.12.11" + "@babel/helper-get-function-arity" "^7.12.13" + "@babel/template" "^7.12.13" + "@babel/types" "^7.12.13" -"@babel/helper-get-function-arity@^7.12.10": - version "7.12.10" - resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.12.10.tgz#b158817a3165b5faa2047825dfa61970ddcc16cf" - integrity sha512-mm0n5BPjR06wh9mPQaDdXWDoll/j5UpCAPl1x8fS71GHm7HA6Ua2V4ylG1Ju8lvcTOietbPNNPaSilKj+pj+Ag== +"@babel/helper-get-function-arity@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.12.13.tgz#bc63451d403a3b3082b97e1d8b3fe5bd4091e583" + integrity sha512-DjEVzQNz5LICkzN0REdpD5prGoidvbdYk1BVgRUOINaWJP2t6avB27X1guXK1kXNrX0WMfsrm1A/ZBthYuIMQg== dependencies: - "@babel/types" "^7.12.10" + "@babel/types" "^7.12.13" -"@babel/helper-member-expression-to-functions@^7.12.1", "@babel/helper-member-expression-to-functions@^7.12.7": - version "7.12.7" - resolved "https://registry.yarnpkg.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.12.7.tgz#aa77bd0396ec8114e5e30787efa78599d874a855" - integrity sha512-DCsuPyeWxeHgh1Dus7APn7iza42i/qXqiFPWyBDdOFtvS581JQePsc1F/nD+fHrcswhLlRc2UpYS1NwERxZhHw== +"@babel/helper-member-expression-to-functions@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.12.13.tgz#c5715695b4f8bab32660dbdcdc2341dec7e3df40" + integrity sha512-B+7nN0gIL8FZ8SvMcF+EPyB21KnCcZHQZFczCxbiNGV/O0rsrSBlWGLzmtBJ3GMjSVMIm4lpFhR+VdVBuIsUcQ== dependencies: - "@babel/types" "^7.12.7" + "@babel/types" "^7.12.13" -"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.12.1": - version "7.12.5" - resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.12.5.tgz#1bfc0229f794988f76ed0a4d4e90860850b54dfb" - integrity sha512-SR713Ogqg6++uexFRORf/+nPXMmWIn80TALu0uaFb+iQIUoR7bOC7zBWyzBs5b3tBBJXuyD0cRu1F15GyzjOWA== +"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.12.13.tgz#ec67e4404f41750463e455cc3203f6a32e93fcb0" + integrity sha512-NGmfvRp9Rqxy0uHSSVP+SRIW1q31a7Ji10cLBcqSDUngGentY4FRiHOFZFE1CLU5eiL0oE8reH7Tg1y99TDM/g== dependencies: - "@babel/types" "^7.12.5" + "@babel/types" "^7.12.13" -"@babel/helper-module-transforms@^7.12.1": - version "7.12.1" - resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.12.1.tgz#7954fec71f5b32c48e4b303b437c34453fd7247c" - integrity sha512-QQzehgFAZ2bbISiCpmVGfiGux8YVFXQ0abBic2Envhej22DVXV9nCFaS5hIQbkyo1AdGb+gNME2TSh3hYJVV/w== - dependencies: - "@babel/helper-module-imports" "^7.12.1" - "@babel/helper-replace-supers" "^7.12.1" - "@babel/helper-simple-access" "^7.12.1" - "@babel/helper-split-export-declaration" "^7.11.0" - "@babel/helper-validator-identifier" "^7.10.4" - "@babel/template" "^7.10.4" - "@babel/traverse" "^7.12.1" - "@babel/types" "^7.12.1" +"@babel/helper-module-transforms@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.12.13.tgz#01afb052dcad2044289b7b20beb3fa8bd0265bea" + integrity sha512-acKF7EjqOR67ASIlDTupwkKM1eUisNAjaSduo5Cz+793ikfnpe7p4Q7B7EWU2PCoSTPWsQkR7hRUWEIZPiVLGA== + dependencies: + "@babel/helper-module-imports" "^7.12.13" + "@babel/helper-replace-supers" "^7.12.13" + "@babel/helper-simple-access" "^7.12.13" + "@babel/helper-split-export-declaration" "^7.12.13" + "@babel/helper-validator-identifier" "^7.12.11" + "@babel/template" "^7.12.13" + "@babel/traverse" "^7.12.13" + "@babel/types" "^7.12.13" lodash "^4.17.19" -"@babel/helper-optimise-call-expression@^7.10.4", "@babel/helper-optimise-call-expression@^7.12.10": - version "7.12.10" - resolved "https://registry.yarnpkg.com/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.12.10.tgz#94ca4e306ee11a7dd6e9f42823e2ac6b49881e2d" - integrity sha512-4tpbU0SrSTjjt65UMWSrUOPZTsgvPgGG4S8QSTNHacKzpS51IVWGDj0yCwyeZND/i+LSN2g/O63jEXEWm49sYQ== +"@babel/helper-optimise-call-expression@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.12.13.tgz#5c02d171b4c8615b1e7163f888c1c81c30a2aaea" + integrity sha512-BdWQhoVJkp6nVjB7nkFWcn43dkprYauqtk++Py2eaf/GRDFm5BxRqEIZCiHlZUGAVmtwKcsVL1dC68WmzeFmiA== dependencies: - "@babel/types" "^7.12.10" + "@babel/types" "^7.12.13" -"@babel/helper-plugin-utils@^7.0.0", "@babel/helper-plugin-utils@^7.10.4", "@babel/helper-plugin-utils@^7.8.0": - version "7.10.4" - resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.10.4.tgz#2f75a831269d4f677de49986dff59927533cf375" - integrity sha512-O4KCvQA6lLiMU9l2eawBPMf1xPP8xPfB3iEQw150hOVTqj/rfXz0ThTb4HEzqQfs2Bmo5Ay8BzxfzVtBrr9dVg== +"@babel/helper-plugin-utils@^7.0.0", "@babel/helper-plugin-utils@^7.10.4", "@babel/helper-plugin-utils@^7.12.13", "@babel/helper-plugin-utils@^7.8.0": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.12.13.tgz#174254d0f2424d8aefb4dd48057511247b0a9eeb" + integrity sha512-C+10MXCXJLiR6IeG9+Wiejt9jmtFpxUc3MQqCmPY8hfCjyUGl9kT+B2okzEZrtykiwrc4dbCPdDoz0A/HQbDaA== -"@babel/helper-replace-supers@^7.12.1": - version "7.12.11" - resolved "https://registry.yarnpkg.com/@babel/helper-replace-supers/-/helper-replace-supers-7.12.11.tgz#ea511658fc66c7908f923106dd88e08d1997d60d" - integrity sha512-q+w1cqmhL7R0FNzth/PLLp2N+scXEK/L2AHbXUyydxp828F4FEa5WcVoqui9vFRiHDQErj9Zof8azP32uGVTRA== +"@babel/helper-replace-supers@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helper-replace-supers/-/helper-replace-supers-7.12.13.tgz#00ec4fb6862546bd3d0aff9aac56074277173121" + integrity sha512-pctAOIAMVStI2TMLhozPKbf5yTEXc0OJa0eENheb4w09SrgOWEs+P4nTOZYJQCqs8JlErGLDPDJTiGIp3ygbLg== dependencies: - "@babel/helper-member-expression-to-functions" "^7.12.7" - "@babel/helper-optimise-call-expression" "^7.12.10" - "@babel/traverse" "^7.12.10" - "@babel/types" "^7.12.11" + "@babel/helper-member-expression-to-functions" "^7.12.13" + "@babel/helper-optimise-call-expression" "^7.12.13" + "@babel/traverse" "^7.12.13" + "@babel/types" "^7.12.13" -"@babel/helper-simple-access@^7.12.1": - version "7.12.1" - resolved "https://registry.yarnpkg.com/@babel/helper-simple-access/-/helper-simple-access-7.12.1.tgz#32427e5aa61547d38eb1e6eaf5fd1426fdad9136" - integrity sha512-OxBp7pMrjVewSSC8fXDFrHrBcJATOOFssZwv16F3/6Xtc138GHybBfPbm9kfiqQHKhYQrlamWILwlDCeyMFEaA== +"@babel/helper-simple-access@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helper-simple-access/-/helper-simple-access-7.12.13.tgz#8478bcc5cacf6aa1672b251c1d2dde5ccd61a6c4" + integrity sha512-0ski5dyYIHEfwpWGx5GPWhH35j342JaflmCeQmsPWcrOQDtCN6C1zKAVRFVbK53lPW2c9TsuLLSUDf0tIGJ5hA== dependencies: - "@babel/types" "^7.12.1" + "@babel/types" "^7.12.13" -"@babel/helper-split-export-declaration@^7.10.4", "@babel/helper-split-export-declaration@^7.11.0", "@babel/helper-split-export-declaration@^7.12.11": - version "7.12.11" - resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.12.11.tgz#1b4cc424458643c47d37022223da33d76ea4603a" - integrity sha512-LsIVN8j48gHgwzfocYUSkO/hjYAOJqlpJEc7tGXcIm4cubjVUf8LGW6eWRyxEu7gA25q02p0rQUWoCI33HNS5g== +"@babel/helper-split-export-declaration@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.12.13.tgz#e9430be00baf3e88b0e13e6f9d4eaf2136372b05" + integrity sha512-tCJDltF83htUtXx5NLcaDqRmknv652ZWCHyoTETf1CXYJdPC7nohZohjUgieXhv0hTJdRf2FjDueFehdNucpzg== dependencies: - "@babel/types" "^7.12.11" + "@babel/types" "^7.12.13" -"@babel/helper-validator-identifier@^7.10.4", "@babel/helper-validator-identifier@^7.12.11": +"@babel/helper-validator-identifier@^7.12.11": version "7.12.11" resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.12.11.tgz#c9a1f021917dcb5ccf0d4e453e399022981fc9ed" integrity sha512-np/lG3uARFybkoHokJUmf1QfEvRVCPbmQeUQpKow5cQ3xWrV9i3rUHodKDJPQfTVX61qKi+UdYk8kik84n7XOw== -"@babel/helpers@^7.12.5": - version "7.12.5" - resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.12.5.tgz#1a1ba4a768d9b58310eda516c449913fe647116e" - integrity sha512-lgKGMQlKqA8meJqKsW6rUnc4MdUk35Ln0ATDqdM1a/UpARODdI4j5Y5lVfUScnSNkJcdCRAaWkspykNoFg9sJA== +"@babel/helpers@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.12.13.tgz#3c75e993632e4dadc0274eae219c73eb7645ba47" + integrity sha512-oohVzLRZ3GQEk4Cjhfs9YkJA4TdIDTObdBEZGrd6F/T0GPSnuV6l22eMcxlvcvzVIPH3VTtxbseudM1zIE+rPQ== dependencies: - "@babel/template" "^7.10.4" - "@babel/traverse" "^7.12.5" - "@babel/types" "^7.12.5" + "@babel/template" "^7.12.13" + "@babel/traverse" "^7.12.13" + "@babel/types" "^7.12.13" -"@babel/highlight@^7.10.4": - version "7.10.4" - resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.10.4.tgz#7d1bdfd65753538fabe6c38596cdb76d9ac60143" - integrity sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA== +"@babel/highlight@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.12.13.tgz#8ab538393e00370b26271b01fa08f7f27f2e795c" + integrity sha512-kocDQvIbgMKlWxXe9fof3TQ+gkIPOUSEYhJjqUjvKMez3krV7vbzYCDq39Oj11UAVK7JqPVGQPlgE85dPNlQww== dependencies: - "@babel/helper-validator-identifier" "^7.10.4" + "@babel/helper-validator-identifier" "^7.12.11" chalk "^2.0.0" js-tokens "^4.0.0" -"@babel/parser@^7.1.0", "@babel/parser@^7.12.0", "@babel/parser@^7.12.10", "@babel/parser@^7.12.11", "@babel/parser@^7.12.7", "@babel/parser@^7.6.0", "@babel/parser@^7.9.6": - version "7.12.11" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.11.tgz#9ce3595bcd74bc5c466905e86c535b8b25011e79" - integrity sha512-N3UxG+uuF4CMYoNj8AhnbAcJF0PiuJ9KHuy1lQmkYsxTer/MAH9UBNHsBoAX/4s6NvlDD047No8mYVGGzLL4hg== +"@babel/parser@^7.1.0", "@babel/parser@^7.12.0", "@babel/parser@^7.12.13", "@babel/parser@^7.6.0", "@babel/parser@^7.9.6": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.13.tgz#3ee7be4131fe657ba9143d5c5b3a9f253fdb75e9" + integrity sha512-z7n7ybOUzaRc3wwqLpAX8UFIXsrVXUJhtNGBwAnLz6d1KUapqyq7ad2La8gZ6CXhHmGAIL32cop8Tst4/PNWLw== "@babel/plugin-syntax-async-generators@^7.8.4": version "7.8.4" @@ -283,11 +283,11 @@ "@babel/helper-plugin-utils" "^7.8.0" "@babel/plugin-syntax-class-properties@^7.8.3": - version "7.12.1" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-class-properties/-/plugin-syntax-class-properties-7.12.1.tgz#bcb297c5366e79bebadef509549cd93b04f19978" - integrity sha512-U40A76x5gTwmESz+qiqssqmeEsKvcSyvtgktrm0uzcARAmM9I1jR221f6Oq+GmHrcD+LvZDag1UTOTe2fL3TeA== + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-class-properties/-/plugin-syntax-class-properties-7.12.13.tgz#b5c987274c4a3a82b89714796931a6b53544ae10" + integrity sha512-fm4idjKla0YahUNgFNLCB0qySdsoPiZP3iQE3rky0mBUtMZ23yDJ9SJdg6dXTSDnulOVqiF3Hgr9nbXvXTQZYA== dependencies: - "@babel/helper-plugin-utils" "^7.10.4" + "@babel/helper-plugin-utils" "^7.12.13" "@babel/plugin-syntax-import-meta@^7.10.4", "@babel/plugin-syntax-import-meta@^7.8.3": version "7.10.4" @@ -304,11 +304,11 @@ "@babel/helper-plugin-utils" "^7.8.0" "@babel/plugin-syntax-jsx@^7.0.0": - version "7.12.1" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.12.1.tgz#9d9d357cc818aa7ae7935917c1257f67677a0926" - integrity sha512-1yRi7yAtB0ETgxdY9ti/p2TivUxJkTdhu/ZbF9MshVGqOx1TdB3b7xCXs49Fupgg50N45KcAsRP/ZqWjs9SRjg== + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.12.13.tgz#044fb81ebad6698fe62c478875575bcbb9b70f15" + integrity sha512-d4HM23Q1K7oq/SLNmG6mRt85l2csmQ0cHRaxRXjKW0YFdEXqlZ5kzFQKH5Uc3rDJECgu+yCRgPkG04Mm98R/1g== dependencies: - "@babel/helper-plugin-utils" "^7.10.4" + "@babel/helper-plugin-utils" "^7.12.13" "@babel/plugin-syntax-logical-assignment-operators@^7.8.3": version "7.10.4" @@ -353,92 +353,68 @@ "@babel/helper-plugin-utils" "^7.8.0" "@babel/plugin-syntax-top-level-await@^7.8.3": - version "7.12.1" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-top-level-await/-/plugin-syntax-top-level-await-7.12.1.tgz#dd6c0b357ac1bb142d98537450a319625d13d2a0" - integrity sha512-i7ooMZFS+a/Om0crxZodrTzNEPJHZrlMVGMTEpFAj6rYY/bKCddB0Dk/YxfPuYXOopuhKk/e1jV6h+WUU9XN3A== + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-top-level-await/-/plugin-syntax-top-level-await-7.12.13.tgz#c5f0fa6e249f5b739727f923540cf7a806130178" + integrity sha512-A81F9pDwyS7yM//KwbCSDqy3Uj4NMIurtplxphWxoYtNPov7cJsDkAFNNyVlIZ3jwGycVsurZ+LtOA8gZ376iQ== dependencies: - "@babel/helper-plugin-utils" "^7.10.4" + "@babel/helper-plugin-utils" "^7.12.13" -"@babel/plugin-syntax-typescript@^7.12.1": - version "7.12.1" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.12.1.tgz#460ba9d77077653803c3dd2e673f76d66b4029e5" - integrity sha512-UZNEcCY+4Dp9yYRCAHrHDU+9ZXLYaY9MgBXSRLkB9WjYFRR6quJBumfVrEkUxrePPBwFcpWfNKXqVRQQtm7mMA== +"@babel/plugin-syntax-typescript@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.12.13.tgz#9dff111ca64154cef0f4dc52cf843d9f12ce4474" + integrity sha512-cHP3u1JiUiG2LFDKbXnwVad81GvfyIOmCD6HIEId6ojrY0Drfy2q1jw7BwN7dE84+kTnBjLkXoL3IEy/3JPu2w== dependencies: - "@babel/helper-plugin-utils" "^7.10.4" + "@babel/helper-plugin-utils" "^7.12.13" "@babel/plugin-transform-typescript@^7.12.1": - version "7.12.1" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.12.1.tgz#d92cc0af504d510e26a754a7dbc2e5c8cd9c7ab4" - integrity sha512-VrsBByqAIntM+EYMqSm59SiMEf7qkmI9dqMt6RbD/wlwueWmYcI0FFK5Fj47pP6DRZm+3teXjosKlwcZJ5lIMw== + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.12.13.tgz#8bcb5dd79cb8bba690d6920e19992d9228dfed48" + integrity sha512-z1VWskPJxK9tfxoYvePWvzSJC+4pxXr8ArmRm5ofqgi+mwpKg6lvtomkIngBYMJVnKhsFYVysCQLDn//v2RHcg== dependencies: - "@babel/helper-create-class-features-plugin" "^7.12.1" - "@babel/helper-plugin-utils" "^7.10.4" - "@babel/plugin-syntax-typescript" "^7.12.1" + "@babel/helper-create-class-features-plugin" "^7.12.13" + "@babel/helper-plugin-utils" "^7.12.13" + "@babel/plugin-syntax-typescript" "^7.12.13" "@babel/runtime@^7.1.2", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.5": - version "7.12.5" - resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.5.tgz#410e7e487441e1b360c29be715d870d9b985882e" - integrity sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg== + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.13.tgz#0a21452352b02542db0ffb928ac2d3ca7cb6d66d" + integrity sha512-8+3UMPBrjFa/6TtKi/7sehPKqfAm4g6K+YQjyyFOLUTxzOngcRZTlAVY8sc2CORJYqdHQY8gRPHmn+qo15rCBw== dependencies: regenerator-runtime "^0.13.4" "@babel/standalone@^7.12.12": - version "7.12.12" - resolved "https://registry.yarnpkg.com/@babel/standalone/-/standalone-7.12.12.tgz#f858ab1c76d9c4c23fe0783a0330ad37755f0176" - integrity sha512-sHuNDN9NvPHsDAmxPD3RpsIeqCoFSW+ySa6+3teInrYe9y0Gn5swLQ2ZE7Zk6L8eBBESZM2ob1l98qWauQfDMA== - -"@babel/template@^7.0.0", "@babel/template@^7.10.4", "@babel/template@^7.12.7", "@babel/template@^7.3.3": - version "7.12.7" - resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.12.7.tgz#c817233696018e39fbb6c491d2fb684e05ed43bc" - integrity sha512-GkDzmHS6GV7ZeXfJZ0tLRBhZcMcY0/Lnb+eEbXDBfCAcZCjrZKe6p3J4we/D24O9Y8enxWAg1cWwof59yLh2ow== - dependencies: - "@babel/code-frame" "^7.10.4" - "@babel/parser" "^7.12.7" - "@babel/types" "^7.12.7" - -"@babel/traverse@^7.0.0": - version "7.12.12" - resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.12.12.tgz#d0cd87892704edd8da002d674bc811ce64743376" - integrity sha512-s88i0X0lPy45RrLM8b9mz8RPH5FqO9G9p7ti59cToE44xFm1Q+Pjh5Gq4SXBbtb88X7Uy7pexeqRIQDDMNkL0w== - dependencies: - "@babel/code-frame" "^7.12.11" - "@babel/generator" "^7.12.11" - "@babel/helper-function-name" "^7.12.11" - "@babel/helper-split-export-declaration" "^7.12.11" - "@babel/parser" "^7.12.11" - "@babel/types" "^7.12.12" + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/standalone/-/standalone-7.12.13.tgz#99650a35132de1a13e377d4a63b7286fd95c7e1b" + integrity sha512-GCI57RGfODuEv69t3HRv0ZGsZYHZf9Wb2dwne8BXod0UOcTN3HWAunSrSTR42fHTIQD1yj1r8Zx0AINSYz97Ew== + +"@babel/template@^7.0.0", "@babel/template@^7.12.13", "@babel/template@^7.3.3": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.12.13.tgz#530265be8a2589dbb37523844c5bcb55947fb327" + integrity sha512-/7xxiGA57xMo/P2GVvdEumr8ONhFOhfgq2ihK3h1e6THqzTAkHbkXgB0xI9yeTfIUoH3+oAeHhqm/I43OTbbjA== + dependencies: + "@babel/code-frame" "^7.12.13" + "@babel/parser" "^7.12.13" + "@babel/types" "^7.12.13" + +"@babel/traverse@^7.0.0", "@babel/traverse@^7.1.0", "@babel/traverse@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.12.13.tgz#689f0e4b4c08587ad26622832632735fb8c4e0c0" + integrity sha512-3Zb4w7eE/OslI0fTp8c7b286/cQps3+vdLW3UcwC8VSJC6GbKn55aeVVu2QJNuCDoeKyptLOFrPq8WqZZBodyA== + dependencies: + "@babel/code-frame" "^7.12.13" + "@babel/generator" "^7.12.13" + "@babel/helper-function-name" "^7.12.13" + "@babel/helper-split-export-declaration" "^7.12.13" + "@babel/parser" "^7.12.13" + "@babel/types" "^7.12.13" debug "^4.1.0" globals "^11.1.0" lodash "^4.17.19" -"@babel/traverse@^7.1.0", "@babel/traverse@^7.12.1", "@babel/traverse@^7.12.10", "@babel/traverse@^7.12.5": - version "7.12.10" - resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.12.10.tgz#2d1f4041e8bf42ea099e5b2dc48d6a594c00017a" - integrity sha512-6aEtf0IeRgbYWzta29lePeYSk+YAFIC3kyqESeft8o5CkFlYIMX+EQDDWEiAQ9LHOA3d0oHdgrSsID/CKqXJlg== - dependencies: - "@babel/code-frame" "^7.10.4" - "@babel/generator" "^7.12.10" - "@babel/helper-function-name" "^7.10.4" - "@babel/helper-split-export-declaration" "^7.11.0" - "@babel/parser" "^7.12.10" - "@babel/types" "^7.12.10" - debug "^4.1.0" - globals "^11.1.0" - lodash "^4.17.19" - -"@babel/types@^7.0.0", "@babel/types@^7.12.0", "@babel/types@^7.12.1", "@babel/types@^7.12.10", "@babel/types@^7.12.11", "@babel/types@^7.12.5", "@babel/types@^7.12.7", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.6.1", "@babel/types@^7.9.6": - version "7.12.11" - resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.12.11.tgz#a86e4d71e30a9b6ee102590446c98662589283ce" - integrity sha512-ukA9SQtKThINm++CX1CwmliMrE54J6nIYB5XTwL5f/CLFW9owfls+YSU8tVW15RQ2w+a3fSbPjC6HdQNtWZkiA== - dependencies: - "@babel/helper-validator-identifier" "^7.12.11" - lodash "^4.17.19" - to-fast-properties "^2.0.0" - -"@babel/types@^7.12.12": - version "7.12.12" - resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.12.12.tgz#4608a6ec313abbd87afa55004d373ad04a96c299" - integrity sha512-lnIX7piTxOH22xE7fDXDbSHg9MM1/6ORnafpJmov5rs0kX5g4BZxeXNJLXsMRiO0U5Rb8/FvMS6xlTnTHvxonQ== +"@babel/types@^7.0.0", "@babel/types@^7.12.0", "@babel/types@^7.12.13", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.6.1", "@babel/types@^7.9.6": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.12.13.tgz#8be1aa8f2c876da11a9cf650c0ecf656913ad611" + integrity sha512-oKrdZTld2im1z8bDwTOQvUbxKwE+854zc16qWZQlcTqMN00pWxHQ4ZeOq0yDMnisOpRykH2/5Qqcrk/OlbAjiQ== dependencies: "@babel/helper-validator-identifier" "^7.12.11" lodash "^4.17.19" @@ -480,10 +456,10 @@ "@francoischalifour/autocomplete-preset-algolia" "^1.0.0-alpha.28" algoliasearch "^4.0.0" -"@eslint/eslintrc@^0.2.2": - version "0.2.2" - resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.2.2.tgz#d01fc791e2fc33e88a29d6f3dc7e93d0cd784b76" - integrity sha512-EfB5OHNYp1F4px/LI/FEnGylop7nOqkQ1LRzCM0KccA2U8tvV8w01KBv37LbO7nW4H+YhKyo2LcJhRwjjV17QQ== +"@eslint/eslintrc@^0.3.0": + version "0.3.0" + resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.3.0.tgz#d736d6963d7003b6514e6324bec9c602ac340318" + integrity sha512-1JTKgrOKAHVivSvOYw+sJOunkBjUOvjqWk1DPja7ZFhIS2mX/4EgTT8M7eTK9jrKhL/FvXXEbQwIs3pg1xp3dg== dependencies: ajv "^6.12.4" debug "^4.1.1" @@ -492,7 +468,7 @@ ignore "^4.0.6" import-fresh "^3.2.1" js-yaml "^3.13.1" - lodash "^4.17.19" + lodash "^4.17.20" minimatch "^3.0.4" strip-json-comments "^3.1.1" @@ -702,9 +678,9 @@ "@rushstack/node-core-library" "3.35.2" "@microsoft/api-extractor@^7.12.1": - version "7.12.1" - resolved "https://registry.yarnpkg.com/@microsoft/api-extractor/-/api-extractor-7.12.1.tgz#4204be6c9f845d7d1796b6d51c58bcb25e7267e9" - integrity sha512-lleLrKkqiRvOQeoRMSHQY0wl/j9SxRVd9+Btyh/WWw0kHNy7nAKyzGmejvlz2XTn13H0elJWV6C3dxhaQy4mtA== + version "7.13.0" + resolved "https://registry.yarnpkg.com/@microsoft/api-extractor/-/api-extractor-7.13.0.tgz#13900fc7596c29daeecd3f33ed8960cfc5250107" + integrity sha512-T+14VIhB91oJIett5AZ02VWYmz/01VHFWkcAOWiErIQ8AiFhJZoGqTjGxoi8ZpEEBuAj2EGVYojORwLc/+aiDQ== dependencies: "@microsoft/api-extractor-model" "7.12.1" "@microsoft/tsdoc" "0.12.24" @@ -716,32 +692,32 @@ resolve "~1.17.0" semver "~7.3.0" source-map "~0.6.1" - typescript "~4.0.5" + typescript "~4.1.3" "@microsoft/tsdoc@0.12.24": version "0.12.24" resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.12.24.tgz#30728e34ebc90351dd3aff4e18d038eed2c3e098" integrity sha512-Mfmij13RUTmHEMi9vRUhMXD7rnGR2VvxeNYtaGtaJ4redwwjT4UXYJ+nzmVJF7hhd4pn/Fx5sncDKxMVFJSWPg== -"@nodelib/fs.scandir@2.1.3": - version "2.1.3" - resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz#3a582bdb53804c6ba6d146579c46e52130cf4a3b" - integrity sha512-eGmwYQn3gxo4r7jdQnkrrN6bY478C3P+a/y72IJukF8LjB6ZHeB3c+Ehacj3sYeSmUXGlnA67/PmbM9CVwL7Dw== +"@nodelib/fs.scandir@2.1.4": + version "2.1.4" + resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.4.tgz#d4b3549a5db5de2683e0c1071ab4f140904bbf69" + integrity sha512-33g3pMJk3bg5nXbL/+CY6I2eJDzZAni49PfJnL5fghPTggPvBd/pFNSgJsdAgWptuFu7qq/ERvOYFlhvsLTCKA== dependencies: - "@nodelib/fs.stat" "2.0.3" + "@nodelib/fs.stat" "2.0.4" run-parallel "^1.1.9" -"@nodelib/fs.stat@2.0.3", "@nodelib/fs.stat@^2.0.2": - version "2.0.3" - resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-2.0.3.tgz#34dc5f4cabbc720f4e60f75a747e7ecd6c175bd3" - integrity sha512-bQBFruR2TAwoevBEd/NWMoAAtNGzTRgdrqnYCc7dhzfoNvqPzLyqlEQnzZ3kVnNrSp25iyxE00/3h2fqGAGArA== +"@nodelib/fs.stat@2.0.4", "@nodelib/fs.stat@^2.0.2": + version "2.0.4" + resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-2.0.4.tgz#a3f2dd61bab43b8db8fa108a121cfffe4c676655" + integrity sha512-IYlHJA0clt2+Vg7bccq+TzRdJvv19c2INqBSsoOLp1je7xjtr7J26+WXR72MCdvU9q1qTzIWDfhMf+DRvQJK4Q== "@nodelib/fs.walk@^1.2.3": - version "1.2.4" - resolved "https://registry.yarnpkg.com/@nodelib/fs.walk/-/fs.walk-1.2.4.tgz#011b9202a70a6366e436ca5c065844528ab04976" - integrity sha512-1V9XOY4rDW0rehzbrcqAmHnz8e7SKvX27gh8Gt2WgB0+pdzdiLV83p72kZPU+jvMbS1qU5mauP2iOvO8rhmurQ== + version "1.2.6" + resolved "https://registry.yarnpkg.com/@nodelib/fs.walk/-/fs.walk-1.2.6.tgz#cce9396b30aa5afe9e3756608f5831adcb53d063" + integrity sha512-8Broas6vTtW4GIXTAHDoE32hnN2M5ykgCpWGbuXHQ15vEMqr23pB76e/GZcYsZCHALv50ktd24qhEyKr6wBtow== dependencies: - "@nodelib/fs.scandir" "2.1.3" + "@nodelib/fs.scandir" "2.1.4" fastq "^1.6.0" "@polka/url@^0.5.0": @@ -755,16 +731,16 @@ integrity sha512-3NsZsJIA/22P3QUyrEDNA2D133H4j224twJrdipXN38dpnIOzAbUDtOwkcJ5pXmn75w7LSQDjA4tO9dm1XlqlA== "@rollup/plugin-alias@^3.1.1": - version "3.1.1" - resolved "https://registry.yarnpkg.com/@rollup/plugin-alias/-/plugin-alias-3.1.1.tgz#bb96cf37fefeb0a953a6566c284855c7d1cd290c" - integrity sha512-hNcQY4bpBUIvxekd26DBPgF7BT4mKVNDF5tBG4Zi+3IgwLxGYRY0itHs9D0oLVwXM5pvJDWJlBQro+au8WaUWw== + version "3.1.2" + resolved "https://registry.yarnpkg.com/@rollup/plugin-alias/-/plugin-alias-3.1.2.tgz#c585b05be4a7782d269c69d13def56f44e417772" + integrity sha512-wzDnQ6v7CcoRzS0qVwFPrFdYA4Qlr+ookA217Y2Z3DPZE1R8jrFNM3jvGgOf6o6DMjbnQIn5lCIJgHPe1Bt3uw== dependencies: slash "^3.0.0" "@rollup/plugin-commonjs@^17.0.0": - version "17.0.0" - resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-17.0.0.tgz#2ae2228354cf0fbba6cf9f06f30b2c66a974324c" - integrity sha512-/omBIJG1nHQc+bgkYDuLpb/V08QyutP9amOrJRUSlYJZP+b/68gM//D8sxJe3Yry2QnYIr3QjR3x4AlxJEN3GA== + version "17.1.0" + resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-17.1.0.tgz#757ec88737dffa8aa913eb392fade2e45aef2a2d" + integrity sha512-PoMdXCw0ZyvjpCMT5aV4nkL0QywxP29sODQsSGeDpr/oI49Qq9tRtAsb/LbYbDzFlOydVEqHmmZWFtXJEAX9ew== dependencies: "@rollup/pluginutils" "^3.1.0" commondir "^1.0.1" @@ -792,9 +768,9 @@ "@rollup/pluginutils" "^3.0.8" "@rollup/plugin-node-resolve@^11.0.1": - version "11.0.1" - resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.0.1.tgz#d3765eec4bccf960801439a999382aed2dca959b" - integrity sha512-ltlsj/4Bhwwhb+Nb5xCz/6vieuEj2/BAkkqVIKmZwC7pIdl8srmgmglE4S0jFlZa32K4qvdQ6NHdmpRKD/LwoQ== + version "11.1.1" + resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.1.1.tgz#47bc34252914794a1b06fb50371d7520a03f91f3" + integrity sha512-zlBXR4eRS+2m79TsUZWhsd0slrHUYdRx4JF+aVQm+MI0wsKdlpC2vlDVjmlGvtZY1vsefOT9w3JxvmWSBei+Lg== dependencies: "@rollup/pluginutils" "^3.1.0" "@types/resolve" "1.17.1" @@ -804,9 +780,9 @@ resolve "^1.19.0" "@rollup/plugin-typescript@^8.0.0": - version "8.1.0" - resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-8.1.0.tgz#b7bbbbb4fd1324834f37844efd48b3844d912742" - integrity sha512-pyQlcGQYRsONUDwXK3ckGPHjPzmjlq4sinzr7emW8ZMb2oZjg9WLcdcP8wyHSvBjvHrLzMayyPy079RROqb4vw== + version "8.1.1" + resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-8.1.1.tgz#cadd6c381a92cc7e8148cc8b1eeba146020635d0" + integrity sha512-DPFy0SV8/GgHFL31yPFVo0G1T3yzwdw6R9KisBfO2zCYbDHUqDChSWr1KmtpGz/TmutpoGJjIvu80p9HzCEF0A== dependencies: "@rollup/pluginutils" "^3.1.0" resolve "^1.17.0" @@ -863,9 +839,9 @@ string-argv "~0.3.1" "@sinonjs/commons@^1.7.0": - version "1.8.1" - resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.1.tgz#e7df00f98a203324f6dc7cc606cad9d4a8ab2217" - integrity sha512-892K+kWUUi3cl+LlqEWIDrhvLgdL79tECi8JZUyq6IviKy/DNhuzCRlbHUjxK89f4ypPMMaFnFuR9Ie6DoIMsw== + version "1.8.2" + resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.2.tgz#858f5c4b48d80778fde4b9d541f27edc0d56488b" + integrity sha512-sruwd86RJHdsVf/AtBoijDmUqJp3B6hF/DGC23C+JaegnDHaZyewCjoVGTdg3J0uz3Zs7NnIT05OBOmML72lQw== dependencies: type-detect "4.0.8" @@ -937,16 +913,21 @@ resolved "https://registry.yarnpkg.com/@types/es-module-lexer/-/es-module-lexer-0.3.0.tgz#9fee3f19f64e6b3f999eeb3a70bd177a4d57a6cb" integrity sha512-XI3MGSejUQIJ3wzY0i5IHy5J3eb36M/ytgG8jIOssP08ovtRPcjpjXQqrx51AHBNBOisTS/NQNWJitI17+EwzQ== -"@types/estree@*", "@types/estree@^0.0.45": - version "0.0.45" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.45.tgz#e9387572998e5ecdac221950dab3e8c3b16af884" - integrity sha512-jnqIUKDUqJbDIUxm0Uj7bnlMnRm1T/eZ9N+AVMqhPgzrba2GhGG5o/jCTwmdPK709nEZsGoMzXEDUjcXHa3W0g== +"@types/estree@*": + version "0.0.46" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.46.tgz#0fb6bfbbeabd7a30880504993369c4bf1deab1fe" + integrity sha512-laIjwTQaD+5DukBZaygQ79K1Z0jb1bPEMRrkXSLjtCcZm+abyp5YbrqpSLzD42FwWW6gK/aS4NYpJ804nG2brg== "@types/estree@0.0.39": version "0.0.39" resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== +"@types/estree@^0.0.45": + version "0.0.45" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.45.tgz#e9387572998e5ecdac221950dab3e8c3b16af884" + integrity sha512-jnqIUKDUqJbDIUxm0Uj7bnlMnRm1T/eZ9N+AVMqhPgzrba2GhGG5o/jCTwmdPK709nEZsGoMzXEDUjcXHa3W0g== + "@types/etag@^1.8.0": version "1.8.0" resolved "https://registry.yarnpkg.com/@types/etag/-/etag-1.8.0.tgz#37f0b1f3ea46da7ae319bbedb607e375b4c99f7e" @@ -955,9 +936,9 @@ "@types/node" "*" "@types/fs-extra@^9.0.5": - version "9.0.5" - resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.5.tgz#2afb76a43a4bef80a363b94b314d0ca1694fc4f8" - integrity sha512-wr3t7wIW1c0A2BIJtdVp4EflriVaVVAsCAIHVzzh8B+GiFv9X1xeJjCs4upRXtzp7kQ6lP5xvskjoD4awJ1ZeA== + version "9.0.6" + resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.6.tgz#488e56b77299899a608b8269719c1d133027a6ab" + integrity sha512-ecNRHw4clCkowNOBJH1e77nvbPxHYnWIXMv1IAoG/9+MYGkgoyr3Ppxr7XYFNL41V422EDhyV4/4SSK8L2mlig== dependencies: "@types/node" "*" @@ -993,9 +974,9 @@ "@types/istanbul-lib-report" "*" "@types/jest@26.x", "@types/jest@^26.0.19": - version "26.0.19" - resolved "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.19.tgz#e6fa1e3def5842ec85045bd5210e9bb8289de790" - integrity sha512-jqHoirTG61fee6v6rwbnEuKhpSKih0tuhqeFbCmMmErhtu3BYlOZaXWjffgOstMM4S/3iQD31lI5bGLTrs97yQ== + version "26.0.20" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.20.tgz#cd2f2702ecf69e86b586e1f5223a60e454056307" + integrity sha512-9zi2Y+5USJRxd0FsahERhBwlcvFh6D2GLQnY2FH2BzK8J9s9omvNHIbvABwIluXa0fD8XVKMLTO0aOEuUfACAA== dependencies: jest-diff "^26.0.0" pretty-format "^26.0.0" @@ -1016,9 +997,9 @@ integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg== "@types/node@*", "@types/node@^14.14.10": - version "14.14.14" - resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.14.tgz#f7fd5f3cc8521301119f63910f0fb965c7d761ae" - integrity sha512-UHnOPWVWV1z+VV8k6L1HhG7UbGBgIdghqF3l9Ny9ApPghbjICXkUJSd/b9gOgQfjM1r+37cipdw/HJ3F6ICEnQ== + version "14.14.22" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.22.tgz#0d29f382472c4ccf3bd96ff0ce47daf5b7b84b18" + integrity sha512-g+f/qj/cNcqKkc3tFqlXOYjrmZA+jNBiDzbP3kH+B+otKFqAdPgVTGP1IeKRdMml/aE69as5S4FqtxAbl+LaMw== "@types/node@10.17.13": version "10.17.13" @@ -1036,37 +1017,24 @@ integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA== "@types/prettier@^2.0.0": - version "2.1.5" - resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.1.5.tgz#b6ab3bba29e16b821d84e09ecfaded462b816b00" - integrity sha512-UEyp8LwZ4Dg30kVU2Q3amHHyTn1jEdhCIE59ANed76GaT1Vp76DD3ZWSAxgCrw6wJ0TqeoBpqmfUHiUDPs//HQ== - -"@types/prop-types@*": - version "15.7.3" - resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7" - integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw== - -"@types/react-dom@^17.0.0": - version "17.0.0" - resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.0.tgz#b3b691eb956c4b3401777ee67b900cb28415d95a" - integrity sha512-lUqY7OlkF/RbNtD5nIq7ot8NquXrdFrjSOR6+w9a9RFQevGi1oZO1dcJbXMeONAPKtZ2UrZOEJ5UOCVsxbLk/g== - dependencies: - "@types/react" "*" - -"@types/react@*", "@types/react@^17.0.0": - version "17.0.0" - resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.0.tgz#5af3eb7fad2807092f0046a1302b7823e27919b8" - integrity sha512-aj/L7RIMsRlWML3YB6KZiXB3fV2t41+5RBGYF8z+tAKU43Px8C3cYUZsDvf1/+Bm4FK21QWBrDutu8ZJ/70qOw== - dependencies: - "@types/prop-types" "*" - csstype "^3.0.2" + version "2.1.6" + resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.1.6.tgz#f4b1efa784e8db479cdb8b14403e2144b1e9ff03" + integrity sha512-6gOkRe7OIioWAXfnO/2lFiv+SJichKVSys1mSsgyrYHSEjk8Ctv4tSR/Odvnu+HWlH2C8j53dahU03XmQdd5fA== -"@types/resolve@1.17.1", "@types/resolve@^1.17.1": +"@types/resolve@1.17.1": version "1.17.1" resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6" integrity sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw== dependencies: "@types/node" "*" +"@types/resolve@^1.17.1": + version "1.19.0" + resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.19.0.tgz#75c729aedd9a0de60650facb16eb33239d3c407a" + integrity sha512-NikKq+D2KJzmaWbcz4JLVT34ybtCC4c3jV6XRGWOQvOkXka9QblEmC+sPf3vRa3lmcURkVbCk2V2BDyCO7jbXg== + dependencies: + "@types/node" "*" + "@types/sass@^1.16.0": version "1.16.0" resolved "https://registry.yarnpkg.com/@types/sass/-/sass-1.16.0.tgz#b41ac1c17fa68ffb57d43e2360486ef526b3d57d" @@ -1092,14 +1060,14 @@ "@types/node" "*" "@types/yargs-parser@*": - version "15.0.0" - resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-15.0.0.tgz#cb3f9f741869e20cce330ffbeb9271590483882d" - integrity sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw== + version "20.2.0" + resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-20.2.0.tgz#dd3e6699ba3237f0348cd085e4698780204842f9" + integrity sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA== "@types/yargs@^15.0.0": - version "15.0.12" - resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-15.0.12.tgz#6234ce3e3e3fa32c5db301a170f96a599c960d74" - integrity sha512-f+fD/fQAo3BCbCDlrUpznF1A5Zp9rB0noS5vnoormHSIPFKL0Z2DcUJ3Gxp5ytH4uLRNxy7AwYUC9exZzqGMAw== + version "15.0.13" + resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-15.0.13.tgz#34f7fec8b389d7f3c1fd08026a5763e072d3c6dc" + integrity sha512-kQ5JNTrbDv3Rp5X2n/iUu37IJBDU2gsZ5R/g1/KHOOEc5IKfUFjXT6DENPGduh08I/pamwtEq4oul7gUqKTQDQ== dependencies: "@types/yargs-parser" "*" @@ -1111,35 +1079,35 @@ "@types/node" "*" "@typescript-eslint/parser@^4.9.1": - version "4.11.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.11.0.tgz#1dd3d7e42708c10ce9f3aa64c63c0ab99868b4e2" - integrity sha512-NBTtKCC7ZtuxEV5CrHUO4Pg2s784pvavc3cnz6V+oJvVbK4tH9135f/RBP6eUA2KHiFKAollSrgSctQGmHbqJQ== + version "4.14.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.14.2.tgz#31e216e4baab678a56e539f9db9862e2542c98d0" + integrity sha512-ipqSP6EuUsMu3E10EZIApOJgWSpcNXeKZaFeNKQyzqxnQl8eQCbV+TSNsl+s2GViX2d18m1rq3CWgnpOxDPgHg== dependencies: - "@typescript-eslint/scope-manager" "4.11.0" - "@typescript-eslint/types" "4.11.0" - "@typescript-eslint/typescript-estree" "4.11.0" + "@typescript-eslint/scope-manager" "4.14.2" + "@typescript-eslint/types" "4.14.2" + "@typescript-eslint/typescript-estree" "4.14.2" debug "^4.1.1" -"@typescript-eslint/scope-manager@4.11.0": - version "4.11.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.11.0.tgz#2d906537db8a3a946721699e4fc0833810490254" - integrity sha512-6VSTm/4vC2dHM3ySDW9Kl48en+yLNfVV6LECU8jodBHQOhO8adAVizaZ1fV0QGZnLQjQ/y0aBj5/KXPp2hBTjA== +"@typescript-eslint/scope-manager@4.14.2": + version "4.14.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.14.2.tgz#64cbc9ca64b60069aae0c060b2bf81163243b266" + integrity sha512-cuV9wMrzKm6yIuV48aTPfIeqErt5xceTheAgk70N1V4/2Ecj+fhl34iro/vIssJlb7XtzcaD07hWk7Jk0nKghg== dependencies: - "@typescript-eslint/types" "4.11.0" - "@typescript-eslint/visitor-keys" "4.11.0" + "@typescript-eslint/types" "4.14.2" + "@typescript-eslint/visitor-keys" "4.14.2" -"@typescript-eslint/types@4.11.0": - version "4.11.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.11.0.tgz#86cf95e7eac4ccfd183f9fcf1480cece7caf4ca4" - integrity sha512-XXOdt/NPX++txOQHM1kUMgJUS43KSlXGdR/aDyEwuAEETwuPt02Nc7v+s57PzuSqMbNLclblQdv3YcWOdXhQ7g== +"@typescript-eslint/types@4.14.2": + version "4.14.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.14.2.tgz#d96da62be22dc9dc6a06647f3633815350fb3174" + integrity sha512-LltxawRW6wXy4Gck6ZKlBD05tCHQUj4KLn4iR69IyRiDHX3d3NCAhO+ix5OR2Q+q9bjCrHE/HKt+riZkd1At8Q== -"@typescript-eslint/typescript-estree@4.11.0": - version "4.11.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.11.0.tgz#1144d145841e5987d61c4c845442a24b24165a4b" - integrity sha512-eA6sT5dE5RHAFhtcC+b5WDlUIGwnO9b0yrfGa1mIOIAjqwSQCpXbLiFmKTdRbQN/xH2EZkGqqLDrKUuYOZ0+Hg== +"@typescript-eslint/typescript-estree@4.14.2": + version "4.14.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.14.2.tgz#9c5ebd8cae4d7b014f890acd81e8e17f309c9df9" + integrity sha512-ESiFl8afXxt1dNj8ENEZT12p+jl9PqRur+Y19m0Z/SPikGL6rqq4e7Me60SU9a2M28uz48/8yct97VQYaGl0Vg== dependencies: - "@typescript-eslint/types" "4.11.0" - "@typescript-eslint/visitor-keys" "4.11.0" + "@typescript-eslint/types" "4.14.2" + "@typescript-eslint/visitor-keys" "4.14.2" debug "^4.1.1" globby "^11.0.1" is-glob "^4.0.1" @@ -1147,45 +1115,34 @@ semver "^7.3.2" tsutils "^3.17.1" -"@typescript-eslint/visitor-keys@4.11.0": - version "4.11.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.11.0.tgz#906669a50f06aa744378bb84c7d5c4fdbc5b7d51" - integrity sha512-tRYKyY0i7cMk6v4UIOCjl1LhuepC/pc6adQqJk4Is3YcC6k46HvsV9Wl7vQoLbm9qADgeujiT7KdLrylvFIQ+A== +"@typescript-eslint/visitor-keys@4.14.2": + version "4.14.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.14.2.tgz#997cbe2cb0690e1f384a833f64794e98727c70c6" + integrity sha512-KBB+xLBxnBdTENs/rUgeUKO0UkPBRs2vD09oMRRIkj5BEN8PX1ToXV532desXfpQnZsYTyLLviS7JrPhdL154w== dependencies: - "@typescript-eslint/types" "4.11.0" + "@typescript-eslint/types" "4.14.2" eslint-visitor-keys "^2.0.0" -"@vue/babel-helper-vue-transform-on@^1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-transform-on/-/babel-helper-vue-transform-on-1.0.0.tgz#8cbec6bbcae53626ad70139061be5e73403c9a62" - integrity sha512-svFuKPoXP92TJ76ztENOglOsLjcMGUXkdeQhYDxl6KBnZCpqFjqx6RodUPWFg1bj4zsUVsfoIh1RibLO86fUUQ== +"@vue/babel-helper-vue-transform-on@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-transform-on/-/babel-helper-vue-transform-on-1.0.2.tgz#9b9c691cd06fc855221a2475c3cc831d774bc7dc" + integrity sha512-hz4R8tS5jMn8lDq6iD+yWL6XNB699pGIVLk7WSJnn1dbpjaazsjZQkieJoRX6gW5zpYSCFqQ7jUquPNY65tQYA== "@vue/babel-plugin-jsx@^1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@vue/babel-plugin-jsx/-/babel-plugin-jsx-1.0.1.tgz#8ece4e521888fabe2c96adca428606e5cea55f54" - integrity sha512-pE1YlINZBzqaLeSNfrvo0nNvYjtWTBU+sXUrx65sLW7DL+nDCZcAVeVkMFDcpT1jIahx4hI3EzOcGZE6oLPLoA== + version "1.0.2" + resolved "https://registry.yarnpkg.com/@vue/babel-plugin-jsx/-/babel-plugin-jsx-1.0.2.tgz#6bfd8e39c48e53391a56705649f81a35fe20b6a1" + integrity sha512-1uZlQCLCeuqJgDYLCmg3qfsvTVtOQiXh278ES4bvPTYYbv2Bi/rElLETK6AdjI9xxzyTUf5n1QEiH8Xxz0eZrg== dependencies: "@babel/helper-module-imports" "^7.0.0" "@babel/plugin-syntax-jsx" "^7.0.0" "@babel/template" "^7.0.0" "@babel/traverse" "^7.0.0" "@babel/types" "^7.0.0" - "@vue/babel-helper-vue-transform-on" "^1.0.0" + "@vue/babel-helper-vue-transform-on" "^1.0.2" camelcase "^6.0.0" html-tags "^3.1.0" svg-tags "^1.0.0" -"@vue/compiler-core@3.0.4": - version "3.0.4" - resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.0.4.tgz#0122aca6eada4cb28b39ed930af917444755e330" - integrity sha512-snpMICsbWTZqBFnPB03qr4DtiSxVYfDF3DvbDSkN9Z9NTM8Chl8E/lYhKBSsvauq91DAWAh8PU3lr9vrLyQsug== - dependencies: - "@babel/parser" "^7.12.0" - "@babel/types" "^7.12.0" - "@vue/shared" "3.0.4" - estree-walker "^2.0.1" - source-map "^0.6.1" - "@vue/compiler-core@3.0.5": version "3.0.5" resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.0.5.tgz#a6e54cabe9536e74c6513acd2649f311af1d43ac" @@ -1197,15 +1154,7 @@ estree-walker "^2.0.1" source-map "^0.6.1" -"@vue/compiler-dom@3.0.4", "@vue/compiler-dom@^3.0.4": - version "3.0.4" - resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.0.4.tgz#834fd4b15c5698cf9f4505c2bfbccca058a843eb" - integrity sha512-FOxbHBIkkGjYQeTz1DlXQjS1Ms8EPXQWsdTdTPeohoS0KzCz6RiOjiAG+jLtMi6Nr5GX2h0TlCvcnI8mcsicFQ== - dependencies: - "@vue/compiler-core" "3.0.4" - "@vue/shared" "3.0.4" - -"@vue/compiler-dom@3.0.5": +"@vue/compiler-dom@3.0.5", "@vue/compiler-dom@^3.0.4": version "3.0.5" resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.0.5.tgz#7885a13e6d18f64dde8ebceec052ed2c102696c2" integrity sha512-HSOSe2XSPuCkp20h4+HXSiPH9qkhz6YbW9z9ZtL5vef2T2PMugH7/osIFVSrRZP/Ul5twFZ7MIRlp8tPX6e4/g== @@ -1213,29 +1162,7 @@ "@vue/compiler-core" "3.0.5" "@vue/shared" "3.0.5" -"@vue/compiler-sfc@^3.0.4": - version "3.0.4" - resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.0.4.tgz#2119fe1e68d2c268aafa20461c82c139a9adf8e0" - integrity sha512-brDn6HTuK6R3oBCjtMPPsIpyJEZFinlnxjtBXww/goFJOJBAU9CrsdegwyZItNnixCFUIg4CLv4Nj1Eg/eKlfg== - dependencies: - "@babel/parser" "^7.12.0" - "@babel/types" "^7.12.0" - "@vue/compiler-core" "3.0.4" - "@vue/compiler-dom" "3.0.4" - "@vue/compiler-ssr" "3.0.4" - "@vue/shared" "3.0.4" - consolidate "^0.16.0" - estree-walker "^2.0.1" - hash-sum "^2.0.0" - lru-cache "^5.1.1" - magic-string "^0.25.7" - merge-source-map "^1.1.0" - postcss "^7.0.32" - postcss-modules "^3.2.2" - postcss-selector-parser "^6.0.4" - source-map "^0.6.1" - -"@vue/compiler-sfc@^3.0.5": +"@vue/compiler-sfc@^3.0.4", "@vue/compiler-sfc@^3.0.5": version "3.0.5" resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.0.5.tgz#3ae08e60244a72faf9598361874fb7bdb5b1d37c" integrity sha512-uOAC4X0Gx3SQ9YvDC7YMpbDvoCmPvP0afVhJoxRotDdJ+r8VO3q4hFf/2f7U62k4Vkdftp6DVni8QixrfYzs+w== @@ -1257,14 +1184,6 @@ postcss-selector-parser "^6.0.4" source-map "^0.6.1" -"@vue/compiler-ssr@3.0.4": - version "3.0.4" - resolved "https://registry.yarnpkg.com/@vue/compiler-ssr/-/compiler-ssr-3.0.4.tgz#ccbd1f55734d51d1402fad825ac102002a7a07c7" - integrity sha512-4aYWQEL4+LS4+D44K9Z7xMOWMEjBsz4Li9nMcj2rxRQ35ewK6uFPodvs6ORP60iBDSkwUFZoldFlNemQlu1BFw== - dependencies: - "@vue/compiler-dom" "3.0.4" - "@vue/shared" "3.0.4" - "@vue/compiler-ssr@3.0.5": version "3.0.5" resolved "https://registry.yarnpkg.com/@vue/compiler-ssr/-/compiler-ssr-3.0.5.tgz#7661ad891a0be948726c7f7ad1e425253c587b83" @@ -1305,11 +1224,6 @@ "@vue/compiler-ssr" "3.0.5" "@vue/shared" "3.0.5" -"@vue/shared@3.0.4": - version "3.0.4" - resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.0.4.tgz#6dc50f593bdfdeaa6183d1dbc15e2d45e7c6b8b3" - integrity sha512-Swfbz31AaMX48CpFl+YmIrqOH9MgJMTrltG9e26A4ZxYx9LjGuMV+41WnxFzS3Bc9nbrc6sDPM37G6nIT8NJSg== - "@vue/shared@3.0.5": version "3.0.5" resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.0.5.tgz#c131d88bd6713cc4d93b3bb1372edb1983225ff0" @@ -1384,9 +1298,9 @@ acorn@^7.1.1, acorn@^7.4.0: integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== acorn@^8.0.4: - version "8.0.4" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.0.4.tgz#7a3ae4191466a6984eee0fe3407a4f3aa9db8354" - integrity sha512-XNP0PqF1XD19ZlLKvB7cMmnZswW4C/03pRHgirB30uSJTaS3A3V1/P4sS3HPvFmjoriPCJQs+JDSbm4bL1TxGQ== + version "8.0.5" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.0.5.tgz#a3bfb872a74a6a7f661bc81b9849d9cac12601b7" + integrity sha512-v+DieK/HJkJOpFBETDJioequtc3PfxsWMaxIdIwujtF7FEV/MAyDQLlm6/zPvr7Mix07mLh6ccVwIsloceodlg== add-stream@^1.0.0: version "1.0.0" @@ -1418,25 +1332,35 @@ ajv@^6.10.0, ajv@^6.12.3, ajv@^6.12.4: json-schema-traverse "^0.4.1" uri-js "^4.2.2" +ajv@^7.0.2: + version "7.0.4" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-7.0.4.tgz#827e5f5ae32f5e5c1637db61f253a112229b5e2f" + integrity sha512-xzzzaqgEQfmuhbhAoqjJ8T/1okb6gAzXn/eQRNpAN1AEUoHJTNF9xCDRTtf/s3SKldtZfa+RJeTs+BQq+eZ/sw== + dependencies: + fast-deep-equal "^3.1.1" + json-schema-traverse "^1.0.0" + require-from-string "^2.0.2" + uri-js "^4.2.2" + algoliasearch@^4.0.0: - version "4.8.3" - resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-4.8.3.tgz#f76b824423e4264506fb6ba6a6709feb08ab9954" - integrity sha512-pljX9jEE2TQ3i1JayhG8afNdE8UuJg3O9c7unW6QO67yRWCKr6b0t5aKC3hSVtjt7pA2TQXLKoAISb4SHx9ozQ== - dependencies: - "@algolia/cache-browser-local-storage" "4.8.3" - "@algolia/cache-common" "4.8.3" - "@algolia/cache-in-memory" "4.8.3" - "@algolia/client-account" "4.8.3" - "@algolia/client-analytics" "4.8.3" - "@algolia/client-common" "4.8.3" - "@algolia/client-recommendation" "4.8.3" - "@algolia/client-search" "4.8.3" - "@algolia/logger-common" "4.8.3" - "@algolia/logger-console" "4.8.3" - "@algolia/requester-browser-xhr" "4.8.3" - "@algolia/requester-common" "4.8.3" - "@algolia/requester-node-http" "4.8.3" - "@algolia/transporter" "4.8.3" + version "4.8.4" + resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-4.8.4.tgz#ac2fc9335dfe06f55b9bd4faf6050ea0c8e0feea" + integrity sha512-QbXpFvBKj/QhKWE7xBoqaWOWyw7ni6W6THSuFJHOcADRrInhjFCBYjrv+YsIhv9huCepKXWpfV4UJup9BslVhQ== + dependencies: + "@algolia/cache-browser-local-storage" "4.8.4" + "@algolia/cache-common" "4.8.4" + "@algolia/cache-in-memory" "4.8.4" + "@algolia/client-account" "4.8.4" + "@algolia/client-analytics" "4.8.4" + "@algolia/client-common" "4.8.4" + "@algolia/client-recommendation" "4.8.4" + "@algolia/client-search" "4.8.4" + "@algolia/logger-common" "4.8.4" + "@algolia/logger-console" "4.8.4" + "@algolia/requester-browser-xhr" "4.8.4" + "@algolia/requester-common" "4.8.4" + "@algolia/requester-node-http" "4.8.4" + "@algolia/transporter" "4.8.4" ansi-colors@^4.1.1: version "4.1.1" @@ -1715,9 +1639,9 @@ big.js@^5.2.2: integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ== binary-extensions@^2.0.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.1.0.tgz#30fa40c9e7fe07dbc895678cd287024dea241dd9" - integrity sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ== + version "2.2.0" + resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" + integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== bl@^4.0.3: version "4.0.3" @@ -1824,12 +1748,7 @@ buffer@^5.5.0: base64-js "^1.3.1" ieee754 "^1.1.13" -builtin-modules@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.1.0.tgz#aad97c15131eb76b65b50ef208e7584cd76a7484" - integrity sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw== - -builtin-modules@^3.2.0: +builtin-modules@^3.1.0, builtin-modules@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.2.0.tgz#45d5db99e7ee5e6bc4f362e008bf917ab5049887" integrity sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA== @@ -1864,13 +1783,13 @@ cache-base@^1.0.1: union-value "^1.0.0" unset-value "^1.0.0" -call-bind@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.0.tgz#24127054bb3f9bdcb4b1fb82418186072f77b8ce" - integrity sha512-AEXsYIyyDY3MCzbwdhzG3Jx1R0J2wetQyUynn6dYHAO+bg8l1k7jwZtRv4ryryFs7EP+NDlikJlVe59jr0cM2w== +call-bind@^1.0.0, call-bind@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c" + integrity sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA== dependencies: function-bind "^1.1.1" - get-intrinsic "^1.0.0" + get-intrinsic "^1.0.2" callsites@^3.0.0: version "3.1.0" @@ -1885,15 +1804,6 @@ camelcase-keys@^2.0.0: camelcase "^2.0.0" map-obj "^1.0.0" -camelcase-keys@^4.0.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/camelcase-keys/-/camelcase-keys-4.2.0.tgz#a2aa5fb1af688758259c32c141426d78923b9b77" - integrity sha1-oqpfsa9oh1glnDLBQUJteJI7m3c= - dependencies: - camelcase "^4.1.0" - map-obj "^2.0.0" - quick-lru "^1.0.0" - camelcase-keys@^6.2.2: version "6.2.2" resolved "https://registry.yarnpkg.com/camelcase-keys/-/camelcase-keys-6.2.2.tgz#5e755d6ba51aa223ec7d3d52f25778210f9dc3c0" @@ -1908,11 +1818,6 @@ camelcase@^2.0.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-2.1.1.tgz#7c1d16d679a1bbe59ca02cacecfb011e201f5a1f" integrity sha1-fB0W1nmhu+WcoCys7PsBHiAfWh8= -camelcase@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd" - integrity sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0= - camelcase@^5.0.0, camelcase@^5.3.1: version "5.3.1" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320" @@ -1976,9 +1881,9 @@ character-parser@^2.2.0: is-regex "^1.0.3" "chokidar@>=2.0.0 <4.0.0", chokidar@^3.4.3: - version "3.4.3" - resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.4.3.tgz#c1df38231448e45ca4ac588e6c79573ba6a57d5b" - integrity sha512-DtM3g7juCXQxFVSNPNByEC2+NImtBuxQQvWlHunpJIS5Ocr0lG306cC7FCi7cEA0fzmybPUIl4txBIobk1gGOQ== + version "3.5.1" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.1.tgz#ee9ce7bbebd2b79f49f304799d5468e31e14e68a" + integrity sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw== dependencies: anymatch "~3.1.1" braces "~3.0.2" @@ -1988,7 +1893,7 @@ character-parser@^2.2.0: normalize-path "~3.0.0" readdirp "~3.5.0" optionalDependencies: - fsevents "~2.1.2" + fsevents "~2.3.1" ci-info@^1.5.0: version "1.6.0" @@ -2141,7 +2046,7 @@ commander@^2.20.0, commander@^2.7.1: resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@^6.2.0: +commander@^6.1.0, commander@^6.2.0: version "6.2.1" resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c" integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA== @@ -2279,16 +2184,16 @@ conventional-changelog-conventionalcommits@^4.5.0: q "^1.5.1" conventional-changelog-core@^4.2.1: - version "4.2.1" - resolved "https://registry.yarnpkg.com/conventional-changelog-core/-/conventional-changelog-core-4.2.1.tgz#f811ad98ab2ff080becafc61407509420c9b447d" - integrity sha512-8cH8/DEoD3e5Q6aeogdR5oaaKs0+mG6+f+Om0ZYt3PNv7Zo0sQhu4bMDRsqAF+UTekTAtP1W/C41jH/fkm8Jtw== + version "4.2.2" + resolved "https://registry.yarnpkg.com/conventional-changelog-core/-/conventional-changelog-core-4.2.2.tgz#f0897df6d53b5d63dec36b9442bd45354f8b3ce5" + integrity sha512-7pDpRUiobQDNkwHyJG7k9f6maPo9tfPzkSWbRq97GGiZqisElhnvUZSvyQH20ogfOjntB5aadvv6NNcKL1sReg== dependencies: add-stream "^1.0.0" conventional-changelog-writer "^4.0.18" conventional-commits-parser "^3.2.0" dateformat "^3.0.0" get-pkg-repo "^1.0.0" - git-raw-commits "2.0.0" + git-raw-commits "^2.0.8" git-remote-origin-url "^2.0.0" git-semver-tags "^4.1.1" lodash "^4.17.15" @@ -2341,9 +2246,9 @@ conventional-changelog-preset-loader@^2.3.4: integrity sha512-GEKRWkrSAZeTq5+YjUZOYxdHq+ci4dNwHvpaBC3+ENalzFWuCWa9EZXSuZBpkr72sMdKB+1fyDV4takK1Lf58g== conventional-changelog-writer@^4.0.18: - version "4.0.18" - resolved "https://registry.yarnpkg.com/conventional-changelog-writer/-/conventional-changelog-writer-4.0.18.tgz#10b73baa59c7befc69b360562f8b9cd19e63daf8" - integrity sha512-mAQDCKyB9HsE8Ko5cCM1Jn1AWxXPYV0v8dFPabZRkvsiWUul2YyAqbIaoMKF88Zf2ffnOPSvKhboLf3fnjo5/A== + version "4.1.0" + resolved "https://registry.yarnpkg.com/conventional-changelog-writer/-/conventional-changelog-writer-4.1.0.tgz#1ca7880b75aa28695ad33312a1f2366f4b12659f" + integrity sha512-WwKcUp7WyXYGQmkLsX4QmU42AZ1lqlvRW9mqoyiQzdD+rJWbTepdWoKJuwXTS+yq79XKnQNa93/roViPQrAQgw== dependencies: compare-func "^2.0.0" conventional-commits-filter "^2.0.7" @@ -2424,9 +2329,9 @@ copy-descriptor@^0.1.0: integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40= core-js@^3.8.2: - version "3.8.2" - resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.8.2.tgz#0a1fd6709246da9ca8eff5bb0cbd15fba9ac7044" - integrity sha512-FfApuSRgrR6G5s58casCBd9M2k+4ikuu4wbW6pJyYU7bd9zvFc9qf7vr5xmrZOhT9nn+8uwlH1oRR9jTnFoA3A== + version "3.8.3" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.8.3.tgz#c21906e1f14f3689f93abcc6e26883550dd92dd0" + integrity sha512-KPYXeVZYemC2TkNEkX/01I+7yd+nX3KddKwZ1Ww7SKWdI2wQprSgLmrTddT8nw92AjEklTsPBoSdQBhbI1bQ6Q== core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" @@ -2520,11 +2425,6 @@ csstype@^2.6.8: resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.14.tgz#004822a4050345b55ad4dcc00be1d9cf2f4296de" integrity sha512-2mSc+VEpGPblzAxyeR+vZhJKgYg0Og0nnRi7pmRXFYYxSfnOnW8A5wwQb4n4cE2nIOzqKOAzLCaEX6aBmNEv8A== -csstype@^3.0.2: - version "3.0.6" - resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.6.tgz#865d0b5833d7d8d40f4e5b8a6d76aea3de4725ef" - integrity sha512-+ZAmfyWMT7TiIlzdqJgjMb7S4f1beorDbWbsocyK4RaiqA5RTX3K14bnBWmmA9QEM0gRdsjyyrEmcyga8Zsxmw== - currently-unhandled@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea" @@ -2532,12 +2432,10 @@ currently-unhandled@^0.4.1: dependencies: array-find-index "^1.0.1" -dargs@^4.0.1: - version "4.1.0" - resolved "https://registry.yarnpkg.com/dargs/-/dargs-4.1.0.tgz#03a9dbb4b5c2f139bf14ae53f0b8a2a6a86f4e17" - integrity sha1-A6nbtLXC8Tm/FK5T8LiipqhvThc= - dependencies: - number-is-nan "^1.0.0" +dargs@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/dargs/-/dargs-7.0.0.tgz#04015c41de0bcb69ec84050f3d9be0caf8d6d5cc" + integrity sha512-2iy1EkLdlBzQGvbweYRFxmFath8+K7+AKB0TlhHWkNuH+TmovaMH/Wp7V7R4u7f4SnX3OgLsU9t1NI9ioDnUpg== dashdash@^1.12.0: version "1.14.1" @@ -2581,7 +2479,7 @@ debug@^3.2.6: dependencies: ms "^2.1.1" -decamelize-keys@^1.0.0, decamelize-keys@^1.1.0: +decamelize-keys@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/decamelize-keys/-/decamelize-keys-1.1.0.tgz#d171a87933252807eb3cb61dc1c1445d078df2d9" integrity sha1-0XGoeTMlKAfrPLYdwcFEXQeN8tk= @@ -2817,22 +2715,24 @@ error-ex@^1.2.0, error-ex@^1.3.1: is-arrayish "^0.2.1" es-abstract@^1.18.0-next.1: - version "1.18.0-next.1" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.18.0-next.1.tgz#6e3a0a4bda717e5023ab3b8e90bec36108d22c68" - integrity sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA== + version "1.18.0-next.2" + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.18.0-next.2.tgz#088101a55f0541f595e7e057199e27ddc8f3a5c2" + integrity sha512-Ih4ZMFHEtZupnUh6497zEL4y2+w8+1ljnCyaTa+adcoafI1GOvMwFlDjBLfWR7y9VLfrjRJe9ocuHY1PSR9jjw== dependencies: + call-bind "^1.0.2" es-to-primitive "^1.2.1" function-bind "^1.1.1" + get-intrinsic "^1.0.2" has "^1.0.3" has-symbols "^1.0.1" is-callable "^1.2.2" - is-negative-zero "^2.0.0" + is-negative-zero "^2.0.1" is-regex "^1.1.1" - object-inspect "^1.8.0" + object-inspect "^1.9.0" object-keys "^1.1.1" - object.assign "^4.1.1" - string.prototype.trimend "^1.0.1" - string.prototype.trimstart "^1.0.1" + object.assign "^4.1.2" + string.prototype.trimend "^1.0.3" + string.prototype.trimstart "^1.0.3" es-module-lexer@^0.3.26: version "0.3.26" @@ -2849,9 +2749,9 @@ es-to-primitive@^1.2.1: is-symbol "^1.0.2" esbuild@^0.8.34: - version "0.8.34" - resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.34.tgz#16b4ac58f74c821d2c5a8c2f0585ca96a38ab4e6" - integrity sha512-tnr0V1ooakYr1aRLXQLzCn2GVG1kBTW3FWpRyC+NgrR3ntsouVpJOlTOV0BS4YLATx3/c+x3h/uBq9lWJlUAtQ== + version "0.8.39" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.39.tgz#18b84a3d56173c55ee8f45bc6c7b5374b0a98ecb" + integrity sha512-/do5H74a5ChyeKRWfkDh3EpICXpsz6dWTtFFbotb7BlIHvWqnRrZYDb8IBubOHdEtKzuiksilRO19aBtp3/HHQ== escape-html@^1.0.3, escape-html@~1.0.3: version "1.0.3" @@ -2926,12 +2826,12 @@ eslint-visitor-keys@^2.0.0: integrity sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ== eslint@^7.15.0: - version "7.16.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.16.0.tgz#a761605bf9a7b32d24bb7cde59aeb0fd76f06092" - integrity sha512-iVWPS785RuDA4dWuhhgXTNrGxHHK3a8HLSMBgbbU59ruJDubUraXN8N5rn7kb8tG6sjg74eE0RA3YWT51eusEw== + version "7.19.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.19.0.tgz#6719621b196b5fad72e43387981314e5d0dc3f41" + integrity sha512-CGlMgJY56JZ9ZSYhJuhow61lMPPjUzWmChFya71Z/jilVos7mR/jPgaEfVGgMBY5DshbKdG8Ezb8FDCHcoMEMg== dependencies: "@babel/code-frame" "^7.0.0" - "@eslint/eslintrc" "^0.2.2" + "@eslint/eslintrc" "^0.3.0" ajv "^6.10.0" chalk "^4.0.0" cross-spawn "^7.0.2" @@ -2955,7 +2855,7 @@ eslint@^7.15.0: js-yaml "^3.13.1" json-stable-stringify-without-jsonify "^1.0.1" levn "^0.4.1" - lodash "^4.17.19" + lodash "^4.17.20" minimatch "^3.0.4" natural-compare "^1.4.0" optionator "^0.9.1" @@ -3219,9 +3119,9 @@ fast-deep-equal@^3.1.1: integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== fast-glob@^3.1.1, fast-glob@^3.2.4: - version "3.2.4" - resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.4.tgz#d20aefbf99579383e7f3cc66529158c9b98554d3" - integrity sha512-kr/Oo6PX51265qeuCYsyGypiO5uJFgBS0jksyG7FUeCyQzNwYnzrNIMR1NXfkZXsMYXYLRAHgISHBz8gQcxKHQ== + version "3.2.5" + resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.5.tgz#7939af2a656de79a4f1901903ee8adcaa7cb9661" + integrity sha512-2DtFcgT68wiTTiwZ2hNdJfcHNke9XOfnwmBRWXhmeKM8rF0TGwmC/Qto3S7RoZKp5cilZbxzO5iTNTQsJ+EeDg== dependencies: "@nodelib/fs.stat" "^2.0.2" "@nodelib/fs.walk" "^1.2.3" @@ -3241,9 +3141,9 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= fastq@^1.6.0: - version "1.10.0" - resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.10.0.tgz#74dbefccade964932cdf500473ef302719c652bb" - integrity sha512-NL2Qc5L3iQEsyYzweq7qfgy5OtXCmGzGvhElGEd/SoFWEMOEczNh5s5ocaF01HDetxz+p8ecjNPA6cZxxIHmzA== + version "1.10.1" + resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.10.1.tgz#8b8f2ac8bf3632d67afcd65dac248d5fdc45385e" + integrity sha512-AWuv6Ery3pM+dY7LYS8YIaCiQvUaos9OB1RyNgaOWnaX+Tik7Onvcsf8x8c+YtDeT0maYLniBip2hox5KtEXXA== dependencies: reusify "^1.0.4" @@ -3337,14 +3237,14 @@ flat-cache@^3.0.4: rimraf "^3.0.2" flatted@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.0.tgz#a5d06b4a8b01e3a63771daa5cb7a1903e2e57067" - integrity sha512-tW+UkmtNg/jv9CSofAKvgVcO7c2URjhTdW1ZTkcAritblu8tajiYy7YisnIflEwtKssCtOxpnBRoCB7iap0/TA== + version "3.1.1" + resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469" + integrity sha512-zAoAQiudy+r5SvnSw3KJy5os/oRJYHzrzja/tBDqrZtNhUw8bt6y8OBzMWcjWr+8liV8Eb6yOhw8WZ7VFZ5ZzA== follow-redirects@^1.0.0, follow-redirects@^1.10.0: - version "1.13.1" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.1.tgz#5f69b813376cee4fd0474a3aba835df04ab763b7" - integrity sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg== + version "1.13.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.2.tgz#dd73c8effc12728ba5cf4259d760ea5fb83e3147" + integrity sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA== for-in@^1.0.2: version "1.0.2" @@ -3383,14 +3283,14 @@ fresh@0.5.2: integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac= fs-extra@^9.0.0, fs-extra@^9.0.1: - version "9.0.1" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc" - integrity sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ== + version "9.1.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d" + integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ== dependencies: at-least-node "^1.0.0" graceful-fs "^4.2.0" jsonfile "^6.0.1" - universalify "^1.0.0" + universalify "^2.0.0" fs-extra@~7.0.1: version "7.0.1" @@ -3406,10 +3306,10 @@ fs.realpath@^1.0.0: resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= -fsevents@^2.1.2: - version "2.2.1" - resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.2.1.tgz#1fb02ded2036a8ac288d507a65962bd87b97628d" - integrity sha512-bTLYHSeC0UH/EFXS9KqWnXuOl/wHK5Z/d+ghd5AsFMYN7wIGkUCOJyzy88+wJKkZPGON8u4Z9f6U4FdgURE9qA== +fsevents@^2.1.2, fsevents@~2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.1.tgz#b209ab14c61012636c8863507edf7fb68cc54e9f" + integrity sha512-YR47Eg4hChJGAB1O3yEAOkGO+rlzutoICGqGo9EZ4lKWokzZRSyIW1QmTzqjtw8MJdj9srP869CuWw/hyzSiBw== fsevents@~2.1.2: version "2.1.3" @@ -3443,10 +3343,10 @@ get-caller-file@^2.0.1: resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== -get-intrinsic@^1.0.0: - version "1.0.2" - resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.0.2.tgz#6820da226e50b24894e08859469dc68361545d49" - integrity sha512-aeX0vrFm21ILl3+JpFFRNe9aUvp6VFZb2/CTbgLb8j75kOhvoNYjt9d8KA/tJG4gSo8nzEDedRl0h7vDmBYRVg== +get-intrinsic@^1.0.2: + version "1.1.0" + resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.1.0.tgz#892e62931e6938c8a23ea5aaebcfb67bd97da97e" + integrity sha512-M11rgtQp5GZMZzDL7jLTNxbDfurpzuau5uqRWDPvlHjfvg3TdScAZo96GLvhMjImrmR8uAt0FS2RLoMrfWGKlg== dependencies: function-bind "^1.1.1" has "^1.0.3" @@ -3514,16 +3414,16 @@ getpass@^0.1.1: dependencies: assert-plus "^1.0.0" -git-raw-commits@2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/git-raw-commits/-/git-raw-commits-2.0.0.tgz#d92addf74440c14bcc5c83ecce3fb7f8a79118b5" - integrity sha512-w4jFEJFgKXMQJ0H0ikBk2S+4KP2VEjhCvLCNqbNRQC8BgGWgLKNCO7a9K9LI+TVT7Gfoloje502sEnctibffgg== +git-raw-commits@^2.0.8: + version "2.0.10" + resolved "https://registry.yarnpkg.com/git-raw-commits/-/git-raw-commits-2.0.10.tgz#e2255ed9563b1c9c3ea6bd05806410290297bbc1" + integrity sha512-sHhX5lsbG9SOO6yXdlwgEMQ/ljIn7qMpAbJZCGfXX2fq5T8M5SrDnpYk9/4HswTildcIqatsWa91vty6VhWSaQ== dependencies: - dargs "^4.0.1" - lodash.template "^4.0.2" - meow "^4.0.0" - split2 "^2.0.0" - through2 "^2.0.0" + dargs "^7.0.0" + lodash "^4.17.15" + meow "^8.0.0" + split2 "^3.0.0" + through2 "^4.0.0" git-remote-origin-url@^2.0.0: version "2.0.0" @@ -3580,9 +3480,9 @@ globals@^12.1.0: type-fest "^0.8.1" globby@^11.0.0, globby@^11.0.1: - version "11.0.1" - resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.1.tgz#9a2bf107a068f3ffeabc49ad702c79ede8cfd357" - integrity sha512-iH9RmgwCmUJHi2z5o2l3eTtGBtXek1OYlHrbcxOYugyHLmAsZrPj43OtHThd62Buh/Vv6VyCBD2bdyWcGNQqoQ== + version "11.0.2" + resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.2.tgz#1af538b766a3b540ebfb58a32b2e2d5897321d83" + integrity sha512-2ZThXDvvV8fYFRVIxnrMQBipZQDr7MxKAmQK1vujaj9/7eF0efG7BPUKJ7jP7G5SLF37xKDXvO4S/KKLj/Z0og== dependencies: array-union "^2.1.0" dir-glob "^3.0.1" @@ -3598,7 +3498,7 @@ good-listener@^1.2.2: dependencies: delegate "^3.1.2" -graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4: +graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4: version "4.2.4" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb" integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw== @@ -3738,9 +3638,9 @@ hosted-git-info@^2.1.4: integrity sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg== hosted-git-info@^3.0.6: - version "3.0.7" - resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-3.0.7.tgz#a30727385ea85acfcee94e0aad9e368c792e036c" - integrity sha512-fWqc0IcuXs+BmE9orLDyVykAG9GJtGLGuZAAqgcckPgv5xad4AcXGIv8galtQvlwutxSlaMcdw7BUtq2EIvqCQ== + version "3.0.8" + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-3.0.8.tgz#6e35d4cc87af2c5f816e4cb9ce350ba87a3f370d" + integrity sha512-aXpmwoOhRBrw6X3j0h5RloK4x1OzsxMPyxqIHyNfSe2pypkVTZFpEiRoSipPEPlMrh0HW/XsjkJ5WgnCirpNUw== dependencies: lru-cache "^6.0.0" @@ -3910,11 +3810,6 @@ indent-string@^2.1.0: dependencies: repeating "^2.0.0" -indent-string@^3.0.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-3.2.0.tgz#4a5fd6d27cc332f37e5419a504dbb837105c9289" - integrity sha1-Sl/W0nzDMvN+VBmlBNu4NxBckok= - indent-string@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-4.0.0.tgz#624f8f4497d619b2d9768531d58f4122854d7251" @@ -3995,9 +3890,9 @@ is-buffer@^1.1.5: integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== is-callable@^1.1.4, is-callable@^1.2.2: - version "1.2.2" - resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.2.tgz#c7c6715cd22d4ddb48d3e19970223aceabb080d9" - integrity sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA== + version "1.2.3" + resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.3.tgz#8b1e0500b73a1d76c70487636f368e519de8db8e" + integrity sha512-J1DcMe8UYTBSrKezuIUTUwjXsho29693unXM2YhJUTR2txK/eG47bvNa/wipPFmZFgr/N6f1GA66dv0mEyTIyQ== is-ci@^1.0.10: version "1.2.1" @@ -4119,7 +4014,7 @@ is-module@^1.0.0: resolved "https://registry.yarnpkg.com/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591" integrity sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE= -is-negative-zero@^2.0.0: +is-negative-zero@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.1.tgz#3de746c18dda2319241a53675908d8f766f11c24" integrity sha512-2z6JzQvZRa9A2Y7xC6dQQm4FSTSTNWjKIYYTt4246eMTJmIo0Q+ZyOsU66X8lxK1AbB92dFeglPLrhwpeRKO6w== @@ -4176,10 +4071,11 @@ is-reference@^1.1.4, is-reference@^1.2.1: "@types/estree" "*" is-regex@^1.0.3, is-regex@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.1.tgz#c6f98aacc546f6cec5468a07b7b153ab564a57b9" - integrity sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg== + version "1.1.2" + resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.2.tgz#81c8ebde4db142f2cf1c53fc86d6a45788266251" + integrity sha512-axvdhb5pdhEVThqJzYXwMlVuZwC+FF2DpcOhTS+y/8jVq4trxyPgfcwIxIKiyeuLlSQYKkmUaPQJ8ZE4yNKXDg== dependencies: + call-bind "^1.0.2" has-symbols "^1.0.1" is-regexp@^1.0.0: @@ -4690,9 +4586,9 @@ jju@~1.4.0: integrity sha1-o6vicYryQaKykE+EpiWXDzia4yo= jpeg-js@^0.4.2: - version "0.4.2" - resolved "https://registry.yarnpkg.com/jpeg-js/-/jpeg-js-0.4.2.tgz#8b345b1ae4abde64c2da2fe67ea216a114ac279d" - integrity sha512-+az2gi/hvex7eLTMTlbRLOhH6P6WFdk2ITI8HJsaH2VqYO0I594zXSYEP+tf4FW+8Cy68ScDXoAsQdyQanv3sw== + version "0.4.3" + resolved "https://registry.yarnpkg.com/jpeg-js/-/jpeg-js-0.4.3.tgz#6158e09f1983ad773813704be80680550eff977b" + integrity sha512-ru1HWKek8octvUHFHvE5ZzQ1yAsJmIvRdGWvSoKV52XKyuyYA437QWDttXT8eZXDSbuMpHlLzPDZUPd6idIz+Q== js-stringify@^1.0.2: version "1.0.2" @@ -4769,6 +4665,11 @@ json-schema-traverse@^0.4.1: resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== +json-schema-traverse@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2" + integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug== + json-schema@0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13" @@ -4785,9 +4686,9 @@ json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1: integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus= json5@2.x, json5@^2.1.2: - version "2.1.3" - resolved "https://registry.yarnpkg.com/json5/-/json5-2.1.3.tgz#c9b0f7fa9233bfe5807fe66fcf3a5617ed597d43" - integrity sha512-KXPvOm8K9IJKFM0bmdn8QXh7udDh1g/giieX0NLCaMnb4hEiVFqnop2ImTXCc5e0/oHz3LTqmHGtExn5hfMkOA== + version "2.2.0" + resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.0.tgz#2dfefe720c6ba525d9ebd909950f0515316c89a3" + integrity sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA== dependencies: minimist "^1.2.5" @@ -4867,9 +4768,9 @@ kleur@^3.0.3: integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w== kolorist@^1.2.9: - version "1.2.9" - resolved "https://registry.yarnpkg.com/kolorist/-/kolorist-1.2.9.tgz#ccd5c68827c0385f0b26588321c3b6c4433dd2ab" - integrity sha512-mba6w9rkNlcMSSsGM1Xb9rgGFCDEL1APijLIkgtjsORyr9bKaSvQg/2fP8k7lwEiTh8WlMCHWREvf1ndguIKIQ== + version "1.2.10" + resolved "https://registry.yarnpkg.com/kolorist/-/kolorist-1.2.10.tgz#0f97a3f3a1dd75e980765c7cec8a1de258e580c6" + integrity sha512-S3QtGjCHyINclP4LSClgHw4gi/NxTFcSorqD9SWfrREHKtMyGfi6pyDCTbpQaqyZrMAjB4Exde8eco6kejkqQg== launch-editor-middleware@^2.2.1: version "2.2.1" @@ -4903,9 +4804,9 @@ less@^3.13.0: source-map "~0.6.0" less@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/less/-/less-4.1.0.tgz#a12708d1951239db1c9d7eaa405f1ebac9a75b8d" - integrity sha512-w1Ag/f34g7LwtQ/sMVSGWIyZx+gG9ZOAEtyxeX1fG75is6BMyC2lD5kG+1RueX7PkAvlQBm2Lf2aN2j0JbVr2A== + version "4.1.1" + resolved "https://registry.yarnpkg.com/less/-/less-4.1.1.tgz#15bf253a9939791dc690888c3ff424f3e6c7edba" + integrity sha512-w09o8tZFPThBscl5d0Ggp3RcrKIouBoQscnOMgFH3n5V3kN/CXGHNfCkRPtxJk6nKryDXaV9aHLK55RXuH4sAw== dependencies: copy-anything "^2.0.1" parse-node-version "^1.0.1" @@ -4974,9 +4875,9 @@ lint-staged@^10.5.3: stringify-object "^3.3.0" listr2@^3.2.2: - version "3.2.3" - resolved "https://registry.yarnpkg.com/listr2/-/listr2-3.2.3.tgz#ef9e0d790862f038dde8a9837be552b1adfd1c07" - integrity sha512-vUb80S2dSUi8YxXahO8/I/s29GqnOL8ozgHVLjfWQXa03BNEeS1TpBLjh2ruaqq5ufx46BRGvfymdBSuoXET5w== + version "3.3.1" + resolved "https://registry.yarnpkg.com/listr2/-/listr2-3.3.1.tgz#87b57cc0b8541fa794b814c8bcb76f1211cfbf5c" + integrity sha512-8Zoxe7s/8nNr4bJ8bdAduHD8uJce+exmMmUWTXlq0WuUdffnH3muisHPHPFtW2vvOfohIsq7FGCaguUxN/h3Iw== dependencies: chalk "^4.1.0" cli-truncate "^2.1.0" @@ -4986,6 +4887,7 @@ listr2@^3.2.2: p-map "^4.0.0" rxjs "^6.6.3" through "^2.3.8" + wrap-ansi "^7.0.0" load-json-file@^1.0.0: version "1.1.0" @@ -5037,11 +4939,6 @@ lodash-es@^4.17.20: resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.20.tgz#29f6332eefc60e849f869c264bc71126ad61e8f7" integrity sha512-JD1COMZsq8maT6mnuz1UMV0jvYD0E0aUsSOdrr1/nAG3dhqQXwRRgeW0cSqH1U43INKcqxaiVIQNOUDld7gRDA== -lodash._reinterpolate@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" - integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0= - lodash.camelcase@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" @@ -5062,37 +4959,17 @@ lodash.ismatch@^4.4.0: resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37" integrity sha1-dWy1FQyjum8RCFp4hJZF8Yj4Xzc= -lodash.memoize@4.x: - version "4.1.2" - resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" - integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4= - lodash.sortby@^4.7.0: version "4.7.0" resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg= -lodash.template@^4.0.2: - version "4.5.0" - resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.5.0.tgz#f976195cf3f347d0d5f52483569fe8031ccce8ab" - integrity sha512-84vYFxIkmidUiFxidA/KjjH9pAycqW+h980j7Fuz5qxRtO9pgB7MDFTdys1N7A5mcucRiDyEq4fusljItR1T/A== - dependencies: - lodash._reinterpolate "^3.0.0" - lodash.templatesettings "^4.0.0" - -lodash.templatesettings@^4.0.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/lodash.templatesettings/-/lodash.templatesettings-4.2.0.tgz#e481310f049d3cf6d47e912ad09313b154f0fb33" - integrity sha512-stgLz+i3Aa9mZgnjr/O+v9ruKZsPsndy7qPZOchbqk2cnTU1ZaldKK+v7m54WoKIyxiuMZTKT2H81F8BeAc3ZQ== - dependencies: - lodash._reinterpolate "^3.0.0" - lodash@4.17.19: version "4.17.19" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== -lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@~4.17.15: +lodash@4.x, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@~4.17.15: version "4.17.20" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== @@ -5195,11 +5072,6 @@ map-obj@^1.0.0, map-obj@^1.0.1: resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-1.0.1.tgz#d933ceb9205d82bdcf4886f6742bdc2b4dea146d" integrity sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0= -map-obj@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-2.0.0.tgz#a65cd29087a92598b8791257a523e021222ac1f9" - integrity sha1-plzSkIepJZi4eRJXpSPgISIqwfk= - map-obj@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-4.1.0.tgz#b91221b542734b9f14256c0132c897c5d7256fd5" @@ -5281,25 +5153,10 @@ meow@^3.3.0: redent "^1.0.0" trim-newlines "^1.0.0" -meow@^4.0.0: - version "4.0.1" - resolved "https://registry.yarnpkg.com/meow/-/meow-4.0.1.tgz#d48598f6f4b1472f35bf6317a95945ace347f975" - integrity sha512-xcSBHD5Z86zaOc+781KrupuHAzeGXSLtiAOmBsiLDiPSaYSB6hdew2ng9EBAnZ62jagG9MHAOdxpDi/lWBFJ/A== - dependencies: - camelcase-keys "^4.0.0" - decamelize-keys "^1.0.0" - loud-rejection "^1.0.0" - minimist "^1.1.3" - minimist-options "^3.0.1" - normalize-package-data "^2.3.4" - read-pkg-up "^3.0.0" - redent "^2.0.0" - trim-newlines "^2.0.0" - meow@^8.0.0: - version "8.1.0" - resolved "https://registry.yarnpkg.com/meow/-/meow-8.1.0.tgz#0fcaa267e35e4d58584b8205923df6021ddcc7ba" - integrity sha512-fNWkgM1UVMey2kf24yLiccxLihc5W+6zVus3/N0b+VfnJgxV99E9u04X6NAiKdg6ED7DAQBX5sy36NM0QJZkWA== + version "8.1.2" + resolved "https://registry.yarnpkg.com/meow/-/meow-8.1.2.tgz#bcbe45bda0ee1729d350c03cffc8395a36c4e897" + integrity sha512-r85E3NdZ+mpYk1C6RjPFEMSE+s1iZMuHtsHAqY0DT3jZczl0diWUZ8g6oU7h0M9cD2EL+PzaYghhCLzR0ZNn5Q== dependencies: "@types/minimist" "^1.2.0" camelcase-keys "^6.2.2" @@ -5367,22 +5224,17 @@ micromatch@^4.0.2: braces "^3.0.1" picomatch "^2.0.5" -mime-db@1.44.0: - version "1.44.0" - resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.44.0.tgz#fa11c5eb0aca1334b4233cb4d52f10c5a6272f92" - integrity sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg== - -"mime-db@>= 1.43.0 < 2": +mime-db@1.45.0, "mime-db@>= 1.43.0 < 2": version "1.45.0" resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.45.0.tgz#cceeda21ccd7c3a745eba2decd55d4b73e7879ea" integrity sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w== mime-types@^2.1.12, mime-types@~2.1.19, mime-types@~2.1.24: - version "2.1.27" - resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.27.tgz#47949f98e279ea53119f5722e0f34e529bec009f" - integrity sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w== + version "2.1.28" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.28.tgz#1160c4757eab2c5363888e005273ecf79d2a0ecd" + integrity sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ== dependencies: - mime-db "1.44.0" + mime-db "1.45.0" mime@1.6.0, mime@^1.4.1: version "1.6.0" @@ -5390,9 +5242,9 @@ mime@1.6.0, mime@^1.4.1: integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== mime@^2.3.1, mime@^2.4.6, mime@^2.4.7: - version "2.4.7" - resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.7.tgz#962aed9be0ed19c91fd7dc2ece5d7f4e89a90d74" - integrity sha512-dhNd1uA2u397uQk3Nv5LM4lm93WYDUXFn3Fu291FJerns4jyTudqhIWe4W04YLy7Uk1tm1Ore04NpjRvQp/NPA== + version "2.5.0" + resolved "https://registry.yarnpkg.com/mime/-/mime-2.5.0.tgz#2b4af934401779806ee98026bb42e8c1ae1876b1" + integrity sha512-ft3WayFSFUVBuJj7BMLKAQcSlItKtfjsKDDsii3rqFDAZ7t11zRe8ASw/GlmivGwVUYtwkQrxiGGpL6gFvB0ag== mimic-fn@^2.1.0: version "2.1.0" @@ -5428,14 +5280,6 @@ minimist-options@4.1.0: is-plain-obj "^1.1.0" kind-of "^6.0.3" -minimist-options@^3.0.1: - version "3.0.2" - resolved "https://registry.yarnpkg.com/minimist-options/-/minimist-options-3.0.2.tgz#fba4c8191339e13ecf4d61beb03f070103f3d954" - integrity sha512-FyBrT/d0d4+uiZRbqznPXqw3IpZZG3gl3wKWiX784FycUKVwBt0uLBFkQrtE4tZOrgo78nZp2jnKz3L65T5LdQ== - dependencies: - arrify "^1.0.1" - is-plain-obj "^1.1.0" - minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.5: version "1.2.5" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" @@ -5643,11 +5487,6 @@ npm-run-path@^4.0.0, npm-run-path@^4.0.1: dependencies: path-key "^3.0.0" -number-is-nan@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" - integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0= - nwsapi@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.0.tgz#204879a9e3d068ff2a55139c2c772780681a38b7" @@ -5672,7 +5511,7 @@ object-copy@^0.1.0: define-property "^0.2.5" kind-of "^3.0.3" -object-inspect@^1.8.0: +object-inspect@^1.9.0: version "1.9.0" resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.9.0.tgz#c90521d74e1127b67266ded3394ad6116986533a" integrity sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw== @@ -5689,7 +5528,7 @@ object-visit@^1.0.0: dependencies: isobject "^3.0.0" -object.assign@^4.1.1: +object.assign@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.2.tgz#0ed54a342eceb37b38ff76eb831a0e788cb63940" integrity sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ== @@ -5746,9 +5585,9 @@ open-in-editor@^2.2.0: os-homedir "~1.0.2" open@^7.3.0: - version "7.3.0" - resolved "https://registry.yarnpkg.com/open/-/open-7.3.0.tgz#45461fdee46444f3645b6e14eb3ca94b82e1be69" - integrity sha512-mgLwQIx2F/ye9SmbrUkurZCnkoXyXyu9EbHtJZrICjVAJfyMArdHp3KkixGdZx1ZHFPNIwl0DDM1dFFqXbTLZw== + version "7.4.0" + resolved "https://registry.yarnpkg.com/open/-/open-7.4.0.tgz#ad95b98f871d9acb0ec8fecc557082cc9986626b" + integrity sha512-PGoBCX/lclIWlpS/R2PQuIR4NJoXh6X5AwVzE7WXnWRGvHg7+4TBCgsujUgiPpm0K1y4qvQeWnCWVTpTKZBtvA== dependencies: is-docker "^2.0.0" is-wsl "^2.1.1" @@ -5778,9 +5617,9 @@ optionator@^0.9.1: word-wrap "^1.2.3" ora@^5.1.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/ora/-/ora-5.2.0.tgz#de10bfd2d15514384af45f3fa9d9b1aaf344fda1" - integrity sha512-+wG2v8TUU8EgzPHun1k/n45pXquQ9fHnbXVetl9rRgO6kjZszGGbraF3XPTIdgeA+s1lbRjSEftAnyT0w8ZMvQ== + version "5.3.0" + resolved "https://registry.yarnpkg.com/ora/-/ora-5.3.0.tgz#fb832899d3a1372fe71c8b2c534bbfe74961bb6f" + integrity sha512-zAKMgGXUim0Jyd6CXK9lraBnD3H5yPGBPPOkC23a2BG6hsm4Zu6OQSjQuEtV0BHDf4aKHcUFvJiGRrFuW3MG8g== dependencies: bl "^4.0.3" chalk "^4.1.0" @@ -5884,9 +5723,9 @@ parse-json@^4.0.0: json-parse-better-errors "^1.0.1" parse-json@^5.0.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-5.1.0.tgz#f96088cdf24a8faa9aea9a009f2d9d942c999646" - integrity sha512-+mi/lmVVNKFNVyLXV31ERiy2CY5E1/F6QtJFEzoChPRwwngMNXRDQ9GJ5WdE2Z2P4AujsOi0/+2qHID68KwfIQ== + version "5.2.0" + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-5.2.0.tgz#c76fc66dee54231c962b22bcc8a72cf2f99753cd" + integrity sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg== dependencies: "@babel/code-frame" "^7.0.0" error-ex "^1.3.1" @@ -6058,10 +5897,11 @@ pkg-dir@^4.2.0: find-up "^4.0.0" playwright-chromium@^1.7.0: - version "1.7.0" - resolved "https://registry.yarnpkg.com/playwright-chromium/-/playwright-chromium-1.7.0.tgz#d22b0f879d4ce753a42528f2357b756c4ef00402" - integrity sha512-m88/bTwguxseNq2IIKwnKcFRG4DSV+sVJpbC7VnGB+cVmrPVx9pMOCSlqN5ldHrMR9hmhMea96b/BcTReCHpKg== + version "1.8.0" + resolved "https://registry.yarnpkg.com/playwright-chromium/-/playwright-chromium-1.8.0.tgz#5e68b07ee27e5fe132f758c40a5ee37a0e501288" + integrity sha512-DMyWmFPXkW0Tm5yBx2pV3m5F8qBSk29+DuZd21liwnG8qNZX43zEY1QpsS51zWPYFgi+nHkRr343GycyAoSUzQ== dependencies: + commander "^6.1.0" debug "^4.1.1" extract-zip "^2.0.1" https-proxy-agent "^5.0.0" @@ -6238,18 +6078,18 @@ postcss@^7.0.14, postcss@^7.0.32, postcss@^7.0.5, postcss@^7.0.6: supports-color "^6.1.0" postcss@^8.2.1: - version "8.2.1" - resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.2.1.tgz#eabc5557c4558059b9d9e5b15bce7ffa9089c2a8" - integrity sha512-RhsqOOAQzTgh1UB/IZdca7F9WDb7SUCR2Vnv1x7DbvuuggQIpoDwjK+q0rzoPffhYvWNKX5JSwS4so4K3UC6vA== + version "8.2.4" + resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.2.4.tgz#20a98a39cf303d15129c2865a9ec37eda0031d04" + integrity sha512-kRFftRoExRVXZlwUuay9iC824qmXPcQQVzAjbCCgjpXnkdMCJYBu2gTwAaFBzv8ewND6O8xFb3aELmEkh9zTzg== dependencies: colorette "^1.2.1" nanoid "^3.1.20" source-map "^0.6.1" preact@^10.0.0: - version "10.5.8" - resolved "https://registry.yarnpkg.com/preact/-/preact-10.5.8.tgz#96e71e2caadf60b5ff901f0e4772a46ba0756336" - integrity sha512-8d0FfBX3O0ay34i15mTckXicSsvaQLemPUByXTyfQUxDeFqZhbtnftVZMNqX3zEJLHcy1bqRu9t+V4GqJtG1TQ== + version "10.5.12" + resolved "https://registry.yarnpkg.com/preact/-/preact-10.5.12.tgz#6a8ee8bf40a695c505df9abebacd924e4dd37704" + integrity sha512-r6siDkuD36oszwlCkcqDJCAKBQxGoeEGytw2DGMD5A/GGdu5Tymw+N2OBXwvOLxg6d1FeY8MgMV3cc5aVQo4Cg== prelude-ls@^1.2.1: version "1.2.1" @@ -6277,9 +6117,9 @@ pretty-format@^26.0.0, pretty-format@^26.6.2: react-is "^17.0.1" prismjs@^1.20.0: - version "1.22.0" - resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.22.0.tgz#73c3400afc58a823dd7eed023f8e1ce9fd8977fa" - integrity sha512-lLJ/Wt9yy0AiSYBf212kK3mM5L8ycwlyTlSxHBAneXLR0nzFMlZ5y7riFPF3E33zXOF2IH95xdY5jIyZbM9z/w== + version "1.23.0" + resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.23.0.tgz#d3b3967f7d72440690497652a9d40ff046067f33" + integrity sha512-c29LVsqOaLbBHuIbsTxaKENh1N2EQBOHaWv7gkHN4dgRbxSREqDnDbtFJYdpPauS4YCplMSNCABQ6Eeor69bAA== optionalDependencies: clipboard "^2.0.0" @@ -6318,11 +6158,11 @@ prop-types@^15.6.2: react-is "^16.8.1" proper-lockfile@^4.1.1: - version "4.1.1" - resolved "https://registry.yarnpkg.com/proper-lockfile/-/proper-lockfile-4.1.1.tgz#284cf9db9e30a90e647afad69deb7cb06881262c" - integrity sha512-1w6rxXodisVpn7QYvLk706mzprPTAPCYAqxMvctmPN3ekuRk/kuGkGc82pangZiAt4R3lwSuUzheTTn0/Yb7Zg== + version "4.1.2" + resolved "https://registry.yarnpkg.com/proper-lockfile/-/proper-lockfile-4.1.2.tgz#c8b9de2af6b2f1601067f98e01ac66baa223141f" + integrity sha512-TjNPblN4BwAWMXU8s9AEz4JmQxnD1NNL7bNOY/AKUzyamc379FWASUhc/K1pL2noVb+XmZKLL68cjzLsiOAMaA== dependencies: - graceful-fs "^4.1.11" + graceful-fs "^4.2.4" retry "^0.12.0" signal-exit "^3.0.2" @@ -6485,11 +6325,6 @@ qs@~6.5.2: resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA== -quick-lru@^1.0.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-1.1.0.tgz#4360b17c61136ad38078397ff11416e186dcfbb8" - integrity sha1-Q2CxfGETatOAeDl/8RQW4Ybc+7g= - quick-lru@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-4.0.1.tgz#5b8878f113a58217848c6482026c73e1ba57727f" @@ -6639,7 +6474,7 @@ read-pkg@^5.2.0: parse-json "^5.0.0" type-fest "^0.6.0" -readable-stream@3, readable-stream@^3.4.0: +readable-stream@3, readable-stream@^3.0.0, readable-stream@^3.4.0: version "3.6.0" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== @@ -6683,14 +6518,6 @@ redent@^1.0.0: indent-string "^2.1.0" strip-indent "^1.0.1" -redent@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/redent/-/redent-2.0.0.tgz#c1b2007b42d57eb1389079b3c8333639d5e1ccaa" - integrity sha1-wbIAe0LVfrE4kHmzyDM2OdXhzKo= - dependencies: - indent-string "^3.0.0" - strip-indent "^2.0.0" - redent@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/redent/-/redent-3.0.0.tgz#e557b7998316bb53c9f1f56fa626352c6963059f" @@ -6786,6 +6613,11 @@ require-directory@^2.1.1: resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I= +require-from-string@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909" + integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw== + require-main-filename@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" @@ -6836,9 +6668,9 @@ resolve-url@^0.2.1: integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo= resolve.exports@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/resolve.exports/-/resolve.exports-1.0.1.tgz#9aff14e2ed43ea40bbdc2f83b9a2465b1f093325" - integrity sha512-rV7NC8yDnV2wSg3nB7Faoje+oQk7/7cuxEq4cgOR81mULtAWvHGODowzxojq4FIftNA0FRtnn5v5a+F4aTiSzA== + version "1.0.2" + resolved "https://registry.yarnpkg.com/resolve.exports/-/resolve.exports-1.0.2.tgz#98c82ba8a4d3f9fcc32cbfa6f950b803d77b6c21" + integrity sha512-1+PDdTR3xrGWB/NzXLkzS1+PQlJ+BOR2baBGJSVat4HasiY1mnkyAQws3FUTmBDB79oK54QFaDM8Ig9nUtJwvQ== resolve@^1.1.6, resolve@^1.1.7, resolve@^1.10.0, resolve@^1.10.1, resolve@^1.15.1, resolve@^1.17.0, resolve@^1.18.1, resolve@^1.19.0: version "1.19.0" @@ -6911,11 +6743,11 @@ rollup-plugin-license@^2.2.0: spdx-satisfies "5.0.0" rollup@^2.35.1: - version "2.35.1" - resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.35.1.tgz#e6bc8d10893556a638066f89e8c97f422d03968c" - integrity sha512-q5KxEyWpprAIcainhVy6HfRttD9kutQpHbeqDTWnqAFNJotiojetK6uqmcydNMymBEtC4I8bCYR+J3mTMqeaUA== + version "2.38.4" + resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.38.4.tgz#1b84ea8728c73b1a00a6a6e9c630ec8c3fe48cea" + integrity sha512-B0LcJhjiwKkTl79aGVF/u5KdzsH8IylVfV56Ut6c9ouWLJcUK17T83aZBetNYSnZtXf2OHD4+2PbmRW+Fp5ulg== optionalDependencies: - fsevents "~2.1.2" + fsevents "~2.3.1" rsvp@^4.8.4: version "4.8.5" @@ -6971,17 +6803,10 @@ sane@^4.0.3: minimist "^1.1.1" walker "~1.0.5" -sass@^1.30.0: - version "1.30.0" - resolved "https://registry.yarnpkg.com/sass/-/sass-1.30.0.tgz#60bbbbaf76ba10117e61c6c24f00161c3d60610e" - integrity sha512-26EUhOXRLaUY7+mWuRFqGeGGNmhB1vblpTENO1Z7mAzzIZeVxZr9EZoaY1kyGLFWdSOZxRMAufiN2mkbO6dAlw== - dependencies: - chokidar ">=2.0.0 <4.0.0" - -sass@^1.32.5: - version "1.32.5" - resolved "https://registry.yarnpkg.com/sass/-/sass-1.32.5.tgz#2882d22ad5748c05fa9bff6c3b0ffbc4f4b9e1dc" - integrity sha512-kU1yJ5zUAmPxr7f3q0YXTAd1oZjSR1g3tYyv+xu0HZSl5JiNOaE987eiz7wCUvbm4I9fGWGU2TgApTtcP4GMNQ== +sass@^1.30.0, sass@^1.32.5: + version "1.32.6" + resolved "https://registry.yarnpkg.com/sass/-/sass-1.32.6.tgz#e3646c8325cd97ff75a8a15226007f3ccd221393" + integrity sha512-1bcDHDcSqeFtMr0JXI3xc/CXX6c4p0wHHivJdru8W7waM7a1WjKMm4m/Z5sY7CbVw4Whi2Chpcw6DFfSWwGLzQ== dependencies: chokidar ">=2.0.0 <4.0.0" @@ -7145,9 +6970,9 @@ signal-exit@^3.0.0, signal-exit@^3.0.2, signal-exit@^3.0.3: integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA== sirv@^1.0.10: - version "1.0.10" - resolved "https://registry.yarnpkg.com/sirv/-/sirv-1.0.10.tgz#3e591f5a9ae2520f50d5830f5fae38d97e7be194" - integrity sha512-H5EZCoZaggEUQy8ocKsF7WAToGuZhjJlLvM3XOef46CbdIgbNeQ1p32N1PCuCjkVYwrAVOSMacN6CXXgIzuspg== + version "1.0.11" + resolved "https://registry.yarnpkg.com/sirv/-/sirv-1.0.11.tgz#81c19a29202048507d6ec0d8ba8910fda52eb5a4" + integrity sha512-SR36i3/LSWja7AJNRBz4fF/Xjpn7lQFI30tZ434dIy+bitLYSP+ZEenHg36i23V2SGEz+kqjksg0uOGZ5LPiqg== dependencies: "@polka/url" "^1.0.0-next.9" mime "^2.3.1" @@ -7231,9 +7056,9 @@ source-map-support@^0.5.19, source-map-support@^0.5.6, source-map-support@~0.5.1 source-map "^0.6.0" source-map-url@^0.4.0: - version "0.4.0" - resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3" - integrity sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM= + version "0.4.1" + resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.1.tgz#0af66605a745a5a2f91cf1bbf8a7afbc283dec56" + integrity sha512-cPiFOTLUKvJFIg4SKVScy4ilPPW6rFgMgfuZJPNoDuMs3nC1HbMUycBoJw77xFIp6z1UJQJOfx6C9GMH80DiTw== source-map@^0.5.0, source-map@^0.5.6: version "0.5.7" @@ -7325,6 +7150,13 @@ split2@^2.0.0: dependencies: through2 "^2.0.2" +split2@^3.0.0: + version "3.2.2" + resolved "https://registry.yarnpkg.com/split2/-/split2-3.2.2.tgz#bf2cf2a37d838312c249c89206fd7a17dd12365f" + integrity sha512-9NThjpgZnifTkJpzTZ7Eue85S49QwpNhZTq6GRJwObb6jnLFNGB7Qm73V5HewTROPyxD0C29xqmaI68bQtV+hg== + dependencies: + readable-stream "^3.0.0" + split@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/split/-/split-1.0.1.tgz#605bd9be303aa59fb35f9229fbea0ddec9ea07d9" @@ -7413,7 +7245,7 @@ string.prototype.padend@^3.0.0: define-properties "^1.1.3" es-abstract "^1.18.0-next.1" -string.prototype.trimend@^1.0.1: +string.prototype.trimend@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.3.tgz#a22bd53cca5c7cf44d7c9d5c732118873d6cd18b" integrity sha512-ayH0pB+uf0U28CtjlLvL7NaohvR1amUvVZk+y3DYb0Ey2PUV5zPkkKy9+U1ndVEIXO8hNg18eIv9Jntbii+dKw== @@ -7421,7 +7253,7 @@ string.prototype.trimend@^1.0.1: call-bind "^1.0.0" define-properties "^1.1.3" -string.prototype.trimstart@^1.0.1: +string.prototype.trimstart@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/string.prototype.trimstart/-/string.prototype.trimstart-1.0.3.tgz#9b4cb590e123bb36564401d59824298de50fd5aa" integrity sha512-oBIBUy5lea5tt0ovtOFiEQaBkoBBkyJhZXzJYrSmDo5IUUqbOPvVezuRs/agBIdZ2p2Eo1FD6bD9USyBLfl3xg== @@ -7572,11 +7404,11 @@ systemjs@^6.8.3: integrity sha512-UcTY+FEA1B7e+bpJk1TI+a9Na6LG7wFEqW7ED16cLqLuQfI/9Ri0rsXm3tKlIgNoHyLHZycjdAOijzNbzelgwA== table@^6.0.4: - version "6.0.4" - resolved "https://registry.yarnpkg.com/table/-/table-6.0.4.tgz#c523dd182177e926c723eb20e1b341238188aa0d" - integrity sha512-sBT4xRLdALd+NFBvwOz8bw4b15htyythha+q+DVZqy2RS08PPC8O2sZFgJYEY7bJvbCFKccs+WIZ/cd+xxTWCw== + version "6.0.7" + resolved "https://registry.yarnpkg.com/table/-/table-6.0.7.tgz#e45897ffbcc1bcf9e8a87bf420f2c9e5a7a52a34" + integrity sha512-rxZevLGTUzWna/qBLObOe16kB2RTnnbhciwgPbMMlazz1yZGVEgnZK762xyVdVznhqxrfCeBMmMkgOOaPwjH7g== dependencies: - ajv "^6.12.4" + ajv "^7.0.2" lodash "^4.17.20" slice-ansi "^4.0.0" string-width "^4.2.0" @@ -7761,11 +7593,6 @@ trim-newlines@^1.0.0: resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613" integrity sha1-WIeWa7WCpFA6QetST301ARgVphM= -trim-newlines@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-2.0.0.tgz#b403d0b91be50c331dfc4b82eeceb22c3de16d20" - integrity sha1-tAPQuRvlDDMd/EuC7s6yLD3hbSA= - trim-newlines@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-3.0.0.tgz#79726304a6a898aa8373427298d54c2ee8b1cb30" @@ -7784,9 +7611,9 @@ trouter@^2.0.1: matchit "^1.0.0" ts-jest@^26.4.4: - version "26.4.4" - resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.4.4.tgz#61f13fb21ab400853c532270e52cc0ed7e502c49" - integrity sha512-3lFWKbLxJm34QxyVNNCgXX1u4o/RV0myvA2y2Bxm46iGIjKlaY0own9gIckbjZJPn+WaJEnfPPJ20HHGpoq4yg== + version "26.5.0" + resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.5.0.tgz#3e3417d91bc40178a6716d7dacc5b0505835aa21" + integrity sha512-Ya4IQgvIFNa2Mgq52KaO8yBw2W8tWp61Ecl66VjF0f5JaV8u50nGoptHVILOPGoI7SDnShmEqnYQEmyHdQ+56g== dependencies: "@types/jest" "26.x" bs-logger "0.x" @@ -7794,7 +7621,7 @@ ts-jest@^26.4.4: fast-json-stable-stringify "2.x" jest-util "^26.1.0" json5 "2.x" - lodash.memoize "4.x" + lodash "4.x" make-error "1.x" mkdirp "1.x" semver "7.x" @@ -7806,14 +7633,14 @@ tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0: integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== tslib@^2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.3.tgz#8e0741ac45fc0c226e58a17bfc3e64b9bc6ca61c" - integrity sha512-uZtkfKblCEQtZKBF6EBXVZeQNl82yqtDQdv+eck8u7tdPxjLu2/lp5/uPW+um2tpuxINHWy3GhiccY7QgEaVHQ== + version "2.1.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a" + integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A== tsutils@^3.17.1: - version "3.17.1" - resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759" - integrity sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g== + version "3.20.0" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.20.0.tgz#ea03ea45462e146b53d70ce0893de453ff24f698" + integrity sha512-RYbuQuvkhuqVeXweWT3tJLKOEJ/UUw9GjNEZGWdrLLlM+611o1gwLHBpxoFJKKl25fLprp2eVthtKs5JOrNeXg== dependencies: tslib "^1.8.1" @@ -7887,25 +7714,20 @@ typedarray-to-buffer@^3.1.5: version "0.0.0" uid "" -typescript@^4.1.2: +typescript@^4.1.2, typescript@~4.1.3: version "4.1.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7" integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg== -typescript@~4.0.5: - version "4.0.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389" - integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ== - uc.micro@^1.0.1, uc.micro@^1.0.5: version "1.0.6" resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac" integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA== uglify-js@^3.1.4: - version "3.12.3" - resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.12.3.tgz#bb26c4abe0e68c55e9776bca9bed99a4df73facf" - integrity sha512-feZzR+kIcSVuLi3s/0x0b2Tx4Iokwqt+8PJM7yRHKuldg4MLdam4TCFeICv+lgDtuYiCtdmrtIP+uN9LWvDasw== + version "3.12.6" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.12.6.tgz#f884584fcc42e10bca70db5cb32e8625c2c42535" + integrity sha512-aqWHe3DfQmZUDGWBbabZ2eQnJlQd1fKlMUu7gV+MiTuDzdgDw31bI3wA2jLLsV/hNcDP26IfyEgSVoft5+0SVw== union-value@^1.0.0: version "1.0.1" @@ -7927,11 +7749,6 @@ universalify@^0.1.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== -universalify@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d" - integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug== - universalify@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" @@ -7951,9 +7768,9 @@ unset-value@^1.0.0: isobject "^3.0.0" uri-js@^4.2.2: - version "4.4.0" - resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.0.tgz#aa714261de793e8a82347a7bcc9ce74e86f28602" - integrity sha512-B0yRTzYdUCCn9n+F4+Gh4yIDtMQcaJsmYBDsTSG8g/OejKBodLQ2IHfN3bM7jUsRXndopT7OIXWdYqc1fjmV6g== + version "4.4.1" + resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" + integrity sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg== dependencies: punycode "^2.1.0" @@ -7993,9 +7810,9 @@ v8-compile-cache@^2.0.3: integrity sha512-gTpR5XQNKFwOd4clxfnhaqvfqMpqEwr4tOtCyz4MtYZX2JYhfr1JvBFKdS+7K/9rfpZR3VLX+YWBbKoxCgS43Q== v8-to-istanbul@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-7.0.0.tgz#b4fe00e35649ef7785a9b7fcebcea05f37c332fc" - integrity sha512-fLL2rFuQpMtm9r8hrAV2apXX/WqHJ6+IC4/eQVdMDGBUgH/YMV4Gv3duk3kjmyg6uiQWBAA9nJwue4iJUOkHeA== + version "7.1.0" + resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-7.1.0.tgz#5b95cef45c0f83217ec79f8fc7ee1c8b486aee07" + integrity sha512-uXUVqNUCLa0AH1vuVxzi+MI4RfxEOKt9pBgKwHbgH7st8Kv2P1m+jvWNnektzBh5QShF3ODgKmUFCf38LnVz1g== dependencies: "@types/istanbul-lib-coverage" "^2.0.1" convert-source-map "^1.6.0" @@ -8034,9 +7851,9 @@ verror@1.10.0: extsprintf "^1.2.0" vitepress@^0.11.4: - version "0.11.4" - resolved "https://registry.yarnpkg.com/vitepress/-/vitepress-0.11.4.tgz#0ca9c406d0f0f10cf7baa4117184d05890bc75dc" - integrity sha512-WvofLFpPxgaaHeAF72uv2XHKtuQ7ouwJu2n3wuDyAOwU1BeyL9YpnVQPBw/L7LAjApJe9bdbK7om0J/hloXN0g== + version "0.11.5" + resolved "https://registry.yarnpkg.com/vitepress/-/vitepress-0.11.5.tgz#1973058ff50fab8702438361c5a5f1c1df336be1" + integrity sha512-QElAGDxXcvn3G1UrW6VKWX6hd748+07cU1mMH5/gRN/QDdXTVAyt5Ulxmo+IXAmrZQhN5nvvY7jCWWJIDNXQOA== dependencies: "@docsearch/css" "^1.0.0-alpha.28" "@docsearch/js" "^1.0.0-alpha.28" @@ -8063,7 +7880,7 @@ vitepress@^0.11.4: prismjs "^1.20.0" sirv "^1.0.10" slash "^3.0.0" - vite "^2.0.0-beta.32" + vite "^2.0.0-beta.56" vue "^3.0.5" void-elements@^3.1.0: @@ -8086,9 +7903,9 @@ vue@^3.0.5: "@vue/shared" "3.0.5" vuex@^4.0.0-rc.2: - version "4.0.0-rc.2" - resolved "https://registry.yarnpkg.com/vuex/-/vuex-4.0.0-rc.2.tgz#3681c84eb6f5171b039edaa17cc78105e20724f3" - integrity sha512-HCPzYGea1xL7fMpDoMiHKujC1Bi/HM9LS5ML0Kv55zQtZJvOl0Lq7eWvJoen+SI4Lf7p9V5AqcVsoLPXNBywjg== + version "4.0.0" + resolved "https://registry.yarnpkg.com/vuex/-/vuex-4.0.0.tgz#ac877aa76a9c45368c979471e461b520d38e6cf5" + integrity sha512-56VPujlHscP5q/e7Jlpqc40sja4vOhC4uJD1llBCWolVI8ND4+VzisDVkUMl+z5y0MpIImW6HjhNc+ZvuizgOw== w3c-hr-time@^1.0.2: version "1.0.2" @@ -8197,6 +8014,15 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" @@ -8213,9 +8039,9 @@ write-file-atomic@^3.0.0: typedarray-to-buffer "^3.1.5" ws@^7.2.3, ws@^7.3.1, ws@^7.4.1: - version "7.4.1" - resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.1.tgz#a333be02696bd0e54cea0434e21dcc8a9ac294bb" - integrity sha512-pTsP8UAfhy3sk1lSk/O/s4tjD0CRwvMnzvwr4OKGX7ZvqZtUyx4KIJB5JWbkykPoc55tixMGgTNoh3k4FkNGFQ== + version "7.4.3" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.3.tgz#1f9643de34a543b8edb124bdcbc457ae55a6e5cd" + integrity sha512-hr6vCR76GsossIRsr8OLR9acVVm1jyfEWvhbNjtgPOrfvAlKzvyeg/P6r8RuDjRyrcQoPQT7K0DGEPc7Ae6jzA== xml-name-validator@^3.0.0: version "3.0.0" From 71f1c637c2ee8b79fd8f6696c5498034be3ddc39 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 2 Feb 2021 21:23:27 -0500 Subject: [PATCH 457/514] chore: do not clearline if not logging --- packages/vite/src/node/plugins/reporter.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/vite/src/node/plugins/reporter.ts b/packages/vite/src/node/plugins/reporter.ts index db98f8e0fc592e..87dd486a788bb1 100644 --- a/packages/vite/src/node/plugins/reporter.ts +++ b/packages/vite/src/node/plugins/reporter.ts @@ -92,13 +92,15 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin { }, buildEnd() { - if (tty) { - process.stdout.clearLine(0) - process.stdout.cursorTo(0) + if (shouldLogInfo) { + if (tty) { + process.stdout.clearLine(0) + process.stdout.cursorTo(0) + } + config.logger.info( + `${chalk.green(`✓`)} ${transformedCount} modules transformed.` + ) } - config.logger.info( - `${chalk.green(`✓`)} ${transformedCount} modules transformed.` - ) }, renderStart() { @@ -121,7 +123,7 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin { }, generateBundle() { - if (tty) { + if (shouldLogInfo && tty) { process.stdout.clearLine(0) process.stdout.cursorTo(0) } From a139fbaf587bf3233077fe7d32666a3c972fb803 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 2 Feb 2021 22:02:45 -0500 Subject: [PATCH 458/514] docs: update optimizeDeps options --- docs/config/index.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index b6e3cf53306b37..d991af70167a94 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -488,14 +488,22 @@ export default ({ command, mode }) => { - **Related:** [Dependency Pre-Bundling](/guide/dep-pre-bundling) +### optimizeDeps.entries + +- **Type:** `string | string[]` + + By default, Vite will crawl your index.html to detect dependencies that need to be pre-bundled. If build.rollupOptions.input is specified, Vite will crawl those entry points instead. + + If neither of these fit your needs, you can specify custom entries using this option - the value should be a [fast-glob pattern](https://github.com/mrmlnc/fast-glob#basic-syntax) or array of patterns that are relative from vite project root. This will overwrite default entries inference. + ### optimizeDeps.exclude -- **Type:** `string | RegExp | (string | RegExp)[]` +- **Type:** `string[]` Dependencies to exclude from pre-bundling. ### optimizeDeps.include -- **Type:** `string | RegExp | (string | RegExp)[]` +- **Type:** `string[]` - By default, linked packages not inside `node_modules` are not pre-bundled. Use this option to force a linked package to be pre-bundled. + By default, linked packages not inside `node_modules` are not pre-bundled. Use this option to force a linked package to be pre-bundled. \ No newline at end of file From 9cdf424c17f89d87fa3a703ff1dbcf05697466a9 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 2 Feb 2021 22:53:11 -0500 Subject: [PATCH 459/514] refactor: improve ssr examples --- packages/playground/ssr-react/prerender.js | 3 +++ packages/playground/ssr-react/server.js | 28 ++++++++------------ packages/playground/ssr-vue/prerender.js | 3 +++ packages/playground/ssr-vue/server.js | 30 +++++++++------------- 4 files changed, 29 insertions(+), 35 deletions(-) diff --git a/packages/playground/ssr-react/prerender.js b/packages/playground/ssr-react/prerender.js index 61abf3bab848e0..ac88ef632ec6f5 100644 --- a/packages/playground/ssr-react/prerender.js +++ b/packages/playground/ssr-react/prerender.js @@ -1,3 +1,6 @@ +// Pre-render the app into static HTML. +// run `yarn generate` and then `dist/static` can be served as a static site. + const fs = require('fs') const path = require('path') diff --git a/packages/playground/ssr-react/server.js b/packages/playground/ssr-react/server.js index ad2becc96c68b8..4a6a653a3a781b 100644 --- a/packages/playground/ssr-react/server.js +++ b/packages/playground/ssr-react/server.js @@ -9,20 +9,12 @@ async function createServer( root = process.cwd(), isProd = process.env.NODE_ENV === 'production' ) { - const toAbsolute = (p) => path.resolve(__dirname, p) + const resolve = (p) => path.resolve(__dirname, p) const indexProd = isProd - ? fs.readFileSync(toAbsolute('dist/client/index.html'), 'utf-8') + ? fs.readFileSync(resolve('dist/client/index.html'), 'utf-8') : '' - function getIndexTemplate() { - if (isProd) { - return indexProd - } - // during dev, inject vite client + always read fresh index.html - return fs.readFileSync(toAbsolute('index.html'), 'utf-8') - } - const app = express() /** @@ -42,7 +34,7 @@ async function createServer( } else { app.use(require('compression')()) app.use( - require('serve-static')(toAbsolute('dist/client'), { + require('serve-static')(resolve('dist/client'), { index: false }) ) @@ -51,16 +43,18 @@ async function createServer( app.use('*', async (req, res) => { try { const url = req.originalUrl - let template = getIndexTemplate() + + let template, render if (!isProd) { + // always read fresh template in dev + template = fs.readFileSync(resolve('index.html'), 'utf-8') template = await vite.transformIndexHtml(url, template) + render = (await vite.ssrLoadModule('/src/entry-server.jsx')).render + } else { + template = indexProd + render = require('./dist/server/entry-server.js').render } - const { render } = isProd - ? // @ts-ignore - require('./dist/server/entry-server.js') - : await vite.ssrLoadModule('/src/entry-server.jsx') - const context = {} const appHtml = render(url, context) diff --git a/packages/playground/ssr-vue/prerender.js b/packages/playground/ssr-vue/prerender.js index bf4079048f2f80..5b47f6d2657080 100644 --- a/packages/playground/ssr-vue/prerender.js +++ b/packages/playground/ssr-vue/prerender.js @@ -1,3 +1,6 @@ +// Pre-render the app into static HTML. +// run `yarn generate` and then `dist/static` can be served as a static site. + const fs = require('fs') const path = require('path') diff --git a/packages/playground/ssr-vue/server.js b/packages/playground/ssr-vue/server.js index 3f898ee15c1be2..969ab6dacee01a 100644 --- a/packages/playground/ssr-vue/server.js +++ b/packages/playground/ssr-vue/server.js @@ -9,10 +9,10 @@ async function createServer( root = process.cwd(), isProd = process.env.NODE_ENV === 'production' ) { - const toAbsolute = (p) => path.resolve(__dirname, p) + const resolve = (p) => path.resolve(__dirname, p) const indexProd = isProd - ? fs.readFileSync(toAbsolute('dist/client/index.html'), 'utf-8') + ? fs.readFileSync(resolve('dist/client/index.html'), 'utf-8') : '' const manifest = isProd @@ -20,14 +20,6 @@ async function createServer( require('./dist/client/ssr-manifest.json') : {} - function getIndexTemplate() { - if (isProd) { - return indexProd - } - // during dev, inject vite client + always read fresh index.html - return fs.readFileSync(toAbsolute('index.html'), 'utf-8') - } - const app = express() /** @@ -47,7 +39,7 @@ async function createServer( } else { app.use(require('compression')()) app.use( - require('serve-static')(toAbsolute('dist/client'), { + require('serve-static')(resolve('dist/client'), { index: false }) ) @@ -56,16 +48,18 @@ async function createServer( app.use('*', async (req, res) => { try { const url = req.originalUrl - let template = getIndexTemplate() + + let template, render if (!isProd) { + // always read fresh template in dev + template = fs.readFileSync(resolve('index.html'), 'utf-8') template = await vite.transformIndexHtml(url, template) + render = (await vite.ssrLoadModule('/src/entry-server.js')).render + } else { + template = indexProd + render = require('./dist/server/entry-server.js').render } - const { render } = isProd - ? // @ts-ignore - require('./dist/server/entry-server.js') - : await vite.ssrLoadModule('/src/entry-server.js') - const [appHtml, preloadLinks] = await render(url, manifest) const html = template @@ -74,7 +68,7 @@ async function createServer( res.status(200).set({ 'Content-Type': 'text/html' }).end(html) } catch (e) { - !isProd && vite.ssrFixStacktrace(e) + vite && vite.ssrFixStacktrace(e) console.log(e.stack) res.status(500).end(e.stack) } From 424a95e5a134be7c40c3b39680593b45944ec5fd Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 2 Feb 2021 22:53:18 -0500 Subject: [PATCH 460/514] docs: ssr guide --- docs/.vitepress/config.js | 4 + docs/config/index.md | 32 ++++- docs/guide/api-javascript.md | 63 ++++------ docs/guide/ssr.md | 224 ++++++++++++++++++++++++++++++++++- 4 files changed, 283 insertions(+), 40 deletions(-) diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index 7d37e59b27d4c1..2e6300ee6485d5 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -77,6 +77,10 @@ module.exports = { text: 'Env Variables and Modes', link: '/guide/env-and-mode' }, + { + text: 'Server-Side Rendering (SSR)', + link: '/guide/ssr' + }, { text: 'Backend Integration', link: '/guide/backend-integration' diff --git a/docs/config/index.md b/docs/config/index.md index d991af70167a94..8e3d7a02a4120d 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -484,6 +484,20 @@ export default ({ command, mode }) => { By default, Vite will empty the `outDir` on build if it is inside project root. It will emit a warning if `outDir` is outside of root to avoid accidentially removing important files. You can explicitly set this option to suppress the warning. This is also available via command line as `--emptyOutDir`. +### build.brotliSize + +- **Type:** `boolean` +- **Default:** `true` + + Enable/disable brotli-compressed size reporting. Compressing large output files can be slow, so disabling this may increase build performance for large projects. + +### build.chunkSizeWarningLimit + +- **Type:** `number` +- **Default:** `500` + + Limit for chunk size warnings (in kbs). + ## Dep Optimization Options - **Related:** [Dependency Pre-Bundling](/guide/dep-pre-bundling) @@ -506,4 +520,20 @@ export default ({ command, mode }) => { - **Type:** `string[]` - By default, linked packages not inside `node_modules` are not pre-bundled. Use this option to force a linked package to be pre-bundled. \ No newline at end of file + By default, linked packages not inside `node_modules` are not pre-bundled. Use this option to force a linked package to be pre-bundled. + +## SSR Options + +- **Related:** [SSR Externals Heuristics](/guide/ssr#externals-heuristics) + +### ssr.external + +- **Type:** `string[]` + + Force externalize dependencies for SSR. + +### ssr.noExternal + +- **Type:** `string[]` + + Prevent listed dependencies from being externalized for SSR. diff --git a/docs/guide/api-javascript.md b/docs/guide/api-javascript.md index 56933907be594f..b6c1af43218229 100644 --- a/docs/guide/api-javascript.md +++ b/docs/guide/api-javascript.md @@ -28,44 +28,6 @@ const { createServer } = require('vite') })() ``` -### Using the Vite Server as a Middleware - -Vite can be used as a middleware in an existing raw Node.js http server or frameworks that are comaptible with the `(req, res, next) => {}` style middlewares. For example with `express`: - -```js -const vite = require('vite') -const express = require('express') - -;(async () => { - const app = express() - - // create vite dev server in middleware mode - // so vite creates the hmr websocket server on its own. - // the ws server will be listening at port 24678 by default, and can be - // configured via server.hmr.port - const viteServer = await vite.createServer({ - server: { - middlewareMode: true - } - }) - - // use vite's connect instance as middleware - app.use(viteServer.app) - - app.use('*', (req, res) => { - // serve custom index.html - }) - - app.listen(3000) -})() -``` - -Note that in middleware mode, Vite will not be serving `index.html` - that is now the responsibility of the parent server. When serving the HTML, make sure to include a link to Vite's dev client: - -```html - -``` - ## `InlineConfig` The `InlineConfig` interface extends `UserConfig` with additional properties: @@ -124,6 +86,31 @@ interface ViteDevServer { options?: EsbuildTransformOptions, inMap?: object ): Promise + /** + * Apply vite built-in HTML transforms and any plugin HTML transforms. + */ + transformIndexHtml(url: string, html: string): Promise + /** + * Util for transforming a file with esbuild. + * Can be useful for certain plugins. + */ + transformWithEsbuild( + code: string, + filename: string, + options?: EsbuildTransformOptions, + inMap?: object + ): Promise + /** + * Load a given URL as an instantiated module for SSR. + */ + ssrLoadModule( + url: string, + options?: { isolated?: boolean } + ): Promise> + /** + * Fix ssr error stacktrace + */ + ssrFixStacktrace(e: Error): void /** * Start the server. */ diff --git a/docs/guide/ssr.md b/docs/guide/ssr.md index 70fc03eafbb257..7451c9154f8325 100644 --- a/docs/guide/ssr.md +++ b/docs/guide/ssr.md @@ -1,3 +1,225 @@ # Server-Side Rendering -Vite has server-side rendering built-in. \ No newline at end of file +Vite provides built-in support for server-side rendering (SSR). + +:::tip Note +SSR specifically refers to front-end frameworks (for example React, Preact, Vue, and Svelte) that support running the same application in Node.js, pre-rendering it to HTML, and finally hydrating it on the client. If you are looking for integration with traditional server-side frameworks, check out the [Backend Integration guide](./backend-integration) instead. + +The following guide also assumes prior experience working with SSR in your framework of choice, and will only focus on Vite-specific integration details. +::: + +## Example Projects + +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) + +## Source Structure + +A typical SSR application will have the following source file structure: + +``` +- index.html +- src/ + - main.js # exports env-agnostic (universal) app code + - entry-client.js # mounts the app to a DOM element + - entry-server.js # renders the app using framework's SSR API +``` + +The `index.html` will need to reference `entry-client.js` and include a placeholder where the server-rendered markup should be injected: + +```html +
+ +``` + +You can use any placeholder you prefer instead of ``, as long as it can be precisely replaced. + +:::tip +If you need to perform conditional logic based on SSR vs. client, you can use `import.meta.env.SSR`. This is statically replaced during build so it will allow tree-shaking of unused branches. +::: + +## Setting Up the Dev Server + +When building an SSR app, you likely want to have full control over your main server and decouple Vite from the production environment. It therefore recommended to use Vite in middleware mode. Here is an example with [express](https://expressjs.com/): + +**server.js** + +```js{18-20} +const fs = require('fs') +const path = require('path') +const express = require('express') +const { createServer: createViteServer } = require('vite') + +async function createServer() { + const app = express() + + // Create vite server in middleware mode. This disables Vite's own HTML + // serving logic and let's the parent server take control. + const vite = await createViteServer({ + server: { middlewareMode: true } + }) + // use vite's connect instance as middleware + app.use(vite.middlewares) + + app.use('*', async (req, res) => { + // serve index.html - we will tackle this next + }) + + app.listen(3000) +} + +createServer() +``` + +Here `vite` is an instance of [ViteDevServer](./api-javascript#vitedevserver). `vite.middlewares` is a [Connect](https://github.com/senchalabs/connect) instance which can be used as a middleware in any connect-compatible Node.js framework. + +The next step is implementing the `*` handler to serve server-rendered HTML: + +```js +app.use('*', async (req, res) => { + const url = req.originalUrl + + try { + // 1. Read index.html + let template = fs.readFileSync( + path.resolve(__dirname, 'index.html'), + 'utf-8' + ) + + // 2. Apply vite HTML transforms. This injects the vite HMR client, and + // also applies HTML transforms from Vite plugins, e.g. global preambles + // from @vitejs/plugin-react-refresh + template = await vite.transformIndexHtml(url, template) + + // 3. Load the server entry. vite.ssrLoadModule automatically transforms + // your ESM source code to be usable in Node.js! There is no bundling + // required, and provides efficient invalidation similar to HMR. + const { render } = await vite.ssrLoadModule('/src/entry-server.js') + + // 4. render the app HTML. This assumes entry-server.js's exported `render` + // function calls appropriate framework SSR APIs, + // e.g. ReacDOMServer.renderToString() + const appHtml = await render(url) + + // 5. Inject the app-rendered HTML into the template. + const html = template.replace(``, appHtml) + + // 6. Send the rendered HTML back. + res.status(200).set({ 'Content-Type': 'text/html' }).end(html) + } catch (e) { + // If an error is caught, let vite fix the stracktrace so it maps back to + // your actual source code. + vite.ssrFixStacktrace(e) + console.error(e) + res.status(500).end(e.message) + } +}) +``` + +The `dev` script in `package.json` should also be changed to use the server script instead: + +```diff + "scripts": { +- "dev": "vite" ++ "dev": "node server" + } +``` + +## Building for Production + +To ship an SSR project for production, we need to: + +1. Produce a client build as normal; +2. Produce an SSR build, which can be directly loaded via `require()` so that we don't have to go through Vite's `ssrLoadModule`; + +Our scripts in `package.json` will look like this: + +```json +{ + "scripts": { + "dev": "node server", + "build:client": "vite build --outDir dist/client", + "build:server": "vite build --outDir dist/server --ssr src/entry-server.js " + } +} +``` + +Note the `--ssr` flag which indicates this is an SSR build. It should also specify the SSR entry. + +Then, in `server.js` we need to add some production specific logic by checking `process.env.NODE_ENV`: + +- Instead of reading the root `index.html`, use the `dist/client/index.html` as template instead, since it contains the correct asset links to the client build. + +- Instead of `await vite.ssrLoadModule('/src/entry-server.js')`, use `require('./dist/server/entry-server.js')` instead (this file is the result of the SSR build). + +- 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. + +### Generating Preload Directives + +> This section is Vue-specific. + +`@vitejs/plugin-vue` automatically registers component module IDs that are instantiated during a request render to the associated Vue SSR context. This information can be used to infer async chunks and assets that should be preloaded for a given route. + +In order to leverage this, add the `--ssrManifest` flag to the client build script (Yes, the SSR manifest is generated from the client build because we want to map module IDs to client files): + +```diff +- "build:client": "vite build --outDir dist/client", ++ "build:client": "vite build --outDir dist/client --ssrManifest", +``` + +This will generate a `dist/client/ssr-manifest.json` file that contains mappings of module IDs to their associated chunks and asset files. + +Then, in `src/entry-server.js`: + +```js +const ctx = {} +const html = await renderToString(app, ctx) +// ctx.modules is now a Set of module IDs that were used during the render +``` + +We need to now read and pass the manifest to the `render` function exported by `src/entry-server.js`, and now we have 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. + +## 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 is also known as 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. + +## Externals Heuristics + +Many dependencies ship both ESM and CommonJS files. When running SSR, a dependency that provides CommonJS builds can be "externalized" from Vite's SSR transform / module system to speed up both dev and build. For example, instead of pulling in the pre-bundled ESM version of React and then transforming it back to be Node.js-compatible, it is more efficient to simply `require('react')` instead. It also greatly improves the speed of the SSR bundle build. + +Vite performs automated SSR externalization based on the following heuristics: + +- If a dependency's resolved ESM entry point and its default Node entry point are different, its default Node entry is probably a CommonJS build that can be externalized. For example, `vue` will be automatically externalized because it ships both ESM and CommonJS builds. + +- Otherwise, Vite will check whether the package's entry point contains valid ESM syntax - if not, the package is likely CommonJS and will be externalized. As an example, `react-dom` will be automatically externalized because it only specifies a single entry which is in CommonJS format. + +If this heuristics leads to errors, you can manually adjust SSR externals using `ssr.external` and `ssr.noExternal` config options. + +In the future, this heuristics will likely improve to also externalize dependencies that ship Node-compatible ESM builds (and `import()` them during SSR module load). + +## SSR-specific Plugin Logic + +Some frameworks such as Vue or Svelte compiles components into different formats based on client vs. SSR. To support conditional transforms, Vite passes an additional `ssr` argument to the following plugin hooks: + +- `resolveId` +- `load` +- `transform` + +**Example:** + +```js +export function mySSRPlugin() { + return { + name: 'my-ssr', + transform(code, id, ssr) { + if (ssr) { + // perform ssr-specific transform... + } + } + } +} +``` \ No newline at end of file From a88781e555cd5b4969f56009dcb13a1854cced67 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 2 Feb 2021 22:57:16 -0500 Subject: [PATCH 461/514] chore: remove temp file --- test.js | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 test.js diff --git a/test.js b/test.js deleted file mode 100644 index 88d8a486d841fc..00000000000000 --- a/test.js +++ /dev/null @@ -1,16 +0,0 @@ -const { - transformForSSR -} = require('./packages/vite/dist/node/server/ssrTransform') - -;(async () => { - const { code } = await transformForSSR(` - import { createApp as _createApp } from 'vue' - import App from './App.vue' - - export function createApp() { - return _createApp(App) - } - `) - - console.log(code) -})() From 94a804233682581c0f920ed5c0d42aa85ea3f163 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 2 Feb 2021 22:57:33 -0500 Subject: [PATCH 462/514] fix: only close if http server has listened fix #1855 --- packages/vite/src/node/server/index.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 628731b2541617..8c973d20402f0f 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -600,6 +600,7 @@ function createSeverCloseFn(server: http.Server | null) { return () => {} } + let hasListened = false const openSockets = new Set() server.on('connection', (socket) => { @@ -609,15 +610,23 @@ function createSeverCloseFn(server: http.Server | null) { }) }) + server.once('listening', () => { + hasListened = true + }) + return () => new Promise((resolve, reject) => { openSockets.forEach((s) => s.destroy()) - server.close((err) => { - if (err) { - reject(err) - } else { - resolve() - } - }) + if (hasListened) { + server.close((err) => { + if (err) { + reject(err) + } else { + resolve() + } + }) + } else { + resolve() + } }) } From da365475b157576427a92f8cfecaacf36e20b97e Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 2 Feb 2021 22:59:25 -0500 Subject: [PATCH 463/514] chore: bump test wait retires --- packages/playground/testUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playground/testUtils.ts b/packages/playground/testUtils.ts index 7ae4281b0569ce..027506c75f735f 100644 --- a/packages/playground/testUtils.ts +++ b/packages/playground/testUtils.ts @@ -103,7 +103,7 @@ export async function untilUpdated( expected: string ) { if (isBuild) return - const maxTries = process.env.CI ? 100 : 20 + const maxTries = process.env.CI ? 100 : 50 for (let tries = 0; tries < maxTries; tries++) { const actual = (await poll()) || '' if (actual.indexOf(expected) > -1 || tries === maxTries - 1) { From 8ad7ecd1029bdc0b47e55877db10ac630829c7e5 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 3 Feb 2021 09:28:44 -0500 Subject: [PATCH 464/514] fix: do not shim process with actual object otherwise it breaks conditional process check code --- packages/vite/src/client/env.ts | 5 +---- packages/vite/src/node/plugins/clientInjections.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/client/env.ts b/packages/vite/src/client/env.ts index 21837467c28d33..2bd8cfc284e7d1 100644 --- a/packages/vite/src/client/env.ts +++ b/packages/vite/src/client/env.ts @@ -1,10 +1,7 @@ declare const __MODE__: string declare const __DEFINES__: Record + const that = new Function('return this')() -// shim process -;(that as any).process = (that as any).process || {} -;(that as any).process.env = (that as any).process.env || {} -;(that as any).process.env.NODE_ENV = __MODE__ // assign defines const defines = __DEFINES__ diff --git a/packages/vite/src/node/plugins/clientInjections.ts b/packages/vite/src/node/plugins/clientInjections.ts index 24d8a834d2f776..b935c74f6cfe4c 100644 --- a/packages/vite/src/node/plugins/clientInjections.ts +++ b/packages/vite/src/node/plugins/clientInjections.ts @@ -6,6 +6,7 @@ import { normalizePath } from '../utils' // ids in transform are normalized to unix style const normalizedClientEntry = normalizePath(CLIENT_ENTRY) +const normalizedEnvEntry = normalizePath(ENV_ENTRY) /** * some values used by the client needs to be dynamically injected by the server @@ -15,7 +16,7 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin { return { name: 'vite:client-inject', transform(code, id) { - if (id === normalizedClientEntry || normalizePath(ENV_ENTRY)) { + if (id === normalizedClientEntry || id === normalizedEnvEntry) { let options = config.server.hmr options = options && typeof options !== 'boolean' ? options : {} const host = options.host || null @@ -49,6 +50,12 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin { .replace(`__HMR_PORT__`, JSON.stringify(port)) .replace(`__HMR_TIMEOUT__`, JSON.stringify(timeout)) .replace(`__HMR_ENABLE_OVERLAY__`, JSON.stringify(overlay)) + } else if (code.includes('process.env.NODE_ENV')) { + // replace process.env.NODE_ENV + return code.replace( + /\bprocess\.env\.NODE_ENV\b/g, + JSON.stringify(config.mode) + ) } } } From cd13ef009abd23d2676dda470638c81895034a91 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 3 Feb 2021 09:32:52 -0500 Subject: [PATCH 465/514] fix: consistently use mode for NODE_ENV in deps --- packages/vite/src/node/optimizer/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index d4da4e03a588dc..c7d154cfaa0f27 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -222,7 +222,7 @@ export async function optimizeDeps( treeShaking: 'ignore-annotations', metafile: esbuildMetaPath, define: { - 'process.env.NODE_ENV': '"development"' + 'process.env.NODE_ENV': JSON.stringify(config.mode) }, plugins: [esbuildDepPlugin(flatIdDeps, flatIdToExports, config)] }) From 501bef21e0c80e3ee22bed926fd13f1fac575d6e Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Wed, 3 Feb 2021 22:35:11 +0800 Subject: [PATCH 466/514] docs: update plugin-react-refresh README.md for middleware mode (#1856) [skip ci] --- packages/plugin-react-refresh/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/plugin-react-refresh/README.md b/packages/plugin-react-refresh/README.md index 62429502336c79..cb73bfbf86d217 100644 --- a/packages/plugin-react-refresh/README.md +++ b/packages/plugin-react-refresh/README.md @@ -35,3 +35,24 @@ export default { - This option only enables the plugin to parse these syntax - it does not perform any transpilation since this plugin is dev-only. - If you wish to transpile the syntax for production, you will need to configure the transform separately using [@rollup/plugin-babel](https://github.com/rollup/plugins/tree/master/packages/babel) as a build-only plugin. + +## Middleware Mode Notes + +When Vite is launched in **Middleware Mode**, you need to make sure your entry `index.html` file is transformed with `ViteDevServer.transformIndexHtml`. Otherwise, you may get an error prompting `Uncaught Error: vite-plugin-react can't detect preamble. Something is wrong.` + +To mitigate this issue, you can explicitly transform your `index.html` like this when configuring your express server: + +```ts +app.get('/', async (req, res, next) => { + try { + let html = fs.readFileSync( + path.resolve(root, 'index.html'), + 'utf-8' + ); + html = await viteServer.transformIndexHtml(req.url, html); + res.send(html); + } catch (e) { + return next(e); + } +}); +``` From 000ee62ef41e4964d1002ab7862303cec0419c47 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 3 Feb 2021 10:16:35 -0500 Subject: [PATCH 467/514] fix(css): hoist external @import in concatenated css fix #1845 --- packages/vite/src/node/plugins/css.ts | 83 ++++++++++++++++++--------- 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index adbc9ebdff76e1..475b46ef296d84 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -23,12 +23,6 @@ import { import { dataToEsm } from '@rollup/pluginutils' import chalk from 'chalk' import { CLIENT_PUBLIC_PATH } from '../constants' -import { - ProcessOptions, - Result, - Plugin as PostcssPlugin, - PluginCreator -} from 'postcss' import { ResolveFn, ViteDevServer } from '../' import { getAssetFilename, @@ -38,12 +32,8 @@ import { urlToBuiltUrl } from './asset' import MagicString from 'magic-string' -import type { - ImporterReturnType, - Options as SassOptions, - Result as SassResult, - render as sassRender -} from 'sass' +import * as Postcss from 'postcss' +import * as Sass from 'sass' import type Less from 'less' // const debug = createDebugger('vite:css') @@ -56,8 +46,8 @@ export interface CSSOptions { preprocessorOptions?: Record postcss?: | string - | (ProcessOptions & { - plugins?: PostcssPlugin[] + | (Postcss.ProcessOptions & { + plugins?: Postcss.Plugin[] }) } @@ -262,7 +252,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { // resolve asset URL placeholders to their built file URLs and perform // minification if necessary - const process = async ( + const processChunkCSS = async ( css: string, { inlined, @@ -286,6 +276,11 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { return `./${path.posix.basename(filename)}` } }) + // only external @imports should exist at this point - and they need to + // be hoisted to the top of the CSS chunk per spec (#1845) + if (css.includes('@import')) { + css = await hoistAtImports(css) + } if (minify && config.build.minify) { css = await minifyCSS(css, config) } @@ -298,7 +293,10 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { pureCssChunks.add(chunk.fileName) } if (opts.format === 'es') { - chunkCSS = await process(chunkCSS, { inlined: false, minify: true }) + chunkCSS = await processChunkCSS(chunkCSS, { + inlined: false, + minify: true + }) // emit corresponding css file const fileHandle = this.emitFile({ name: chunk.name + '.css', @@ -311,7 +309,10 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { ) } else if (!config.build.ssr) { // legacy build, inline css - chunkCSS = await process(chunkCSS, { inlined: true, minify: true }) + chunkCSS = await processChunkCSS(chunkCSS, { + inlined: true, + minify: true + }) const style = `__vite_style__` const injectCode = `var ${style} = document.createElement('style');` + @@ -330,7 +331,10 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } } else { // non-split extracted CSS will be minified togethter - chunkCSS = await process(chunkCSS, { inlined: false, minify: false }) + chunkCSS = await processChunkCSS(chunkCSS, { + inlined: false, + minify: false + }) outputToExtractedCSSMap.set( opts, (outputToExtractedCSSMap.get(opts) || '') + chunkCSS @@ -457,7 +461,7 @@ async function compileCSS( ): Promise<{ code: string map?: SourceMap - ast?: Result + ast?: Postcss.Result modules?: Record deps?: Set }> { @@ -546,7 +550,7 @@ async function compileCSS( postcssPlugins.push( UrlRewritePostcssPlugin({ replacer: urlReplacer - }) as PostcssPlugin + }) as Postcss.Plugin ) if (isModule) { @@ -608,8 +612,8 @@ async function compileCSS( } interface PostCSSConfigResult { - options: ProcessOptions - plugins: PostcssPlugin[] + options: Postcss.ProcessOptions + plugins: Postcss.Plugin[] } let cachedPostcssConfig: PostCSSConfigResult | null | undefined @@ -650,7 +654,7 @@ type CssUrlReplacer = ( ) => string | Promise const cssUrlRE = /url\(\s*('[^']+'|"[^"]+"|[^'")]+)\s*\)/ -const UrlRewritePostcssPlugin: PluginCreator<{ +const UrlRewritePostcssPlugin: Postcss.PluginCreator<{ replacer: CssUrlReplacer }> = (opts) => { if (!opts) { @@ -728,6 +732,31 @@ async function minifyCSS(css: string, config: ResolvedConfig) { return res.styles } +// #1845 +// CSS @import can only appear at top of the file. We need to hoist all @import +// to top when multiple files are concatenated. +async function hoistAtImports(css: string) { + const postcss = await import('postcss') + return (await postcss.default([AtImportHoistPlugin]).process(css)).css +} + +const AtImportHoistPlugin: Postcss.PluginCreator = () => { + return { + postcssPlugin: 'vite-hoist-at-imports', + Once(root) { + const imports: Postcss.AtRule[] = [] + root.walkAtRules((rule) => { + if (rule.name === 'import') { + // record in reverse so that can simply prepend to preserve order + imports.unshift(rule) + } + }) + imports.forEach((i) => root.prepend(i)) + } + } +} +AtImportHoistPlugin.postcss = true + // Preprocessor support. This logic is largely replicated from @vue/compiler-sfc type PreprocessLang = 'less' | 'sass' | 'scss' | 'styl' | 'stylus' @@ -761,8 +790,8 @@ function loadPreprocessor(lang: PreprocessLang) { // .scss/.sass processor const scss: StylePreprocessor = async (source, options, resolvers) => { - const render = loadPreprocessor('sass').render as typeof sassRender - const finalOptions: SassOptions = { + const render = loadPreprocessor('sass').render as typeof Sass.render + const finalOptions: Sass.Options = { ...options, data: getSource(source, options.filename, options.additionalData), file: options.filename, @@ -779,7 +808,7 @@ const scss: StylePreprocessor = async (source, options, resolvers) => { } try { - const result = await new Promise((resolve, reject) => { + const result = await new Promise((resolve, reject) => { render(finalOptions, (err, res) => { if (err) { reject(err) @@ -820,7 +849,7 @@ const sass: StylePreprocessor = (source, options, aliasResolver) => async function rebaseUrls( file: string, rootFile: string -): Promise { +): Promise { file = path.resolve(file) // ensure os-specific flashes // in the same dir, no need to rebase const fileDir = path.dirname(file) From b065ede3cca3bc72d3bb3e6f9cd945d1b36ccb42 Mon Sep 17 00:00:00 2001 From: Marcel Lindig Date: Wed, 3 Feb 2021 16:20:44 +0100 Subject: [PATCH 468/514] fix(vite): close server and exit if stdin ends (#1857) --- packages/vite/src/node/server/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 8c973d20402f0f..b79c932dd5059c 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -337,13 +337,20 @@ export async function createServer( server.transformIndexHtml = createDevHtmlTransformFn(server) - process.once('SIGTERM', async () => { + const exitProcess = async () => { try { await server.close() } finally { process.exit(0) } - }) + } + + process.once('SIGTERM', exitProcess) + + if (!process.stdin.isTTY) { + process.stdin.on('end', exitProcess) + process.stdin.resume() + } watcher.on('change', async (file) => { file = normalizePath(file) From cb7b6becd0a566c58aca6cc47ae785ac2c4b4482 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 3 Feb 2021 11:07:43 -0500 Subject: [PATCH 469/514] fix(css): respect sass partial import convention --- packages/playground/css/__tests__/css.spec.ts | 7 ++++ packages/playground/css/index.html | 3 +- packages/playground/css/nested/_partial.scss | 3 ++ packages/playground/css/sass.scss | 1 + packages/vite/src/node/config.ts | 4 +- packages/vite/src/node/plugins/css.ts | 3 +- packages/vite/src/node/plugins/resolve.ts | 40 +++++++++++++++---- 7 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 packages/playground/css/nested/_partial.scss diff --git a/packages/playground/css/__tests__/css.spec.ts b/packages/playground/css/__tests__/css.spec.ts index 2782563d4a911f..e9f86683428cdb 100644 --- a/packages/playground/css/__tests__/css.spec.ts +++ b/packages/playground/css/__tests__/css.spec.ts @@ -56,10 +56,12 @@ test('postcss config', async () => { test('sass', async () => { const imported = await page.$('.sass') const atImport = await page.$('.sass-at-import') + const partialImport = await page.$('.sass-partial') expect(await getColor(imported)).toBe('orange') expect(await getColor(atImport)).toBe('olive') expect(await getBg(atImport)).toMatch(isBuild ? /base64/ : '/nested/icon.png') + expect(await getColor(partialImport)).toBe('orchid') editFile('sass.scss', (code) => code.replace('color: $injectedColor', 'color: red') @@ -70,6 +72,11 @@ test('sass', async () => { code.replace('color: olive', 'color: blue') ) await untilUpdated(() => getColor(atImport), 'blue') + + editFile('nested/_partial.scss', (code) => + code.replace('color: orchid', 'color: green') + ) + await untilUpdated(() => getColor(partialImport), 'green') }) test('less', async () => { diff --git a/packages/playground/css/index.html b/packages/playground/css/index.html index 2333f5cb4d4313..2904cc0511b1c1 100644 --- a/packages/playground/css/index.html +++ b/packages/playground/css/index.html @@ -19,8 +19,9 @@

CSS

SASS: This should be orange

- @import from SASS: This should be olive and have bg image + @import from SASS _index: This should be olive and have bg image

+

@import from SASS _partial: This should be orchid

Imported SASS string:


 
diff --git a/packages/playground/css/nested/_partial.scss b/packages/playground/css/nested/_partial.scss
new file mode 100644
index 00000000000000..9642a0e61adfbb
--- /dev/null
+++ b/packages/playground/css/nested/_partial.scss
@@ -0,0 +1,3 @@
+.sass-partial {
+  color: orchid;
+}
diff --git a/packages/playground/css/sass.scss b/packages/playground/css/sass.scss
index c5794e5db29930..c622dad413bc64 100644
--- a/packages/playground/css/sass.scss
+++ b/packages/playground/css/sass.scss
@@ -1,4 +1,5 @@
 @import '@/nested'; // alias + custom index resolving -> /nested/_index.scss
+@import '@/nested/partial'; // sass convention: omitting leading _ for partials
 
 .sass {
   /* injected via vite.config.js */
diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts
index 34fafb3d827333..e892ae469aaed3 100644
--- a/packages/vite/src/node/config.ts
+++ b/packages/vite/src/node/config.ts
@@ -168,7 +168,8 @@ export type ResolvedConfig = Readonly<
     logger: Logger
     createResolver: (options?: {
       asSrc?: boolean
-      tryIndex?: boolean | string
+      tryIndex?: boolean
+      tryPrefix?: string
       extensions?: string[]
       relativeFirst?: boolean
     }) => ResolveFn
@@ -333,6 +334,7 @@ export async function resolveConfig(
                 asSrc: options?.asSrc ?? true,
                 relativeFirst: options?.relativeFirst ?? false,
                 tryIndex: options?.tryIndex ?? true,
+                tryPrefix: options?.tryPrefix,
                 extensions: options?.extensions
               })
             ]
diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts
index 475b46ef296d84..3216362b9cfb93 100644
--- a/packages/vite/src/node/plugins/css.ts
+++ b/packages/vite/src/node/plugins/css.ts
@@ -433,7 +433,8 @@ function createCSSResolvers(config: ResolvedConfig): CSSResolvers {
         sassResolve ||
         (sassResolve = config.createResolver({
           extensions: ['.scss', '.sass', '.css'],
-          tryIndex: '_index',
+          tryIndex: true,
+          tryPrefix: '_',
           relativeFirst: true
         }))
       )
diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts
index d31aa07b76fc54..63628d5b55080c 100644
--- a/packages/vite/src/node/plugins/resolve.ts
+++ b/packages/vite/src/node/plugins/resolve.ts
@@ -61,7 +61,8 @@ interface ResolveOptions {
    * - resolving bare imports from optimized deps
    */
   asSrc: boolean
-  tryIndex?: boolean | string
+  tryIndex?: boolean
+  tryPrefix?: string
   relativeFirst?: boolean
   extensions?: string[]
   dedupe?: string[]
@@ -74,6 +75,7 @@ export function resolvePlugin({
   asSrc,
   dedupe,
   tryIndex = true,
+  tryPrefix,
   relativeFirst = false,
   extensions = SUPPORTED_EXTS
 }: ResolveOptions): Plugin {
@@ -81,7 +83,7 @@ export function resolvePlugin({
 
   // curried fs resovle
   const fsResolve = (fsPath: string) =>
-    tryFsResolve(fsPath, isProduction, tryIndex, extensions)
+    tryFsResolve(fsPath, isProduction, tryIndex, tryPrefix, extensions)
 
   return {
     name: 'vite:resolve',
@@ -235,16 +237,27 @@ export function resolvePlugin({
   }
 }
 
+// resolve extensions
 export function tryFsResolve(
   fsPath: string,
   isProduction: boolean,
   tryIndex: boolean | string = true,
+  tryPrefix: string | undefined = undefined,
   extensions = SUPPORTED_EXTS
 ): string | undefined {
   const [file, q] = fsPath.split(`?`, 2)
   const query = q ? `?${q}` : ``
   let res: string | undefined
-  if ((res = tryResolveFile(file, query, isProduction, tryIndex, extensions))) {
+  if (
+    (res = tryResolveFile(
+      file,
+      query,
+      isProduction,
+      tryIndex,
+      tryPrefix,
+      extensions
+    ))
+  ) {
     return res
   }
   for (const ext of extensions) {
@@ -253,7 +266,8 @@ export function tryFsResolve(
         file + ext,
         query,
         isProduction,
-        tryIndex,
+        false,
+        tryPrefix,
         extensions
       ))
     ) {
@@ -267,6 +281,7 @@ function tryResolveFile(
   query: string,
   isProduction: boolean,
   tryIndex: boolean | string,
+  tryPrefix: string | undefined,
   extensions: string[]
 ): string | undefined {
   if (fs.existsSync(file)) {
@@ -279,19 +294,30 @@ function tryResolveFile(
         return resolvePackageEntry(file, pkg, isProduction)
       }
       if (tryIndex) {
-        const append = typeof tryIndex === 'string' ? `/${tryIndex}` : `/index`
         const index = tryFsResolve(
-          file + append,
+          file + '/index',
           isProduction,
           false,
+          tryPrefix,
           extensions
         )
-        if (index) return normalizePath(index) + query
+        if (index) return index + query
       }
     } else {
       return normalizePath(ensureVolumeInPath(file)) + query
     }
   }
+  if (tryPrefix) {
+    const prefixed = `${path.dirname(file)}/${tryPrefix}${path.basename(file)}`
+    return tryResolveFile(
+      prefixed,
+      query,
+      isProduction,
+      tryIndex,
+      undefined,
+      extensions
+    )
+  }
 }
 
 export const idToPkgMap = new Map()

From b0e12c2cc3d992d609af96939d3c48bfd4e1ba19 Mon Sep 17 00:00:00 2001
From: Evan You 
Date: Wed, 3 Feb 2021 11:14:31 -0500
Subject: [PATCH 470/514] test: remove stdin.resume() call

This seems to cause tests to hang out and not exit properly
---
 packages/vite/src/node/server/index.ts | 1 -
 1 file changed, 1 deletion(-)

diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts
index b79c932dd5059c..53f9613b625234 100644
--- a/packages/vite/src/node/server/index.ts
+++ b/packages/vite/src/node/server/index.ts
@@ -349,7 +349,6 @@ export async function createServer(
 
   if (!process.stdin.isTTY) {
     process.stdin.on('end', exitProcess)
-    process.stdin.resume()
   }
 
   watcher.on('change', async (file) => {

From 879922d9c451cc07a342f43a99149b150a3af68d Mon Sep 17 00:00:00 2001
From: Evan You 
Date: Wed, 3 Feb 2021 11:38:48 -0500
Subject: [PATCH 471/514] release: v2.0.0-beta.63

---
 packages/vite/CHANGELOG.md | 23 +++++++++++++++++++++++
 packages/vite/LICENSE.md   |  2 +-
 packages/vite/package.json |  2 +-
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md
index b749982d293be6..d154b97f363aeb 100644
--- a/packages/vite/CHANGELOG.md
+++ b/packages/vite/CHANGELOG.md
@@ -1,3 +1,26 @@
+# [2.0.0-beta.63](https://github.com/vitejs/vite/compare/v2.0.0-beta.62...v2.0.0-beta.63) (2021-02-03)
+
+
+### Bug Fixes
+
+* **css:** hoist external [@import](https://github.com/import) in concatenated css ([000ee62](https://github.com/vitejs/vite/commit/000ee62ef41e4964d1002ab7862303cec0419c47)), closes [#1845](https://github.com/vitejs/vite/issues/1845)
+* **css:** respect sass partial import convention ([cb7b6be](https://github.com/vitejs/vite/commit/cb7b6becd0a566c58aca6cc47ae785ac2c4b4482))
+* **vite:** close server and exit if stdin ends ([#1857](https://github.com/vitejs/vite/issues/1857)) ([b065ede](https://github.com/vitejs/vite/commit/b065ede3cca3bc72d3bb3e6f9cd945d1b36ccb42))
+* consistently use mode for NODE_ENV in deps ([cd13ef0](https://github.com/vitejs/vite/commit/cd13ef009abd23d2676dda470638c81895034a91))
+* do not shim process with actual object ([8ad7ecd](https://github.com/vitejs/vite/commit/8ad7ecd1029bdc0b47e55877db10ac630829c7e5))
+* make ssr external behavior consistent between dev/build ([e089eff](https://github.com/vitejs/vite/commit/e089eff8f8108fa5463e2e42e16244f7edfd5a1e))
+* only close if http server has listened ([94a8042](https://github.com/vitejs/vite/commit/94a804233682581c0f920ed5c0d42aa85ea3f163)), closes [#1855](https://github.com/vitejs/vite/issues/1855)
+* **scan:** handle import glob in jsx/tsx files ([24695fe](https://github.com/vitejs/vite/commit/24695fe47727b7b4e3ac85bb389477f673c57c18))
+* **ssr:** improve ssr external heuristics ([928fc33](https://github.com/vitejs/vite/commit/928fc33b6fffb3bb22c2daa4b478ead7715a2c5f)), closes [#1854](https://github.com/vitejs/vite/issues/1854)
+* respect config.build.brotliSize in reporter ([1d5437d](https://github.com/vitejs/vite/commit/1d5437d56bb0974c21561c1cdf5ad1588baefea3))
+
+
+### Features
+
+* **ssr:** graduate ssr method types ([0fe2634](https://github.com/vitejs/vite/commit/0fe2634756b6311f0489613460eeadc6c8280192))
+
+
+
 # [2.0.0-beta.62](https://github.com/vitejs/vite/compare/v2.0.0-beta.61...v2.0.0-beta.62) (2021-02-02)
 
 
diff --git a/packages/vite/LICENSE.md b/packages/vite/LICENSE.md
index 040c1fe1e8bd81..54cfaabc00a787 100644
--- a/packages/vite/LICENSE.md
+++ b/packages/vite/LICENSE.md
@@ -427,7 +427,7 @@ Repository: https://github.com/acornjs/acorn.git
 
 > MIT License
 > 
-> Copyright (C) 2012-2018 by various contributors (see AUTHORS)
+> Copyright (C) 2012-2020 by various contributors (see AUTHORS)
 > 
 > Permission is hereby granted, free of charge, to any person obtaining a copy
 > of this software and associated documentation files (the "Software"), to deal
diff --git a/packages/vite/package.json b/packages/vite/package.json
index 7ee1bcdf5fe660..2034caa3280f85 100644
--- a/packages/vite/package.json
+++ b/packages/vite/package.json
@@ -1,6 +1,6 @@
 {
   "name": "vite",
-  "version": "2.0.0-beta.62",
+  "version": "2.0.0-beta.63",
   "license": "MIT",
   "author": "Evan You",
   "description": "Native-ESM powered web dev build tool",

From d0215060e87c9464c97549cdbb008184796d0f8f Mon Sep 17 00:00:00 2001
From: Evan You 
Date: Wed, 3 Feb 2021 12:06:46 -0500
Subject: [PATCH 472/514] fix(ssr): do not resolve to optimized deps during ssr

fix #1860
---
 packages/vite/src/node/plugins/preAlias.ts | 4 ++--
 packages/vite/src/node/plugins/resolve.ts  | 7 ++++++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/packages/vite/src/node/plugins/preAlias.ts b/packages/vite/src/node/plugins/preAlias.ts
index 7a7415002effde..3bd14626e407d7 100644
--- a/packages/vite/src/node/plugins/preAlias.ts
+++ b/packages/vite/src/node/plugins/preAlias.ts
@@ -13,8 +13,8 @@ export function preAliasPlugin(): Plugin {
     configureServer(_server) {
       server = _server
     },
-    resolveId(id) {
-      if (bareImportRE.test(id)) {
+    resolveId(id, _, __, ssr) {
+      if (!ssr && bareImportRE.test(id)) {
         return tryOptimizedResolve(id, server)
       }
     }
diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts
index 63628d5b55080c..91dac741817a02 100644
--- a/packages/vite/src/node/plugins/resolve.ts
+++ b/packages/vite/src/node/plugins/resolve.ts
@@ -172,7 +172,12 @@ export function resolvePlugin({
 
       // bare package imports, perform node resolve
       if (bareImportRE.test(id)) {
-        if (asSrc && server && (res = tryOptimizedResolve(id, server))) {
+        if (
+          asSrc &&
+          server &&
+          !ssr &&
+          (res = tryOptimizedResolve(id, server))
+        ) {
           return res
         }
 

From 8ec2d6f77eb04e015156769f4f004a4792077770 Mon Sep 17 00:00:00 2001
From: Evan You 
Date: Wed, 3 Feb 2021 15:57:13 -0500
Subject: [PATCH 473/514] fix(ssr): fix externalized cjs deps that exports
 compiled esmodule

---
 packages/vite/src/node/ssr/ssrModuleLoader.ts | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/packages/vite/src/node/ssr/ssrModuleLoader.ts b/packages/vite/src/node/ssr/ssrModuleLoader.ts
index 4224452d24d763..6778088068daef 100644
--- a/packages/vite/src/node/ssr/ssrModuleLoader.ts
+++ b/packages/vite/src/node/ssr/ssrModuleLoader.ts
@@ -131,10 +131,11 @@ function nodeRequire(id: string, importer: string | null) {
   const mod = importer
     ? require(resolveFrom(id, path.dirname(importer), true))
     : require(id)
+  const defaultExport = mod.__esModule ? mod.default : mod
   // rollup-style default import interop for cjs
   return new Proxy(mod, {
     get(mod, prop) {
-      if (prop === 'default') return mod
+      if (prop === 'default') return defaultExport
       return mod[prop]
     }
   })

From cdab0a71e87f4046aeffb1c5285d4221c11bc538 Mon Sep 17 00:00:00 2001
From: Evan You 
Date: Wed, 3 Feb 2021 16:26:05 -0500
Subject: [PATCH 474/514] docs: ssr docs edits

---
 docs/config/index.md |  6 +++++-
 docs/guide/ssr.md    | 45 ++++++++++++++++++++++++++++----------------
 2 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/docs/config/index.md b/docs/config/index.md
index 8e3d7a02a4120d..87a2a30be12c56 100644
--- a/docs/config/index.md
+++ b/docs/config/index.md
@@ -524,7 +524,11 @@ export default ({ command, mode }) => {
 
 ## SSR Options
 
-- **Related:** [SSR Externals Heuristics](/guide/ssr#externals-heuristics)
+:::warning Experimental
+SSR options may be adjusted in minor releases.
+:::
+
+- **Related:** [SSR Externals](/guide/ssr#ssr-externals)
 
 ### ssr.external
 
diff --git a/docs/guide/ssr.md b/docs/guide/ssr.md
index 7451c9154f8325..64e97e39ea4030 100644
--- a/docs/guide/ssr.md
+++ b/docs/guide/ssr.md
@@ -1,6 +1,8 @@
 # Server-Side Rendering
 
-Vite provides built-in support for server-side rendering (SSR).
+:::warning Experimental
+SSR support is still experimental and you may encounter bugs and unsupported use cases. Proceed at your own risk.
+:::
 
 :::tip Note
 SSR specifically refers to front-end frameworks (for example React, Preact, Vue, and Svelte) that support running the same application in Node.js, pre-rendering it to HTML, and finally hydrating it on the client. If you are looking for integration with traditional server-side frameworks, check out the [Backend Integration guide](./backend-integration) instead.
@@ -10,7 +12,7 @@ The following guide also assumes prior experience working with SSR in your frame
 
 ## Example Projects
 
-The Vite playground contains example SSR setups for Vue 3 and React, which can be used as references for this guide:
+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)
@@ -36,9 +38,17 @@ The `index.html` will need to reference `entry-client.js` and include a placehol
 
 You can use any placeholder you prefer instead of ``, as long as it can be precisely replaced.
 
-:::tip
-If you need to perform conditional logic based on SSR vs. client, you can use `import.meta.env.SSR`. This is statically replaced during build so it will allow tree-shaking of unused branches.
-:::
+## Conditional Logic
+
+If you need to perform conditional logic based on SSR vs. client, you can use
+
+```js
+if (import.meta.env.SSR) {
+  // ... server only logic
+}
+```
+
+This is statically replaced during build so it will allow tree-shaking of unused branches.
 
 ## Setting Up the Dev Server
 
@@ -158,26 +168,25 @@ Then, in `server.js` we need to add some production specific logic by checking `
 
 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.
 
-### Generating Preload Directives
-
-> This section is Vue-specific.
+## Generating Preload Directives
 
-`@vitejs/plugin-vue` automatically registers component module IDs that are instantiated during a request render to the associated Vue SSR context. This information can be used to infer async chunks and assets that should be preloaded for a given route.
-
-In order to leverage this, add the `--ssrManifest` flag to the client build script (Yes, the SSR manifest is generated from the client build because we want to map module IDs to client files):
+`vite build` supports the `--ssrManifest` flag which will generate `ssr-manifest.json` in build output directory:
 
 ```diff
 - "build:client": "vite build --outDir dist/client",
 + "build:client": "vite build --outDir dist/client --ssrManifest",
 ```
 
-This will generate a `dist/client/ssr-manifest.json` file that contains mappings of module IDs to their associated chunks and asset files.
+The above script will now generate `dist/client/ssr-manifest.json` for the client build (Yes, the SSR manifest is generated from the client build because we want to map module IDs to client files). The manifest contains mappings of module IDs to their associated chunks and asset files.
+
+To leverage the manifest, frameworks need to provide a way to collect the module IDs of the components that were used during a server render call.
 
-Then, in `src/entry-server.js`:
+`@vitejs/plugin-vue` supports this out of the box and automatically registers used component module IDs on to the associated Vue SSR context:
 
 ```js
+// src/entry-server.js
 const ctx = {}
-const html = await renderToString(app, ctx)
+const html = await vueServerRenderer.renderToString(app, ctx)
 // ctx.modules is now a Set of module IDs that were used during the render
 ```
 
@@ -187,7 +196,7 @@ We need to now read and pass the manifest to the `render` function exported by `
 
 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 is also known as 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.
 
-## Externals Heuristics
+## SSR Externals
 
 Many dependencies ship both ESM and CommonJS files. When running SSR, a dependency that provides CommonJS builds can be "externalized" from Vite's SSR transform / module system to speed up both dev and build. For example, instead of pulling in the pre-bundled ESM version of React and then transforming it back to be Node.js-compatible, it is more efficient to simply `require('react')` instead. It also greatly improves the speed of the SSR bundle build.
 
@@ -201,6 +210,10 @@ If this heuristics leads to errors, you can manually adjust SSR externals using
 
 In the future, this heuristics will likely improve to also externalize dependencies that ship Node-compatible ESM builds (and `import()` them during SSR module load).
 
+:::warning Working with Aliases
+If you have configured alises that redirects one package to another, you may want to alias the actual `node_modules` packages instead in order to make it work for SSR externalized dependencies. Both [Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias) and [pnpm](https://pnpm.js.org/en/aliases) support aliasing via the `npm:` prefix.
+:::
+
 ## SSR-specific Plugin Logic
 
 Some frameworks such as Vue or Svelte compiles components into different formats based on client vs. SSR. To support conditional transforms, Vite passes an additional `ssr` argument to the following plugin hooks:
@@ -222,4 +235,4 @@ export function mySSRPlugin() {
     }
   }
 }
-```
\ No newline at end of file
+```

From 79dd32cbb61b2aeedfd6b1081867a98cc7c73a68 Mon Sep 17 00:00:00 2001
From: Evan You 
Date: Wed, 3 Feb 2021 16:40:49 -0500
Subject: [PATCH 475/514] feat(create-app): more detailed instructions for
 vue-ts template

---
 .../create-app/template-vue-ts/src/App.vue     |  2 +-
 .../src/components/HelloWorld.vue              | 18 +++++++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/packages/create-app/template-vue-ts/src/App.vue b/packages/create-app/template-vue-ts/src/App.vue
index 499a948f188002..26d5731c4055d1 100644
--- a/packages/create-app/template-vue-ts/src/App.vue
+++ b/packages/create-app/template-vue-ts/src/App.vue
@@ -1,6 +1,6 @@
 
 
 
 ```
 
-You can use any placeholder you prefer instead of ``, as long as it can be precisely replaced.
+You can use any placeholder you prefer instead of ``, as long as it can be precisely replaced.
 
 ## Conditional Logic
 
@@ -66,7 +66,7 @@ async function createServer() {
   const app = express()
 
   // Create vite server in middleware mode. This disables Vite's own HTML
-  // serving logic and let's the parent server take control.
+  // serving logic and let the parent server take control.
   const vite = await createViteServer({
     server: { middlewareMode: true }
   })
@@ -160,7 +160,7 @@ Note the `--ssr` flag which indicates this is an SSR build. It should also speci
 
 Then, in `server.js` we need to add some production specific logic by checking `process.env.NODE_ENV`:
 
-- Instead of reading the root `index.html`, use the `dist/client/index.html` as template instead, since it contains the correct asset links to the client build.
+- Instead of reading the root `index.html`, use the `dist/client/index.html` as the template instead, since it contains the correct asset links to the client build.
 
 - Instead of `await vite.ssrLoadModule('/src/entry-server.js')`, use `require('./dist/server/entry-server.js')` instead (this file is the result of the SSR build).
 
@@ -211,7 +211,7 @@ If this heuristics leads to errors, you can manually adjust SSR externals using
 In the future, this heuristics will likely improve to detect if the project has `type: "module"` enabled, so that Vite can also externalize dependencies that ship Node-compatible ESM builds by importing them via dynamic `import()` during SSR.
 
 :::warning Working with Aliases
-If you have configured alises that redirects one package to another, you may want to alias the actual `node_modules` packages instead in order to make it work for SSR externalized dependencies. Both [Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias) and [pnpm](https://pnpm.js.org/en/aliases) support aliasing via the `npm:` prefix.
+If you have configured aliases that redirects one package to another, you may want to alias the actual `node_modules` packages instead to make it work for SSR externalized dependencies. Both [Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias) and [pnpm](https://pnpm.js.org/en/aliases) support aliasing via the `npm:` prefix.
 :::
 
 ## SSR-specific Plugin Logic

From c741872e6ca975f507ec89581b742a1da19a0cb0 Mon Sep 17 00:00:00 2001
From: Evan You 
Date: Thu, 4 Feb 2021 10:04:40 -0500
Subject: [PATCH 482/514] fix(resolve): prioritize file over dir with same name
 for resolve

fix #1871
---
 .../resolve/__tests__/resolve.spec.ts         |  6 ++-
 packages/playground/resolve/dir.js            |  1 +
 packages/playground/resolve/dir/index.js      |  1 +
 packages/playground/resolve/index.html        |  7 +++
 packages/vite/src/node/plugins/resolve.ts     | 48 +++++++++----------
 5 files changed, 37 insertions(+), 26 deletions(-)
 create mode 100644 packages/playground/resolve/dir.js
 create mode 100644 packages/playground/resolve/dir/index.js

diff --git a/packages/playground/resolve/__tests__/resolve.spec.ts b/packages/playground/resolve/__tests__/resolve.spec.ts
index ebb81ba2e98c72..69858977fa8f68 100644
--- a/packages/playground/resolve/__tests__/resolve.spec.ts
+++ b/packages/playground/resolve/__tests__/resolve.spec.ts
@@ -34,10 +34,14 @@ test('Respect production/development conditionals', async () => {
   )
 })
 
-test('omitted index/*', async () => {
+test('implicit dir/index.js', async () => {
   expect(await page.textContent('.index')).toMatch('[success]')
 })
 
+test('implicit dir/index.js vs explicit file', async () => {
+  expect(await page.textContent('.dir-vs-file')).toMatch('[success]')
+})
+
 test('filename with dot', async () => {
   expect(await page.textContent('.dot')).toMatch('[success]')
 })
diff --git a/packages/playground/resolve/dir.js b/packages/playground/resolve/dir.js
new file mode 100644
index 00000000000000..96d7982ecd16fb
--- /dev/null
+++ b/packages/playground/resolve/dir.js
@@ -0,0 +1 @@
+export const file = '[success] dir.js'
diff --git a/packages/playground/resolve/dir/index.js b/packages/playground/resolve/dir/index.js
new file mode 100644
index 00000000000000..604301f196eb9f
--- /dev/null
+++ b/packages/playground/resolve/dir/index.js
@@ -0,0 +1 @@
+export const file = 'dir/index.js'
diff --git a/packages/playground/resolve/index.html b/packages/playground/resolve/index.html
index 1ddfb90704c511..4e0a654ce33c87 100644
--- a/packages/playground/resolve/index.html
+++ b/packages/playground/resolve/index.html
@@ -21,6 +21,9 @@ 

Exports field env priority

Resolve /index.*

fail

+

Resolve dir and file of the same name (should prioritize file)

+

fail

+

Resolve file name containing dot

fail

@@ -79,6 +82,10 @@

Inline package

import { foo } from './util' text('.index', foo()) + // implicit dir index vs. file + import { file } from './dir' + text('.dir-vs-file', file) + // filename with dot import { bar } from './util/bar.util' text('.dot', bar()) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 91dac741817a02..222f2a4b44b533 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -246,25 +246,13 @@ export function resolvePlugin({ export function tryFsResolve( fsPath: string, isProduction: boolean, - tryIndex: boolean | string = true, + tryIndex: boolean = true, tryPrefix: string | undefined = undefined, extensions = SUPPORTED_EXTS ): string | undefined { const [file, q] = fsPath.split(`?`, 2) const query = q ? `?${q}` : `` let res: string | undefined - if ( - (res = tryResolveFile( - file, - query, - isProduction, - tryIndex, - tryPrefix, - extensions - )) - ) { - return res - } for (const ext of extensions) { if ( (res = tryResolveFile( @@ -279,35 +267,45 @@ export function tryFsResolve( return res } } + if ( + (res = tryResolveFile( + file, + query, + isProduction, + tryIndex, + tryPrefix, + extensions + )) + ) { + return res + } } function tryResolveFile( file: string, query: string, isProduction: boolean, - tryIndex: boolean | string, + tryIndex: boolean, tryPrefix: string | undefined, extensions: string[] ): string | undefined { if (fs.existsSync(file)) { const isDir = fs.statSync(file).isDirectory() - if (isDir) { + if (isDir && tryIndex) { const pkgPath = file + '/package.json' if (fs.existsSync(pkgPath)) { // path points to a node package const pkg = loadPackageData(pkgPath) return resolvePackageEntry(file, pkg, isProduction) } - if (tryIndex) { - const index = tryFsResolve( - file + '/index', - isProduction, - false, - tryPrefix, - extensions - ) - if (index) return index + query - } + const index = tryFsResolve( + file + '/index', + isProduction, + false, + tryPrefix, + extensions + ) + if (index) return index + query } else { return normalizePath(ensureVolumeInPath(file)) + query } From 3eed49968872e4e7c019d7cdecb4ad17fb68d2f9 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 4 Feb 2021 12:10:49 -0500 Subject: [PATCH 483/514] docs: logo --- docs/index.md | 1 + docs/public/logo.svg | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 docs/public/logo.svg diff --git a/docs/index.md b/docs/index.md index 38e12e939b3ff2..d4d9835154149e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,5 +1,6 @@ --- home: true +heroImage: /logo.svg actionText: Get Started actionLink: /guide/ diff --git a/docs/public/logo.svg b/docs/public/logo.svg new file mode 100644 index 00000000000000..7ffb40be702721 --- /dev/null +++ b/docs/public/logo.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + From 0ea710e0299fde608915c024db4b2b46df330c4e Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 4 Feb 2021 12:31:12 -0500 Subject: [PATCH 484/514] chore: readme --- README.md | 23 ++++++++++++++++------- docs/.vitepress/config.js | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index eb7d89c581d39f..e46cefeadc6811 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,19 @@ -# vite ⚡ - -[![npm][npm-img]][npm-url] -[![node][node-img]][node-url] -[![unix CI status][unix-ci-img]][unix-ci-url] -[![windows CI status][windows-ci-img]][windows-ci-url] -[![chat on Discord][discord-img]][discord-url] +

+ + Vite logo + +

+
+

+ npm package + node compatility + unix build status + windows build status + discord chat +

+
+ +# Vite ⚡ > Next Generation Frontend Tooling diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index 2e6300ee6485d5..594940297f6855 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -4,7 +4,7 @@ * @type {import('vitepress').UserConfig} */ module.exports = { - title: 'Vite⚡', + title: 'Vite', description: 'Next Generation Frontend Tooling', head: [ [ From 5d3107a4a787929810fbfaef37bf3002aa0bcc17 Mon Sep 17 00:00:00 2001 From: mj2ks <39779703+mj2ks@users.noreply.github.com> Date: Fri, 5 Feb 2021 01:13:53 +0700 Subject: [PATCH 485/514] fix(dev): check wasClean in onclose event (#1872) --- packages/vite/src/client/client.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/client/client.ts b/packages/vite/src/client/client.ts index 09a0b1a1ca784c..cf392ee762d753 100644 --- a/packages/vite/src/client/client.ts +++ b/packages/vite/src/client/client.ts @@ -169,7 +169,8 @@ async function queueUpdate(p: Promise<(() => void) | undefined>) { } // ping server -socket.addEventListener('close', () => { +socket.addEventListener('close', ({ wasClean }) => { + if (wasClean) return console.log(`[vite] server connection lost. polling for restart...`) setInterval(() => { fetch('/') From 3fad3ba861fb56edd22941db645f2d73b02bf7b1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 4 Feb 2021 14:24:11 -0500 Subject: [PATCH 486/514] fix(ssr): respect user defines for ssr --- packages/vite/src/node/build.ts | 2 - packages/vite/src/node/optimizer/index.ts | 11 +++-- packages/vite/src/node/plugins/define.ts | 51 +++++++++++++++-------- packages/vite/src/node/plugins/index.ts | 2 + 4 files changed, 43 insertions(+), 23 deletions(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 7cf6f05f64f786..d76b919646546e 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -15,7 +15,6 @@ import Rollup, { GetModuleInfo } from 'rollup' import { buildReporterPlugin } from './plugins/reporter' -import { buildDefinePlugin } from './plugins/define' import { buildHtmlPlugin } from './plugins/html' import { buildEsbuildPlugin } from './plugins/esbuild' import { terserPlugin } from './plugins/terser' @@ -242,7 +241,6 @@ export function resolveBuildPlugins( buildHtmlPlugin(config), commonjsPlugin(options.commonjsOptions), dataURIPlugin(), - buildDefinePlugin(config), dynamicImportVars({ warnOnError: true, exclude: [/node_modules/] diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index c7d154cfaa0f27..4be60b29a4f4c6 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -208,6 +208,13 @@ export async function optimizeDeps( flatIdToExports[flatId] = exportsData } + const define: Record = { + 'process.env.NODE_ENV': JSON.stringify(config.mode) + } + for (const key in config.define) { + define[key] = JSON.stringify(config.define[key]) + } + const start = Date.now() const esbuildService = await ensureService() await esbuildService.build({ @@ -221,9 +228,7 @@ export async function optimizeDeps( outdir: cacheDir, treeShaking: 'ignore-annotations', metafile: esbuildMetaPath, - define: { - 'process.env.NODE_ENV': JSON.stringify(config.mode) - }, + define, plugins: [esbuildDepPlugin(flatIdDeps, flatIdToExports, config)] }) diff --git a/packages/vite/src/node/plugins/define.ts b/packages/vite/src/node/plugins/define.ts index d56b5872519756..df2772f3cfb40b 100644 --- a/packages/vite/src/node/plugins/define.ts +++ b/packages/vite/src/node/plugins/define.ts @@ -4,34 +4,36 @@ import { ResolvedConfig } from '../config' import { Plugin } from '../plugin' import { isCSSRequest } from './css' -/** - * Build only. - * Server define is injected as runtime variables by clientInjection plugin - * to avoid transform cost during dev. - */ -export function buildDefinePlugin(config: ResolvedConfig): Plugin { +export function definePlugin(config: ResolvedConfig): Plugin { + const isBuild = config.command === 'build' + const userDefine: Record = {} for (const key in config.define) { userDefine[key] = JSON.stringify(config.define[key]) } - const individualEnvKeys: Record = {} - const env: Record = { - ...config.env, - SSR: !!config.build.ssr - } - for (const key in env) { - individualEnvKeys[`import.meta.env.${key}`] = JSON.stringify(env[key]) + // during dev, import.meta properties are handled by importAnalysis plugin + const importMetaKeys: Record = {} + if (isBuild) { + const env: Record = { + ...config.env, + SSR: !!config.build.ssr + } + for (const key in env) { + importMetaKeys[`import.meta.env.${key}`] = JSON.stringify(env[key]) + } + Object.assign(importMetaKeys, { + 'import.meta.env.': `({}).`, + 'import.meta.env': JSON.stringify(config.env), + 'import.meta.hot': `false` + }) } const replacements: Record = { 'process.env.NODE_ENV': JSON.stringify(config.mode), 'process.env.': `({}).`, ...userDefine, - ...individualEnvKeys, - 'import.meta.env.': `({}).`, - 'import.meta.env': JSON.stringify(config.env), - 'import.meta.hot': `false` + ...importMetaKeys } const pattern = new RegExp( @@ -47,7 +49,13 @@ export function buildDefinePlugin(config: ResolvedConfig): Plugin { return { name: 'vite:define', - transform(code, id) { + transform(code, id, ssr) { + if (!ssr && !isBuild) { + // for dev we inject actual global defines in the vite client to + // avoid the transform cost. + return + } + if ( // exclude css and static assets for performance isCSSRequest(id) || @@ -56,6 +64,13 @@ export function buildDefinePlugin(config: ResolvedConfig): Plugin { return } + if (ssr && !isBuild) { + // ssr + dev, simple replace + return code.replace(pattern, (_, match) => { + return '' + replacements[match] + }) + } + const s = new MagicString(code) let hasReplaced = false let match diff --git a/packages/vite/src/node/plugins/index.ts b/packages/vite/src/node/plugins/index.ts index 0fbba274680bc2..a18e171b5cdc9b 100644 --- a/packages/vite/src/node/plugins/index.ts +++ b/packages/vite/src/node/plugins/index.ts @@ -13,6 +13,7 @@ import { wasmPlugin } from './wasm' import { webWorkerPlugin } from './worker' import { dynamicImportPolyfillPlugin } from './dynamicImportPolyfill' import { preAliasPlugin } from './preAlias' +import { definePlugin } from './define' export async function resolvePlugins( config: ResolvedConfig, @@ -54,6 +55,7 @@ export async function resolvePlugins( webWorkerPlugin(config), assetPlugin(config), ...normalPlugins, + definePlugin(config), cssPostPlugin(config), ...buildPlugins.pre, ...postPlugins, From 1fdc710a391b968f85f6a150dc06e51e53742b02 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 4 Feb 2021 15:15:04 -0500 Subject: [PATCH 487/514] fix: better dependency non-js type file handling - avoid appending version query to externalized non-js dep files --- packages/vite/src/node/constants.ts | 2 ++ packages/vite/src/node/optimizer/scan.ts | 7 +++---- packages/vite/src/node/plugins/resolve.ts | 19 ++++++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/vite/src/node/constants.ts b/packages/vite/src/node/constants.ts index 44749867646fc0..c84f32d5e981d7 100644 --- a/packages/vite/src/node/constants.ts +++ b/packages/vite/src/node/constants.ts @@ -2,6 +2,8 @@ import path from 'path' export const SUPPORTED_EXTS = ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'] +export const JS_TYPES_RE = /\.(j|t)sx?$|\.mjs$/ + export const SPECIAL_QUERY_RE = /[\?&](worker|raw|url)\b/ export const DEP_CACHE_DIR = `.vite` diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index 5243eb3106f0b5..200e3a07aa6f61 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -3,7 +3,7 @@ import path from 'path' import glob from 'fast-glob' import { ResolvedConfig } from '..' import { Loader, Plugin } from 'esbuild' -import { KNOWN_ASSET_TYPES, SPECIAL_QUERY_RE } from '../constants' +import { KNOWN_ASSET_TYPES, JS_TYPES_RE, SPECIAL_QUERY_RE } from '../constants' import { createDebugger, emptyDir, @@ -25,7 +25,6 @@ import { ensureService } from '../plugins/esbuild' const debug = createDebugger('vite:deps') -const jsTypesRE = /\.(j|t)sx?$|\.mjs$/ const htmlTypesRE = /\.(html|vue|svelte)$/ export async function scanImports( @@ -301,7 +300,7 @@ function esbuildScanPlugin( // for jsx/tsx, we need to access the content and check for // presence of import.meta.glob, since it results in import relationships // but isn't crawled by esbuild. - build.onLoad({ filter: jsTypesRE }, ({ path: id }) => { + build.onLoad({ filter: JS_TYPES_RE }, ({ path: id }) => { let ext = path.extname(id).slice(1) if (ext === 'mjs') ext = 'js' @@ -363,7 +362,7 @@ export function shouldExternalizeDep(resolvedId: string, rawId?: string) { return true } // resovled is not a js type - if (!jsTypesRE.test(resolvedId)) { + if (!JS_TYPES_RE.test(resolvedId)) { return true } } diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 222f2a4b44b533..8673aeb2ab5b54 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -2,7 +2,12 @@ import fs from 'fs' import path from 'path' import { Plugin } from '../plugin' import chalk from 'chalk' -import { FS_PREFIX, SPECIAL_QUERY_RE, SUPPORTED_EXTS } from '../constants' +import { + FS_PREFIX, + JS_TYPES_RE, + SPECIAL_QUERY_RE, + SUPPORTED_EXTS +} from '../constants' import { isBuiltin, bareImportRE, @@ -23,7 +28,6 @@ import slash from 'slash' import { createFilter } from '@rollup/pluginutils' import { PartialResolvedId } from 'rollup' import { resolve as _resolveExports } from 'resolve.exports' -import { isCSSRequest } from './css' const altMainFields = [ 'module', @@ -381,21 +385,22 @@ export function tryNodeResolve( return { id: resolved } } // if we reach here, it's a valid dep import that hasn't been optimzied. + const isJsType = JS_TYPES_RE.test(resolved) const exclude = server.config.optimizeDeps?.exclude if ( + !isJsType || importer?.includes('node_modules') || exclude?.includes(pkgId) || exclude?.includes(id) || - isCSSRequest(resolved) || - server.config.assetsInclude(resolved) || - resolved.endsWith('.json') || SPECIAL_QUERY_RE.test(resolved) ) { // excluded from optimization // Inject a version query to npm deps so that the browser - // can cache it without revalidation. + // can cache it without revalidation, but only do so for known js types. + // otherwise we may introduce duplicated modules for externalized files + // from pre-bundled deps. const versionHash = server._optimizeDepsMetadata?.browserHash - if (versionHash) { + if (versionHash && isJsType) { resolved = injectQuery(resolved, `v=${versionHash}`) } } else { From f90a85c2ba8c9ba215fe75c49035a7e38fa81a7d Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 4 Feb 2021 16:37:50 -0500 Subject: [PATCH 488/514] feat: support resolving style/sass entries in css @import close #1874 --- packages/playground/css/__tests__/css.spec.ts | 8 + packages/playground/css/css-dep/index.css | 3 + packages/playground/css/css-dep/index.js | 1 + packages/playground/css/css-dep/index.scss | 3 + packages/playground/css/css-dep/package.json | 7 + packages/playground/css/dep.css | 1 + packages/playground/css/index.html | 7 + packages/playground/css/main.js | 2 + packages/playground/css/package.json | 3 +- packages/playground/css/sass.scss | 1 + packages/vite/src/node/config.ts | 21 +-- packages/vite/src/node/plugins/css.ts | 3 + packages/vite/src/node/plugins/resolve.ts | 137 ++++++------------ packages/vite/src/node/ssr/ssrExternal.ts | 10 +- yarn.lock | 4 + 15 files changed, 102 insertions(+), 109 deletions(-) create mode 100644 packages/playground/css/css-dep/index.css create mode 100644 packages/playground/css/css-dep/index.js create mode 100644 packages/playground/css/css-dep/index.scss create mode 100644 packages/playground/css/css-dep/package.json create mode 100644 packages/playground/css/dep.css diff --git a/packages/playground/css/__tests__/css.spec.ts b/packages/playground/css/__tests__/css.spec.ts index e9f86683428cdb..010fde92347e7e 100644 --- a/packages/playground/css/__tests__/css.spec.ts +++ b/packages/playground/css/__tests__/css.spec.ts @@ -125,6 +125,14 @@ test('css modules w/ sass', async () => { await untilUpdated(() => getColor(imported), 'blue') }) +test('@import dependency w/ style entry', async () => { + expect(await getColor('.css-dep')).toBe('purple') +}) + +test('@import dependency w/ sass entry', async () => { + expect(await getColor('.css-dep-sass')).toBe('orange') +}) + test('async chunk', async () => { const el = await page.$('.async') expect(await getColor(el)).toBe('teal') diff --git a/packages/playground/css/css-dep/index.css b/packages/playground/css/css-dep/index.css new file mode 100644 index 00000000000000..fb86e5496c1aee --- /dev/null +++ b/packages/playground/css/css-dep/index.css @@ -0,0 +1,3 @@ +.css-dep { + color: purple; +} \ No newline at end of file diff --git a/packages/playground/css/css-dep/index.js b/packages/playground/css/css-dep/index.js new file mode 100644 index 00000000000000..47b55353d03edb --- /dev/null +++ b/packages/playground/css/css-dep/index.js @@ -0,0 +1 @@ +throw new Error('should not be imported') diff --git a/packages/playground/css/css-dep/index.scss b/packages/playground/css/css-dep/index.scss new file mode 100644 index 00000000000000..97a24aa0551eb9 --- /dev/null +++ b/packages/playground/css/css-dep/index.scss @@ -0,0 +1,3 @@ +.css-dep-sass { + color: orange; +} diff --git a/packages/playground/css/css-dep/package.json b/packages/playground/css/css-dep/package.json new file mode 100644 index 00000000000000..2f5856f51db4fa --- /dev/null +++ b/packages/playground/css/css-dep/package.json @@ -0,0 +1,7 @@ +{ + "name": "css-dep", + "version": "1.0.0", + "main": "index.js", + "style": "index.css", + "sass": "index.scss" +} diff --git a/packages/playground/css/dep.css b/packages/playground/css/dep.css new file mode 100644 index 00000000000000..cb828d3383582a --- /dev/null +++ b/packages/playground/css/dep.css @@ -0,0 +1 @@ +@import 'css-dep' \ No newline at end of file diff --git a/packages/playground/css/index.html b/packages/playground/css/index.html index 2904cc0511b1c1..b2443e6ee9d5d5 100644 --- a/packages/playground/css/index.html +++ b/packages/playground/css/index.html @@ -39,6 +39,13 @@

CSS

CSS modules w/ SASS: this should be orangered

Imported SASS module:


+
+  

+ @import dependency w/ style enrtrypoints: this should be purple +

+

+ @import dependency w/ sass enrtrypoints: this should be orange +

diff --git a/packages/playground/css/main.js b/packages/playground/css/main.js index b3d256a60544a5..9b16842933fa6e 100644 --- a/packages/playground/css/main.js +++ b/packages/playground/css/main.js @@ -15,6 +15,8 @@ import sassMod from './mod.module.scss' document.querySelector('.modules-sass').classList.add(sassMod.applyColor) text('.modules-sass-code', JSON.stringify(sassMod, null, 2)) +import './dep.css' + function text(el, text) { document.querySelector(el).textContent = text } diff --git a/packages/playground/css/package.json b/packages/playground/css/package.json index a5e0140e6da380..dedf35b5834fd0 100644 --- a/packages/playground/css/package.json +++ b/packages/playground/css/package.json @@ -11,6 +11,7 @@ "devDependencies": { "less": "^4.1.0", "postcss-nested": "^5.0.3", - "sass": "^1.32.5" + "sass": "^1.32.5", + "css-dep": "link:./css-dep" } } diff --git a/packages/playground/css/sass.scss b/packages/playground/css/sass.scss index c622dad413bc64..173106214abc1a 100644 --- a/packages/playground/css/sass.scss +++ b/packages/playground/css/sass.scss @@ -1,5 +1,6 @@ @import '@/nested'; // alias + custom index resolving -> /nested/_index.scss @import '@/nested/partial'; // sass convention: omitting leading _ for partials +@import 'css-dep'; // package w/ sass entry points .sass { /* injected via vite.config.js */ diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index e892ae469aaed3..cbe2e0787f3500 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -19,7 +19,7 @@ import dotenv from 'dotenv' import dotenvExpand from 'dotenv-expand' import { Alias, AliasOptions } from 'types/alias' import { CLIENT_DIR, DEFAULT_ASSETS_RE, DEP_CACHE_DIR } from './constants' -import { resolvePlugin } from './plugins/resolve' +import { ResolveOptions, resolvePlugin } from './plugins/resolve' import { createLogger, Logger, LogLevel } from './logger' import { DepOptimizationOptions } from './optimizer' import { createFilter } from '@rollup/pluginutils' @@ -166,16 +166,12 @@ export type ResolvedConfig = Readonly< build: ResolvedBuildOptions assetsInclude: (file: string) => boolean logger: Logger - createResolver: (options?: { - asSrc?: boolean - tryIndex?: boolean - tryPrefix?: string - extensions?: string[] - relativeFirst?: boolean - }) => ResolveFn + createResolver: (options?: Partial) => ResolveFn } > +export { ResolveOptions } + export type ResolveFn = ( id: string, importer?: string, @@ -331,11 +327,10 @@ export async function resolveConfig( dedupe: resolved.dedupe, isProduction, isBuild: command === 'build', - asSrc: options?.asSrc ?? true, - relativeFirst: options?.relativeFirst ?? false, - tryIndex: options?.tryIndex ?? true, - tryPrefix: options?.tryPrefix, - extensions: options?.extensions + asSrc: true, + relativeFirst: false, + tryIndex: true, + ...options }) ] })) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 3216362b9cfb93..0c96cd60832d1a 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -422,6 +422,7 @@ function createCSSResolvers(config: ResolvedConfig): CSSResolvers { cssResolve || (cssResolve = config.createResolver({ extensions: ['.css'], + mainFields: ['style'], tryIndex: false, relativeFirst: true })) @@ -433,6 +434,7 @@ function createCSSResolvers(config: ResolvedConfig): CSSResolvers { sassResolve || (sassResolve = config.createResolver({ extensions: ['.scss', '.sass', '.css'], + mainFields: ['sass', 'style'], tryIndex: true, tryPrefix: '_', relativeFirst: true @@ -445,6 +447,7 @@ function createCSSResolvers(config: ResolvedConfig): CSSResolvers { lessResolve || (lessResolve = config.createResolver({ extensions: ['.less', '.css'], + mainFields: ['less', 'style'], tryIndex: false, relativeFirst: true })) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 8673aeb2ab5b54..a14bdf0cb8941c 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -29,7 +29,7 @@ import { createFilter } from '@rollup/pluginutils' import { PartialResolvedId } from 'rollup' import { resolve as _resolveExports } from 'resolve.exports' -const altMainFields = [ +const MAIN_FIELDS = [ 'module', 'jsnext:main', // moment still uses this... 'jsnext' @@ -55,7 +55,7 @@ const debug = createDebugger('vite:resolve-details', { onlyWhenFocused: true }) -interface ResolveOptions { +export interface ResolveOptions { root: string isBuild: boolean isProduction: boolean @@ -64,31 +64,19 @@ interface ResolveOptions { * - resolving /xxx as URLs * - resolving bare imports from optimized deps */ - asSrc: boolean + asSrc?: boolean tryIndex?: boolean tryPrefix?: string relativeFirst?: boolean + mainFields?: string[] extensions?: string[] dedupe?: string[] } -export function resolvePlugin({ - root, - isBuild, - isProduction, - asSrc, - dedupe, - tryIndex = true, - tryPrefix, - relativeFirst = false, - extensions = SUPPORTED_EXTS -}: ResolveOptions): Plugin { +export function resolvePlugin(options: ResolveOptions): Plugin { + const { root, isProduction, asSrc, relativeFirst = false } = options let server: ViteDevServer | undefined - // curried fs resovle - const fsResolve = (fsPath: string) => - tryFsResolve(fsPath, isProduction, tryIndex, tryPrefix, extensions) - return { name: 'vite:resolve', @@ -111,7 +99,7 @@ export function resolvePlugin({ // explicit fs paths that starts with /@fs/* if (asSrc && id.startsWith(FS_PREFIX)) { const fsPath = fsPathFromId(id) - res = fsResolve(fsPath) + res = tryFsResolve(fsPath, options) isDebug && debug(`[@fs] ${chalk.cyan(id)} -> ${chalk.dim(res)}`) // always return here even if res doesn't exist since /@fs/ is explicit // if the file doesn't exist it should be a 404 @@ -122,7 +110,7 @@ export function resolvePlugin({ // /foo -> /fs-root/foo if (asSrc && id.startsWith('/')) { const fsPath = path.resolve(root, id.slice(1)) - if ((res = fsResolve(fsPath))) { + if ((res = tryFsResolve(fsPath, options))) { isDebug && debug(`[url] ${chalk.cyan(id)} -> ${chalk.dim(res)}`) return res } @@ -134,13 +122,11 @@ export function resolvePlugin({ let fsPath = path.resolve(basedir, id) // handle browser field mapping for relative imports - if ( - (res = tryResolveBrowserMapping(fsPath, importer, true, isProduction)) - ) { + if ((res = tryResolveBrowserMapping(fsPath, importer, options, true))) { return res } - if ((res = fsResolve(fsPath))) { + if ((res = tryFsResolve(fsPath, options))) { isDebug && debug(`[relative] ${chalk.cyan(id)} -> ${chalk.dim(res)}`) const pkg = importer != null && idToPkgMap.get(importer) if (pkg) { @@ -155,7 +141,7 @@ export function resolvePlugin({ } // absolute fs paths - if (path.isAbsolute(id) && (res = fsResolve(id))) { + if (path.isAbsolute(id) && (res = tryFsResolve(id, options))) { isDebug && debug(`[fs] ${chalk.cyan(id)} -> ${chalk.dim(res)}`) return res } @@ -185,23 +171,11 @@ export function resolvePlugin({ return res } - if ( - (res = tryResolveBrowserMapping(id, importer, false, isProduction)) - ) { + if ((res = tryResolveBrowserMapping(id, importer, options, false))) { return res } - if ( - (res = tryNodeResolve( - id, - importer, - root, - isProduction, - isBuild, - dedupe, - server - )) - ) { + if ((res = tryNodeResolve(id, importer, options, server))) { return res } @@ -246,40 +220,29 @@ export function resolvePlugin({ } } -// resolve extensions -export function tryFsResolve( +function tryFsResolve( fsPath: string, - isProduction: boolean, - tryIndex: boolean = true, - tryPrefix: string | undefined = undefined, - extensions = SUPPORTED_EXTS + options: ResolveOptions, + tryIndex = true ): string | undefined { const [file, q] = fsPath.split(`?`, 2) const query = q ? `?${q}` : `` let res: string | undefined - for (const ext of extensions) { + for (const ext of options.extensions || SUPPORTED_EXTS) { if ( (res = tryResolveFile( file + ext, query, - isProduction, + options, false, - tryPrefix, - extensions + options.tryPrefix )) ) { return res } } if ( - (res = tryResolveFile( - file, - query, - isProduction, - tryIndex, - tryPrefix, - extensions - )) + (res = tryResolveFile(file, query, options, tryIndex, options.tryPrefix)) ) { return res } @@ -288,10 +251,9 @@ export function tryFsResolve( function tryResolveFile( file: string, query: string, - isProduction: boolean, + options: ResolveOptions, tryIndex: boolean, - tryPrefix: string | undefined, - extensions: string[] + tryPrefix?: string ): string | undefined { if (fs.existsSync(file)) { const isDir = fs.statSync(file).isDirectory() @@ -300,15 +262,9 @@ function tryResolveFile( if (fs.existsSync(pkgPath)) { // path points to a node package const pkg = loadPackageData(pkgPath) - return resolvePackageEntry(file, pkg, isProduction) + return resolvePackageEntry(file, pkg, options) } - const index = tryFsResolve( - file + '/index', - isProduction, - false, - tryPrefix, - extensions - ) + const index = tryFsResolve(file + '/index', options) if (index) return index + query } else { return normalizePath(ensureVolumeInPath(file)) + query @@ -316,14 +272,7 @@ function tryResolveFile( } if (tryPrefix) { const prefixed = `${path.dirname(file)}/${tryPrefix}${path.basename(file)}` - return tryResolveFile( - prefixed, - query, - isProduction, - tryIndex, - undefined, - extensions - ) + return tryResolveFile(prefixed, query, options, tryIndex) } } @@ -332,12 +281,10 @@ export const idToPkgMap = new Map() export function tryNodeResolve( id: string, importer: string | undefined, - root: string, - isProduction: boolean, - isBuild = true, - dedupe?: string[], + options: ResolveOptions, server?: ViteDevServer ): PartialResolvedId | undefined { + const { root, dedupe, isBuild } = options const deepMatch = id.match(deepImportRE) const pkgId = deepMatch ? deepMatch[1] || deepMatch[2] : id @@ -361,8 +308,8 @@ export function tryNodeResolve( } let resolved = deepMatch - ? resolveDeepImport(id, pkg, isProduction) - : resolvePackageEntry(id, pkg, isProduction) + ? resolveDeepImport(id, pkg, options) + : resolvePackageEntry(id, pkg, options) if (!resolved) { return } @@ -490,7 +437,7 @@ function loadPackageData(pkgPath: string, cacheKey = pkgPath) { export function resolvePackageEntry( id: string, { resolvedImports, dir, data }: PackageData, - isProduction = false + options: ResolveOptions ): string | undefined { if (resolvedImports['.']) { return resolvedImports['.'] @@ -501,7 +448,7 @@ export function resolvePackageEntry( // resolve exports field with highest priority // using https://github.com/lukeed/resolve.exports if (data.exports) { - entryPoint = resolveExports(data, '.', isProduction) + entryPoint = resolveExports(data, '.', options.isProduction) } // if exports resolved to .mjs, still resolve other fields. @@ -526,7 +473,7 @@ export function resolvePackageEntry( // instead; Otherwise, assume it's ESM and use it. const resolvedBrowserEntry = tryFsResolve( path.join(dir, browserEntry), - isProduction + options ) if (resolvedBrowserEntry) { const content = fs.readFileSync(resolvedBrowserEntry, 'utf-8') @@ -546,7 +493,7 @@ export function resolvePackageEntry( } if (!entryPoint || entryPoint.endsWith('.mjs')) { - for (const field of altMainFields) { + for (const field of options.mainFields || MAIN_FIELDS) { if (typeof data[field] === 'string') { entryPoint = data[field] break @@ -563,7 +510,7 @@ export function resolvePackageEntry( } entryPoint = path.join(dir, entryPoint) - const resolvedEntryPont = tryFsResolve(entryPoint, isProduction) + const resolvedEntryPont = tryFsResolve(entryPoint, options) if (resolvedEntryPont) { isDebug && @@ -583,7 +530,7 @@ export function resolvePackageEntry( function resolveDeepImport( id: string, { resolvedImports, dir, data }: PackageData, - isProduction: boolean + options: ResolveOptions ): string | undefined { id = '.' + id.slice(data.name.length) if (resolvedImports[id]) { @@ -596,7 +543,7 @@ function resolveDeepImport( // map relative based on exports data if (exportsField) { if (isObject(exportsField) && !Array.isArray(exportsField)) { - relativeId = resolveExports(data, relativeId, isProduction) + relativeId = resolveExports(data, relativeId, options.isProduction) } else { // not exposed relativeId = undefined @@ -617,7 +564,11 @@ function resolveDeepImport( } if (relativeId) { - const resolved = tryFsResolve(path.join(dir, relativeId), !exportsField) + const resolved = tryFsResolve( + path.join(dir, relativeId), + options, + !exportsField // try index only if no exports field + ) if (resolved) { isDebug && debug(`[node/deep-import] ${chalk.cyan(id)} -> ${chalk.dim(resolved)}`) @@ -629,8 +580,8 @@ function resolveDeepImport( function tryResolveBrowserMapping( id: string, importer: string | undefined, - isFilePath: boolean, - isProduction: boolean + options: ResolveOptions, + isFilePath: boolean ) { let res: string | undefined const pkg = importer && idToPkgMap.get(importer) @@ -639,7 +590,7 @@ function tryResolveBrowserMapping( const browserMappedPath = mapWithBrowserField(mapId, pkg.data.browser) if (browserMappedPath) { const fsPath = path.join(pkg.dir, browserMappedPath) - if ((res = tryFsResolve(fsPath, isProduction))) { + if ((res = tryFsResolve(fsPath, options))) { isDebug && debug(`[browser mapped] ${chalk.cyan(id)} -> ${chalk.dim(res)}`) idToPkgMap.set(res, pkg) diff --git a/packages/vite/src/node/ssr/ssrExternal.ts b/packages/vite/src/node/ssr/ssrExternal.ts index c6fb88a00631fb..b65bf7fce520c2 100644 --- a/packages/vite/src/node/ssr/ssrExternal.ts +++ b/packages/vite/src/node/ssr/ssrExternal.ts @@ -1,6 +1,6 @@ import fs from 'fs' import path from 'path' -import { tryNodeResolve } from '../plugins/resolve' +import { tryNodeResolve, ResolveOptions } from '../plugins/resolve' import { lookupFile, resolveFrom } from '../utils' import { ResolvedConfig } from '..' @@ -28,11 +28,17 @@ export function resolveSSRExternal( ssrExternals.add(id) } + const resolveOptions: ResolveOptions = { + root, + isProduction: false, + isBuild: true + } + for (const id of deps) { let entry let requireEntry try { - entry = tryNodeResolve(id, undefined, root, false)?.id + entry = tryNodeResolve(id, undefined, resolveOptions)?.id requireEntry = require.resolve(id, { paths: [root] }) } catch (e) { // resolve failed, assume include diff --git a/yarn.lock b/yarn.lock index f8500fe122abf5..2d7ec7094260fc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2398,6 +2398,10 @@ css-color-names@^1.0.1: resolved "https://registry.yarnpkg.com/css-color-names/-/css-color-names-1.0.1.tgz#6ff7ee81a823ad46e020fa2fd6ab40a887e2ba67" integrity sha512-/loXYOch1qU1biStIFsHH8SxTmOseh1IJqFvy8IujXOm1h+QjUdDhkzOrR5HG8K8mlxREj0yfi8ewCHx0eMxzA== +"css-dep@link:./packages/playground/css/css-dep": + version "0.0.0" + uid "" + cssesc@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee" From 159cc799f19482da3626f906cde45accdf780823 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 4 Feb 2021 16:57:15 -0500 Subject: [PATCH 489/514] feat: support absolute glob patterns close #1875 --- docs/guide/features.md | 2 +- .../glob-import/__tests__/glob-import.spec.ts | 12 +++---- packages/playground/glob-import/index.html | 2 +- packages/vite/src/node/importGlob.ts | 32 ++++++++++++------- packages/vite/src/node/optimizer/scan.ts | 22 +++++++++---- .../vite/src/node/plugins/importAnalysis.ts | 23 ++++++------- .../src/node/plugins/importAnaysisBuild.ts | 8 ++++- 7 files changed, 63 insertions(+), 38 deletions(-) diff --git a/docs/guide/features.md b/docs/guide/features.md index 64d36cf437d53f..df0322d3ac419c 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -221,7 +221,7 @@ const modules = { Note that: - This is a Vite-only feature and is not a web or ES standard. -- The glob patterns must be relative and start with `.`. +- The glob patterns are treated like import specifiers: they must be either relative (start with `./`) or absolute (start with `/`, resolved relative to project root). Globbing from dependencies is not supported. - The glob matching is done via `fast-glob` - check out its documentation for [supported glob patterns](https://github.com/mrmlnc/fast-glob#pattern-syntax). ## Web Assembly diff --git a/packages/playground/glob-import/__tests__/glob-import.spec.ts b/packages/playground/glob-import/__tests__/glob-import.spec.ts index 987218d48bab43..15ffb4c7d97ede 100644 --- a/packages/playground/glob-import/__tests__/glob-import.spec.ts +++ b/packages/playground/glob-import/__tests__/glob-import.spec.ts @@ -30,14 +30,14 @@ const json = isBuild const allResult = { // JSON file should be properly transformed - './dir/baz.json': json, - './dir/foo.js': { + '/dir/baz.json': json, + '/dir/foo.js': { msg: 'foo' }, - './dir/index.js': { + '/dir/index.js': { modules: filteredResult }, - './dir/nested/bar.js': { + '/dir/nested/bar.js': { modules: { '../baz.json': json }, @@ -58,7 +58,7 @@ if (!isBuild) { () => page.textContent('.result'), JSON.stringify( { - './dir/a.js': {}, + '/dir/a.js': {}, ...allResult }, null, @@ -72,7 +72,7 @@ if (!isBuild) { () => page.textContent('.result'), JSON.stringify( { - './dir/a.js': { + '/dir/a.js': { msg: 'a' }, ...allResult diff --git a/packages/playground/glob-import/index.html b/packages/playground/glob-import/index.html index 541898db833426..b38a194e21b4f2 100644 --- a/packages/playground/glob-import/index.html +++ b/packages/playground/glob-import/index.html @@ -2,7 +2,7 @@ @@ -65,4 +74,16 @@ export default defineComponent({ a { color: #42b983; } - \ No newline at end of file + +label { + margin: 0 0.5em; + font-weight: bold; +} + +code { + background-color: #eee; + padding: 2px 4px; + border-radius: 4px; + color: #304455; +} + diff --git a/packages/create-app/template-vue-ts/src/main.ts b/packages/create-app/template-vue-ts/src/main.ts index 5f4a910f9bb0c4..01433bca2ac765 100644 --- a/packages/create-app/template-vue-ts/src/main.ts +++ b/packages/create-app/template-vue-ts/src/main.ts @@ -1,6 +1,4 @@ import { createApp } from 'vue' -// TypeScript error? Run VSCode command -// TypeScript: Select TypeScript version - > Use Workspace Version import App from './App.vue' createApp(App).mount('#app') diff --git a/packages/create-app/template-vue-ts/src/shims-vue.d.ts b/packages/create-app/template-vue-ts/src/shims-vue.d.ts new file mode 100644 index 00000000000000..ac1ded792334c2 --- /dev/null +++ b/packages/create-app/template-vue-ts/src/shims-vue.d.ts @@ -0,0 +1,5 @@ +declare module '*.vue' { + import { DefineComponent } from 'vue' + const component: DefineComponent<{}, {}, any> + export default component +} diff --git a/packages/create-app/template-vue-ts/tsconfig.json b/packages/create-app/template-vue-ts/tsconfig.json index e93a34d9aad938..e754e65292f1a0 100644 --- a/packages/create-app/template-vue-ts/tsconfig.json +++ b/packages/create-app/template-vue-ts/tsconfig.json @@ -6,11 +6,10 @@ "strict": true, "jsx": "preserve", "sourceMap": true, - "lib": ["esnext", "dom"], - "types": ["vite/client"], - "plugins": [{ "name": "@vuedx/typescript-plugin-vue" }], "resolveJsonModule": true, - "esModuleInterop": true + "esModuleInterop": true, + "lib": ["esnext", "dom"], + "types": ["vite/client"] }, "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"] } From 02653f0b93cacd0f1b3464204d24c0d57f407aa0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 Feb 2021 11:41:09 -0500 Subject: [PATCH 496/514] fix(build): ignore html asset urls that do not exist on disk fix #1885 --- packages/vite/src/node/plugins/html.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index 7400971c5a2dc0..67d6da7e6724c2 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -224,8 +224,17 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { // references the post-build location. for (const attr of assetUrls) { const value = attr.value! - const url = await urlToBuiltUrl(value.content, id, config, this) - s.overwrite(value.loc.start.offset, value.loc.end.offset, `"${url}"`) + try { + const url = await urlToBuiltUrl(value.content, id, config, this) + s.overwrite( + value.loc.start.offset, + value.loc.end.offset, + `"${url}"` + ) + } catch (e) { + // #1885 preload may be pointing to urls that do not exist + // locally on disk + } } processedHtml.set(id, s.toString()) From 98c9b32a395078bb6c042c07a938770c910d535d Mon Sep 17 00:00:00 2001 From: Matias Capeletto Date: Fri, 5 Feb 2021 17:44:39 +0100 Subject: [PATCH 497/514] docs: special queries, plugins vs features note (#1878) --- docs/guide/assets.md | 27 ++++++++++++++++++++++++++- docs/guide/features.md | 22 ++++++++++++++++++++++ docs/plugins/index.md | 4 ++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/docs/guide/assets.md b/docs/guide/assets.md index 23e9f0329dc6c0..e76b642d08657f 100644 --- a/docs/guide/assets.md +++ b/docs/guide/assets.md @@ -28,13 +28,38 @@ The behavior is similar to webpack's `file-loader`. The difference is that the i ### Explicit URL Imports -Assets that are not included in the internal list or in `assetsInclude`, can be manually imported as an URL using the `?url` suffix. This is useful, for example, to import [Houdini Paint Worklets](https://houdini.how/usage). +Assets that are not included in the internal list or in `assetsInclude`, can be explicitly imported as an URL using the `?url` suffix. This is useful, for example, to import [Houdini Paint Worklets](https://houdini.how/usage). ```js import workletURL from 'extra-scalloped-border/worklet.js?url' CSS.paintWorklet.addModule(workletURL) ``` +### Importing Asset as String + +Assets can be imported as strings using the `?raw` suffix. + +```js +import shaderString from './shader.glsl?raw' +``` + +### Importing Script as a Worker + +Scripts can be imported as web workers with the `?worker` suffix. + +```js +// Separate chunk in the production build +import Worker from './shader.js?worker' +const worker = new Worker() +``` + +```js +// Inlined as base64 strings +import InlineWorker from './shader.js?worker&inline' +``` + +Check out the [Web Worker section](./features.md#web-workers) for more details. + ## The `public` Directory If you have assets that are: diff --git a/docs/guide/features.md b/docs/guide/features.md index 7d40d516f3c724..c0bc5d32004223 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -167,6 +167,28 @@ import imgUrl from './img.png' document.getElementById('hero-img').src = imgUrl ``` +Special queries can modify how assets are loaded: + +```js +// Explicitly load assets as URL +import assetAsURL from './asset.js?url' +``` + +```js +// Load assets as strings +import assetAsString from './shader.glsl?raw' +``` + +```js +// Load Web Workers +import Worker from './worker.js?worker' +``` + +```js +// Web Workers inlined as base64 strings at build time +import InlineWorker from './worker.js?worker&inline' +``` + More details in [Static Asset Handling](./assets). ## JSON diff --git a/docs/plugins/index.md b/docs/plugins/index.md index 8f5d0c1ef82be7..65a157716f5161 100644 --- a/docs/plugins/index.md +++ b/docs/plugins/index.md @@ -1,5 +1,9 @@ # Plugins +:::tip NOTE +Vite aims to provide out-of-the-box support for common web development patterns. Before searching for a Vite or Compatible Rollup plugin, check out the [Features Guide](../guide/features.md). A lot of the cases where a plugin would be needed in a Rollup project are already covered in Vite. +::: + ## Official Plugins ### [@vitejs/plugin-vue](https://github.com/vitejs/vite/tree/main/packages/plugin-vue) From 9c819b9ed7ecca3b662471ae90e94ee972d7b761 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 Feb 2021 11:42:16 -0500 Subject: [PATCH 498/514] refactor: only ignore error if is ENOENT --- packages/vite/src/node/plugins/html.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index 67d6da7e6724c2..592805ce38a05a 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -234,6 +234,9 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { } catch (e) { // #1885 preload may be pointing to urls that do not exist // locally on disk + if (e.code !== 'ENOENT') { + throw e + } } } From e81a118735045a40f0ab93c1bedef5b7d674f2f0 Mon Sep 17 00:00:00 2001 From: cisen Date: Sat, 6 Feb 2021 01:02:42 +0800 Subject: [PATCH 499/514] feat(proxy): support conditional options for proxy request (#1888) ...by returning an options object from the `bypass` function. --- packages/vite/src/node/server/middlewares/proxy.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/middlewares/proxy.ts b/packages/vite/src/node/server/middlewares/proxy.ts index de72cfeb638e14..7c40f4609d0899 100644 --- a/packages/vite/src/node/server/middlewares/proxy.ts +++ b/packages/vite/src/node/server/middlewares/proxy.ts @@ -85,6 +85,7 @@ export function proxyMiddleware({ url.startsWith(context) ) { const [proxy, opts] = proxies[context] + const proxyOpitons: HttpProxy.ServerOptions = {} if (opts.bypass) { const bypassResult = opts.bypass(req, res, opts) @@ -92,6 +93,10 @@ export function proxyMiddleware({ req.url = bypassResult debug(`bypass: ${req.url} -> ${bypassResult}`) return next() + } else if (typeof bypassResult === 'object') { + Object.assign(proxyOpitons, bypassResult) + debug(`bypass: ${req.url} use modified opitions: %O`, proxyOpitons) + return next() } else if (bypassResult === false) { debug(`bypass: ${req.url} -> 404`) return res.end(404) @@ -102,7 +107,7 @@ export function proxyMiddleware({ if (opts.rewrite) { req.url = opts.rewrite(req.url!) } - proxy.web(req, res) + proxy.web(req, res, proxyOpitons) return } } From f43b420ac21d0a73d79175aaaaa20f68949c0fb3 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 Feb 2021 12:12:18 -0500 Subject: [PATCH 500/514] release: v2.0.0-beta.65 --- packages/vite/CHANGELOG.md | 39 ++++++++++++++++++++++++++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index b90bc98ab7fc08..edf28135fa2190 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,42 @@ +# [2.0.0-beta.65](https://github.com/vitejs/vite/compare/v2.0.0-beta.64...v2.0.0-beta.65) (2021-02-05) + + +### Bug Fixes + +* **build:** ignore html asset urls that do not exist on disk ([02653f0](https://github.com/vitejs/vite/commit/02653f0b93cacd0f1b3464204d24c0d57f407aa0)), closes [#1885](https://github.com/vitejs/vite/issues/1885) +* better dependency non-js type file handling ([1fdc710](https://github.com/vitejs/vite/commit/1fdc710a391b968f85f6a150dc06e51e53742b02)) +* **dev:** check wasClean in onclose event ([#1872](https://github.com/vitejs/vite/issues/1872)) ([5d3107a](https://github.com/vitejs/vite/commit/5d3107a4a787929810fbfaef37bf3002aa0bcc17)) +* **resolve:** prioritize file over dir with same name for resolve ([c741872](https://github.com/vitejs/vite/commit/c741872e6ca975f507ec89581b742a1da19a0cb0)), closes [#1871](https://github.com/vitejs/vite/issues/1871) +* **ssr:** respect user defines for ssr ([3fad3ba](https://github.com/vitejs/vite/commit/3fad3ba861fb56edd22941db645f2d73b02bf7b1)) +* do not include vite in ssr externals ([578c591](https://github.com/vitejs/vite/commit/578c591ffe7b7c1ffa68e711a7df043afe013daa)), closes [#1865](https://github.com/vitejs/vite/issues/1865) + + +### Code Refactoring + +* **css:** use default CSS modules localsConvention settings ([fee7393](https://github.com/vitejs/vite/commit/fee739325fd4dbf7f6d842c205608e39271db513)) + + +### Features + +* **cli:** make --ssr flag value optional ([3c7b652](https://github.com/vitejs/vite/commit/3c7b652f24fdb5e67c5f56db3cea0769bcd9263b)), closes [#1877](https://github.com/vitejs/vite/issues/1877) +* **proxy:** support conditional options for proxy request ([#1888](https://github.com/vitejs/vite/issues/1888)) ([e81a118](https://github.com/vitejs/vite/commit/e81a118735045a40f0ab93c1bedef5b7d674f2f0)) +* support absolute glob patterns ([159cc79](https://github.com/vitejs/vite/commit/159cc799f19482da3626f906cde45accdf780823)), closes [#1875](https://github.com/vitejs/vite/issues/1875) +* support resolving style/sass entries in css [@import](https://github.com/import) ([f90a85c](https://github.com/vitejs/vite/commit/f90a85c2ba8c9ba215fe75c49035a7e38fa81a7d)), closes [#1874](https://github.com/vitejs/vite/issues/1874) + + +### Performance Improvements + +* improve resolve cache ([6a793d3](https://github.com/vitejs/vite/commit/6a793d319cf7adab061b056692c331a9d66fdac5)) + + +### BREAKING CHANGES + +* **css:** CSS modules now defaults to export class names as-is. +To get camelCase exports like before, explictly set +`css.modules.localsConvention` via config. + + + # [2.0.0-beta.64](https://github.com/vitejs/vite/compare/v2.0.0-beta.63...v2.0.0-beta.64) (2021-02-03) diff --git a/packages/vite/package.json b/packages/vite/package.json index 6be285853b2d93..9dbac83cb154c1 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.0.0-beta.64", + "version": "2.0.0-beta.65", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 6869d0e6fb81cf500d22da4c378d2b8cf1e8069a Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 Feb 2021 12:23:38 -0500 Subject: [PATCH 501/514] docs: logo + favicon --- docs/.vitepress/config.js | 2 ++ docs/.vitepress/theme/custom.css | 9 +++++++++ docs/.vitepress/theme/index.js | 1 + docs/public/logo.svg | 10 +++++----- 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 docs/.vitepress/theme/custom.css diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index 594940297f6855..7d67483b9634e7 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -7,6 +7,7 @@ module.exports = { title: 'Vite', description: 'Next Generation Frontend Tooling', head: [ + ['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }], [ 'style', {}, @@ -15,6 +16,7 @@ module.exports = { ], themeConfig: { repo: 'vitejs/vite', + logo: '/logo.svg', docsDir: 'docs', docsBranch: 'main', editLinks: true, diff --git a/docs/.vitepress/theme/custom.css b/docs/.vitepress/theme/custom.css new file mode 100644 index 00000000000000..6150e6da3f118c --- /dev/null +++ b/docs/.vitepress/theme/custom.css @@ -0,0 +1,9 @@ +.home-hero .image { + width: 200px; + height: 200px; +} + +.nav-bar .logo { + height: 30px; + margin-right: 2px; +} \ No newline at end of file diff --git a/docs/.vitepress/theme/index.js b/docs/.vitepress/theme/index.js index fe497ebfa4bb30..d5953e9997e09f 100644 --- a/docs/.vitepress/theme/index.js +++ b/docs/.vitepress/theme/index.js @@ -2,6 +2,7 @@ import Theme from 'vitepress/theme' import { h } from 'vue' import sponsors from './sponsors.json' import './sponsors.css' +import './custom.css' export default { ...Theme, diff --git a/docs/public/logo.svg b/docs/public/logo.svg index 7ffb40be702721..de4aeddc12bdfe 100644 --- a/docs/public/logo.svg +++ b/docs/public/logo.svg @@ -1,12 +1,12 @@ - - - + + + - + - + From a3de585be31304e9795eb00e9e0be61153ddd466 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 Feb 2021 12:33:26 -0500 Subject: [PATCH 502/514] docs: style tweaks --- docs/.vitepress/theme/custom.css | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/.vitepress/theme/custom.css b/docs/.vitepress/theme/custom.css index 6150e6da3f118c..ec6a9db3d1f617 100644 --- a/docs/.vitepress/theme/custom.css +++ b/docs/.vitepress/theme/custom.css @@ -6,4 +6,17 @@ .nav-bar .logo { height: 30px; margin-right: 2px; -} \ No newline at end of file +} + +:root { + --c-brand: #646cff; + --c-brand-light: #747bff; +} + +.custom-block.tip { + border-color: var(--c-brand-light); +} + +.DocSearch { + --docsearch-primary-color: var(--c-brand) !important; +} From 87f0009fe279133ff7421babaf29a49f988cabd9 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 Feb 2021 13:15:03 -0500 Subject: [PATCH 503/514] release: create-app@1.6.0 --- packages/create-app/CHANGELOG.md | 14 ++++++++++++++ packages/create-app/package.json | 2 +- .../template-lit-element-ts/package.json | 2 +- .../create-app/template-lit-element/package.json | 2 +- .../create-app/template-preact-ts/package.json | 2 +- packages/create-app/template-preact/package.json | 2 +- packages/create-app/template-react-ts/package.json | 2 +- packages/create-app/template-react/package.json | 2 +- packages/create-app/template-vanilla/package.json | 2 +- packages/create-app/template-vue-ts/package.json | 2 +- packages/create-app/template-vue/package.json | 2 +- 11 files changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/create-app/CHANGELOG.md b/packages/create-app/CHANGELOG.md index 8e881f10cb2a8d..49e3c5506eefa4 100644 --- a/packages/create-app/CHANGELOG.md +++ b/packages/create-app/CHANGELOG.md @@ -1,3 +1,17 @@ +# [1.6.0](https://github.com/vitejs/vite/compare/create-app@1.5.2...create-app@1.6.0) (2021-02-05) + + +### Bug Fixes + +* **create-app:** add resolveJsonModule to tsconfig.json for vue-ts template ([#1879](https://github.com/vitejs/vite/issues/1879)) ([2c914a5](https://github.com/vitejs/vite/commit/2c914a5b728d0c130f1e5b73c7b0ab0eedc1cda5)) + + +### Features + +* **create-app:** clearer vue-ts setup recommend ([#1896](https://github.com/vitejs/vite/issues/1896)) [skip ci] ([d6bf066](https://github.com/vitejs/vite/commit/d6bf066e3a18b749bed1a7fc622dd2551404e29f)) + + + ## [1.5.2](https://github.com/vitejs/vite/compare/create-app@1.5.1...create-app@1.5.2) (2021-02-03) diff --git a/packages/create-app/package.json b/packages/create-app/package.json index a971ac3d215f84..1fbf103a340e23 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/create-app", - "version": "1.5.2", + "version": "1.6.0", "license": "MIT", "author": "Evan You", "bin": { diff --git a/packages/create-app/template-lit-element-ts/package.json b/packages/create-app/template-lit-element-ts/package.json index acb41b71adc22c..319d2a3889236d 100644 --- a/packages/create-app/template-lit-element-ts/package.json +++ b/packages/create-app/template-lit-element-ts/package.json @@ -18,7 +18,7 @@ "lit-element": "^2.4.0" }, "devDependencies": { - "vite": "^2.0.0-beta.64", + "vite": "^2.0.0-beta.65", "typescript": "^4.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-lit-element/package.json b/packages/create-app/template-lit-element/package.json index 605d5c18057d0e..5fed563887353b 100644 --- a/packages/create-app/template-lit-element/package.json +++ b/packages/create-app/template-lit-element/package.json @@ -16,6 +16,6 @@ "lit-element": "^2.4.0" }, "devDependencies": { - "vite": "^2.0.0-beta.64" + "vite": "^2.0.0-beta.65" } } \ No newline at end of file diff --git a/packages/create-app/template-preact-ts/package.json b/packages/create-app/template-preact-ts/package.json index 60c1696013ac71..870a1802826f4a 100644 --- a/packages/create-app/template-preact-ts/package.json +++ b/packages/create-app/template-preact-ts/package.json @@ -12,6 +12,6 @@ "devDependencies": { "@prefresh/vite": "^2.0.0", "typescript": "^4.1.3", - "vite": "^2.0.0-beta.64" + "vite": "^2.0.0-beta.65" } } \ No newline at end of file diff --git a/packages/create-app/template-preact/package.json b/packages/create-app/template-preact/package.json index b66820a03e124b..73f0717fd5177d 100644 --- a/packages/create-app/template-preact/package.json +++ b/packages/create-app/template-preact/package.json @@ -11,6 +11,6 @@ }, "devDependencies": { "@prefresh/vite": "^2.0.0", - "vite": "^2.0.0-beta.64" + "vite": "^2.0.0-beta.65" } } \ No newline at end of file diff --git a/packages/create-app/template-react-ts/package.json b/packages/create-app/template-react-ts/package.json index 5255abe0b68abd..740d9351bdef9d 100644 --- a/packages/create-app/template-react-ts/package.json +++ b/packages/create-app/template-react-ts/package.json @@ -15,6 +15,6 @@ "@types/react-dom": "^17.0.0", "@vitejs/plugin-react-refresh": "^1.1.0", "typescript": "^4.1.2", - "vite": "^2.0.0-beta.64" + "vite": "^2.0.0-beta.65" } } \ No newline at end of file diff --git a/packages/create-app/template-react/package.json b/packages/create-app/template-react/package.json index 1996fc2455de9a..8ee1e6f5c48785 100644 --- a/packages/create-app/template-react/package.json +++ b/packages/create-app/template-react/package.json @@ -12,6 +12,6 @@ }, "devDependencies": { "@vitejs/plugin-react-refresh": "^1.1.0", - "vite": "^2.0.0-beta.64" + "vite": "^2.0.0-beta.65" } } \ No newline at end of file diff --git a/packages/create-app/template-vanilla/package.json b/packages/create-app/template-vanilla/package.json index 4fc9233eedb765..2a7be0f7258d93 100644 --- a/packages/create-app/template-vanilla/package.json +++ b/packages/create-app/template-vanilla/package.json @@ -7,6 +7,6 @@ "serve": "vite preview" }, "devDependencies": { - "vite": "^2.0.0-beta.64" + "vite": "^2.0.0-beta.65" } } \ No newline at end of file diff --git a/packages/create-app/template-vue-ts/package.json b/packages/create-app/template-vue-ts/package.json index 87fbf4b8277823..3b849722478d28 100644 --- a/packages/create-app/template-vue-ts/package.json +++ b/packages/create-app/template-vue-ts/package.json @@ -15,6 +15,6 @@ "@vuedx/typecheck": "^0.6.0", "@vuedx/typescript-plugin-vue": "^0.6.0", "typescript": "^4.1.3", - "vite": "^2.0.0-beta.64" + "vite": "^2.0.0-beta.65" } } \ No newline at end of file diff --git a/packages/create-app/template-vue/package.json b/packages/create-app/template-vue/package.json index 172d84a1e60ee3..e93941db3dbf9e 100644 --- a/packages/create-app/template-vue/package.json +++ b/packages/create-app/template-vue/package.json @@ -12,6 +12,6 @@ "devDependencies": { "@vitejs/plugin-vue": "^1.1.4", "@vue/compiler-sfc": "^3.0.5", - "vite": "^2.0.0-beta.64" + "vite": "^2.0.0-beta.65" } } \ No newline at end of file From 927310621cb972d1bb8b843b7b39baf885ddc3fd Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 Feb 2021 13:52:17 -0500 Subject: [PATCH 504/514] chore: typo [skip ci] --- packages/vite/src/node/server/middlewares/proxy.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/server/middlewares/proxy.ts b/packages/vite/src/node/server/middlewares/proxy.ts index 7c40f4609d0899..16b352e78f1cca 100644 --- a/packages/vite/src/node/server/middlewares/proxy.ts +++ b/packages/vite/src/node/server/middlewares/proxy.ts @@ -85,7 +85,7 @@ export function proxyMiddleware({ url.startsWith(context) ) { const [proxy, opts] = proxies[context] - const proxyOpitons: HttpProxy.ServerOptions = {} + const options: HttpProxy.ServerOptions = {} if (opts.bypass) { const bypassResult = opts.bypass(req, res, opts) @@ -94,8 +94,8 @@ export function proxyMiddleware({ debug(`bypass: ${req.url} -> ${bypassResult}`) return next() } else if (typeof bypassResult === 'object') { - Object.assign(proxyOpitons, bypassResult) - debug(`bypass: ${req.url} use modified opitions: %O`, proxyOpitons) + Object.assign(options, bypassResult) + debug(`bypass: ${req.url} use modified opitions: %O`, options) return next() } else if (bypassResult === false) { debug(`bypass: ${req.url} -> 404`) @@ -107,7 +107,7 @@ export function proxyMiddleware({ if (opts.rewrite) { req.url = opts.rewrite(req.url!) } - proxy.web(req, res, proxyOpitons) + proxy.web(req, res, options) return } } From 2cb5afc25dde9fc2c6b4bb6c3f669f064a3dc76b Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 Feb 2021 15:41:06 -0500 Subject: [PATCH 505/514] docs: remove stale style tag --- docs/.vitepress/config.js | 9 +-------- docs/.vitepress/theme/custom.css | 4 ++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index 7d67483b9634e7..4b01c19ea08c02 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -6,14 +6,7 @@ module.exports = { title: 'Vite', description: 'Next Generation Frontend Tooling', - head: [ - ['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }], - [ - 'style', - {}, - '.content img { border-radius: 10px }' + 'h1.title { margin-left: 0.5em }' - ] - ], + head: [['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }]], themeConfig: { repo: 'vitejs/vite', logo: '/logo.svg', diff --git a/docs/.vitepress/theme/custom.css b/docs/.vitepress/theme/custom.css index ec6a9db3d1f617..84be730b55b30c 100644 --- a/docs/.vitepress/theme/custom.css +++ b/docs/.vitepress/theme/custom.css @@ -8,6 +8,10 @@ margin-right: 2px; } +.content img { + border-radius: 10px; +} + :root { --c-brand: #646cff; --c-brand-light: #747bff; From b18eaad614929fa70cc66b58dd5185400cdad63a Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 Feb 2021 17:10:31 -0500 Subject: [PATCH 506/514] docs: rewrite introduction --- docs/guide/introduction.md | 44 ++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/docs/guide/introduction.md b/docs/guide/introduction.md index c5defbe875a7c9..1605c80d3a0995 100644 --- a/docs/guide/introduction.md +++ b/docs/guide/introduction.md @@ -4,35 +4,47 @@ Vite (French word for "fast", pronounced `/vit/`) is a new breed of frontend build tool that significantly improves the frontend development experience. It consists of two major parts: -- A dev server that serves your source files over [native ES modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), with [rich built-in features](./features) and astonishingly fast [Hot Module Replacement (HMR)](./features#hot-module-replacement). +- A dev server that provides [rich feature enhancements](./features) over [native ES modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), for example extremely fast [Hot Module Replacement (HMR)](./features#hot-module-replacement). -- A [build command](./build) that bundles your code with [Rollup](https://rollupjs.org), pre-configured to output highly optimized static assets for production. +- An opinionated [build command](./build) that bundles your code with [Rollup](https://rollupjs.org), pre-configured to output highly optimized static assets for production. In addition, Vite is highly extensible via its [Plugin API](./api-plugin) and [JavaScript API](./api-javascript) with full typing support. -## Why native ESM +## The Problem -Today most JavaScript developers are familiar with the following ES modules syntax: +Before ES modules were available in browsers, developers had no native mechanism for authoring JavaScript in a modularized fashion. This is why we are all familiar with the concept of "bundling": using tools that crawl, process and concatenate our source modules into files that can run in the browser. -```js -import { foo } from './other-module' -``` +Over time we have seen tools like [webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org) and [Parcel](https://parceljs.org/), which greatly improved the development experience for frontend developers. -This syntax already has [wide native support in major browsers](https://caniuse.com/es6-module). However, before browsers had native support for ES modules, we had to rely on bundlers (Browserify, webpack, Parcel or Rollup) to combine all our module source code into a single file so that it can be served by the browser, even during development. +However, as we start to build more and more ambitious applications, the amount of JavaScript we are dealing with also increased exponentially. It is not uncommon for large scale projects to contain thousands of modules. We are starting to hit a performance bottleneck for JavaScript based tooling: it can often take an unreasonably long wait (sometimes up to minutes!) to spin up a dev server, and even with HMR, file edits can take a couple seconds to be reflected in the browser. The slow feedback loop can greatly affect developers' productivity and happiness. -There are two downsides to bundling during development: +Vite aims to address these issues by leveraging new advancements in the ecosystem: the availability of native ES modules in the browser, and the rise of JavaScript tools written in compile-to-native languages. -- **Slow server start:** When starting the dev server, the bundler always eagerly crawls your entire application, even when there are code-split points present. For example, in an application with a dozen routes where each route is lazy loaded, you still have to wait for the bundler to process every single file in your app before you can start working on a single route page. +### Slow Server Start - ![bundler based dev server](/images/bundler.png) +When cold-starting the dev server, a bundler-based build setup has to eagerly crawl and build your entire application before it can be served. + +Vite improves the dev server start time by first deviding the modules in an application into two categories: **dependencies** and **source code**. + +- **Dependencies** are mostly plain JavaScript that do not change often during development. Some large dependencies (e.g. component libraries with hundreds of modules) are also quite expensive to process. Dependencies may also be shipped in various module formats (e.g. ESM or CommonJS). + + Vite [pre-bundles dependencies](./dep-pre-bundling) using [esbuild](https://esbuild.github.io/). Esbuild is written in Go and pre-bundles dependencies 10-100x faster than JavaScript-based bundlers. + +- **Source code** often contains non-plain JavaScript that needs transforming (e.g. JSX, CSS or Vue/Svelete components), and will be edited very often. Also, not all source code needs to be loaded at the same time (e.g. with route-based code-splitting). - **How Vite solves it:** There's no preparation work to be done on server start - Vite simply compiles and serves the files on-demand as the requests come in from the browser. In code-split applications, only modules used by the current route page needs to be served. + Vite serves source code over [native ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). This is essentially letting the browser taking over part of the job of a bundler: Vite only needs to transform and serve source code on demand, as the browser requests them. Code behind conditional dynamic imports are only processed if actually used on the current screen. + + ![bundler based dev server](/images/bundler.png) ![esm based dev server](/images/esm.png) -- **Slow updates:** When a file is edited, in addition to re-building the file itself, the bundler also needs to invalidate part of its module graph and re-construct the entire bundle. This means the feedback speed between saving a file and seeing the changes reflected in the browser deteriorates linearly as the size of your application grows. In large applications, this bundle re-construction step can become prohibitively expensive even with Hot Module Replacement enabled. +### Slow Updates + +When a file is edited in a bundler-based build setup, in addition to re-building the file itself, the bundler also needs to invalidate part of its module graph and re-construct the entire bundle. Reconstructing the bundle can be expensive, and reloading the page blows away the current state of the application. This is why some bundlers support Hot Module Replacment (HMR): allowing a module to "hot replace" itself without affecting the rest of the page. This greatly improves DX - however, in practice we've found that even HMR update speed deteriorates significantly as the size of the application grows. + +In Vite, HMR is performed over native ESM. When a file is edited, Vite only needs to precisely invalidate the chain between the edited module and its closesest HMR boundary (most of the time only the module itself), making HMR updates consistently fast regardless of the size of your application. - **How Vite solves it:** Every served file is cached via HTTP headers (304 Not Modified whenever possible) and, if browser cache is disabled, Vite's in-memory cache. On file edits, we simply invalidate the cache for that file. In addition, [Hot Module Replacement](./features#hot-module-replacement) over native ESM only needs to precisely re-fetch the invalidated modules, making it consistently fast regardless of the size of your application. +Vite also leverages HTTP headers to speed up full page reloads (again, let the browser do more work for us): source code module requests are made conditional via `304 Not Modified`, and dependency module requests are strongly cached via `Cache-Control: max-age=31536000,immutable` so they don't hit the server again once cached. Once you experience how fast Vite is, we highly doubt you'd be willing to put up with bundled development again. @@ -40,10 +52,10 @@ Once you experience how fast Vite is, we highly doubt you'd be willing to put up Even though native ESM is now widely supported, shipping unbundled ESM in production is still inefficient (even with HTTP/2) due to the additional network round trips caused by nested imports. To get the optimal loading performance in production, it is still better to bundle your code with tree-shaking, lazy-loading and common chunk splitting (for better caching). -Ensuring optimal output and behavioral consistency between the dev server and the production build isn't easy. This is why Vite ships with a pre-configured [build command](./build) that does this out of the box. +Ensuring optimal output and behavioral consistency between the dev server and the production build isn't easy. This is why Vite ships with a pre-configured [build command](./build) that bakes in many [performance optimizations](.features#build-optimizations) out of the box. ## Browser Support - Vite requires [native ESM dynamic import support](https://caniuse.com/es6-module-dynamic-import) during development. -- The production build assumes a baseline support for [native ESM via script tags](https://caniuse.com/es6-module), and legacy browsers can be supported via an official plugin. See the [Building for Production](./build) section for more details. +- The production build assumes a baseline support for [native ESM via script tags](https://caniuse.com/es6-module). Vite does **not** perform any compatibility transpilation by default. Legacy browsers can be supported via the official [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) - see the [Building for Production](./build) section for more details. From 814c5d34d00f368c8b02ed7f461c4a27781907d8 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 Feb 2021 17:40:19 -0500 Subject: [PATCH 507/514] docs: add link to comparisons in intro --- docs/guide/introduction.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/guide/introduction.md b/docs/guide/introduction.md index 1605c80d3a0995..d31994fab5d2cc 100644 --- a/docs/guide/introduction.md +++ b/docs/guide/introduction.md @@ -59,3 +59,7 @@ Ensuring optimal output and behavioral consistency between the dev server and th - Vite requires [native ESM dynamic import support](https://caniuse.com/es6-module-dynamic-import) during development. - The production build assumes a baseline support for [native ESM via script tags](https://caniuse.com/es6-module). Vite does **not** perform any compatibility transpilation by default. Legacy browsers can be supported via the official [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) - see the [Building for Production](./build) section for more details. + +## How is Vite Different from X? + +You can check out the [Comparisons](./comparisons) section for more details on how Vite differs from other similar tools. From da997386e2b377f9480f2ed415c6d56aa752e1bc Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 Feb 2021 18:28:04 -0500 Subject: [PATCH 508/514] docs: update the comparison section --- docs/guide/comparisons.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/guide/comparisons.md b/docs/guide/comparisons.md index a1880a77397c1f..7474465c3592c8 100644 --- a/docs/guide/comparisons.md +++ b/docs/guide/comparisons.md @@ -4,11 +4,11 @@ [Snowpack](https://www.snowpack.dev/) is also a no-bundle native ESM dev server that is very similar in scope to Vite. Aside from different implementation details, the two projects share a lot in terms of technical advantages over traditional tooling. Vite's dependency pre-bundling is also inspired by Snowpack v1 (now [`esinstall`](https://github.com/snowpackjs/snowpack/tree/main/esinstall)). Some of the main differences between the two projects are: -**Production Build Handling** +**Production Build** -Snowpack's default build output is unbundled: it transforms each file into separate built modules, which can then be fed into different "optimizers" that perform the actual bundling. The benefit of this is that you can choose between different end-bundlers (e.g. webpack, Rollup, or even ESbuild), the downside is that it's a bit of a fragmented experience - for example, the `esbuild` optimizer is still unstable, the Rollup optimizer is not officially maintained, and different optimizers have different output and configurations. +Snowpack's default build output is unbundled: it transforms each file into separate built modules, which can then be fed into different "optimizers" that perform the actual bundling. The benefit of this is that you can choose between different end-bundlers to fit specific needs (e.g. webpack, Rollup, or even esbuild), the downside is that it's a bit of a fragmented experience - for example, the esbuild optimizer is still unstable, the Rollup optimizer is not officially maintained, and different optimizers have different output and configurations. -Vite opts to have a deeper integration with one single bundler (Rollup) in order to provide a more streamlined experience. The reason for going with Rollup is because we believe for the foreseeable future, Rollup offers the best balance between maturity, extensibility, build speed, and output bundle size. It also allows Vite to support a [Universal Plugin API](./api-plugin) that works for both dev and build. +Vite opts to have a deeper integration with one single bundler (Rollup) in order to provide a more streamlined experience. It also allows Vite to support a [Universal Plugin API](./api-plugin) that works for both dev and build. Due to a more integrated build process, Vite supports a wide range of features that are currently not available in Snowpack build optimizers: @@ -19,6 +19,10 @@ Due to a more integrated build process, Vite supports a wide range of features t - [Automatic dynamic import polyfill](./features#dynamic-import-polyfill) - Official [legacy mode plugin](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) that generates dual modern/legacy bundles and auto delivers the right bundle based on browser support. +**Faster Dependency Pre-Bundling** + +Vite uses [esbuild](https://esbuild.github.io/) instead of Rollup for dependency pre-bundling. This results in significant performance improvements in terms of cold server start and re-bundling on dependency invalidations. + **Monorepo Support** Vite is designed to handle monorepo setups and we have users successfully using it with Yarn, Yarn 2, and PNPM based monorepos. @@ -37,6 +41,6 @@ WMR is mainly designed for [Preact](https://preactjs.com/) projects, and offers [@web/dev-server](https://modern-web.dev/docs/dev-server/overview/) (previously `es-dev-server`) is a great project and Vite 1.0's Koa-based server setup was inspired by it. -`@web/dev-server` is a bit lower-level in terms of scope. It does not provide out-of-the-box framework integrations, and requires manually setting up a Rollup configuration for the production build. However, its parent project does provide a collection of excellent Rollup plugins. +`@web/dev-server` is a bit lower-level in terms of scope. It does not provide official framework integrations, and requires manually setting up a Rollup configuration for the production build. -Overall, Vite is a more opinionated / higher-level tool that aims to provide a more streamlined workflow compared to `@web/dev-server`. That said, the `@web` umbrella project contains many other excellent tools that may benefit Vite users as well. +Overall, Vite is a more opinionated / higher-level tool that aims to provide a more out-of-the-box workflow. That said, the `@web` umbrella project contains many other excellent tools that may benefit Vite users as well. From 6e0cd8e5f5d9e2f40a82520db9f41b1e8c333d14 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 Feb 2021 18:38:57 -0500 Subject: [PATCH 509/514] docs: more comparison --- docs/guide/comparisons.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/guide/comparisons.md b/docs/guide/comparisons.md index 7474465c3592c8..f68319696a986e 100644 --- a/docs/guide/comparisons.md +++ b/docs/guide/comparisons.md @@ -27,6 +27,10 @@ Vite uses [esbuild](https://esbuild.github.io/) instead of Rollup for dependency Vite is designed to handle monorepo setups and we have users successfully using it with Yarn, Yarn 2, and PNPM based monorepos. +**CSS Pre-Processor Support** + +Vite provides more refined support for Sass and Less, including improved `@import` resolution (aliases and npm dependencies) and [automatic `url()` rebasing for inlined files](./features#import-inlining-and-rebasing). + **First Class Vue Support** Vite was initially created to serve as the future foundation of [Vue.js](https://vuejs.org/) tooling. Although as of 2.0 Vite is now fully framework-agnostic, the official Vue plugin still provides first-class support for Vue's Single File Component format, covering all advanced features such as template asset reference resolving, `

tsconfig setup:
1. Install and add - @vuex/typescript-plugin-vue to tsconfig plugins + @vuedx/typescript-plugin-vue to tsconfig plugins
2. Delete shims-vue.d.ts
3. Open src/main.ts in VSCode From f5cd959b8f1c7af8c282858abcfcd5008f8063a6 Mon Sep 17 00:00:00 2001 From: Matias Capeletto Date: Sun, 7 Feb 2021 19:33:55 +0100 Subject: [PATCH 511/514] docs(create-app): add link to script setup RFC (#1913) --- packages/create-app/template-vue/src/App.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/create-app/template-vue/src/App.vue b/packages/create-app/template-vue/src/App.vue index 9a72bd98acdc9f..e9748276d24a0b 100644 --- a/packages/create-app/template-vue/src/App.vue +++ b/packages/create-app/template-vue/src/App.vue @@ -5,6 +5,9 @@