Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use esbuild supported feature #8665

Merged
merged 8 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@typescript-eslint/parser": "^5.28.0",
"conventional-changelog-cli": "^2.2.2",
"cross-env": "^7.0.3",
"esbuild": "^0.14.43",
"esbuild": "^0.14.47",
"eslint": "^8.18.0",
"eslint-define-config": "^1.5.1",
"eslint-plugin-import": "^2.26.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
"dependencies": {
"esbuild": "^0.14.43",
"esbuild": "^0.14.47",
"postcss": "^8.4.14",
"resolve": "^1.22.1",
"rollup": "^2.75.6"
Expand Down
12 changes: 2 additions & 10 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { loadFallbackPlugin } from './plugins/loadFallback'
import type { PackageData } from './packages'
import { watchPackageDataPlugin } from './packages'
import { ensureWatchPlugin } from './plugins/ensureWatch'
import { VERSION } from './constants'
import { ESBUILD_MODULES_TARGET, VERSION } from './constants'

export interface BuildOptions {
/**
Expand Down Expand Up @@ -270,15 +270,7 @@ export function resolveBuildOptions(

// handle special build targets
if (resolved.target === 'modules') {
// Support browserslist
// "defaults and supports es6-module and supports es6-module-dynamic-import",
resolved.target = [
'es2020', // support import.meta.url
'edge88',
'firefox78',
'chrome87',
'safari13' // transpile nullish coalescing
]
resolved.target = ESBUILD_MODULES_TARGET
} else if (resolved.target === 'esnext' && resolved.minify === 'terser') {
// esnext + terser: limit to es2021 so it can be minified by terser
resolved.target = 'es2021'
Expand Down
10 changes: 10 additions & 0 deletions packages/vite/src/node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ export const DEFAULT_MAIN_FIELDS = [
'jsnext'
]

// Support browserslist
// "defaults and supports es6-module and supports es6-module-dynamic-import",
export const ESBUILD_MODULES_TARGET = [
'es2020', // support import.meta.url
'edge88',
'firefox78',
'chrome87',
'safari13' // transpile nullish coalescing
]

export const DEFAULT_EXTENSIONS = [
'.mjs',
'.js',
Expand Down
10 changes: 8 additions & 2 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
writeFile
} from '../utils'
import { transformWithEsbuild } from '../plugins/esbuild'
import { ESBUILD_MODULES_TARGET } from '../constants'
import { esbuildDepPlugin } from './esbuildDepPlugin'
import { scanImports } from './scan'
export { initDepsOptimizer, getDepsOptimizer } from './optimizer'
Expand Down Expand Up @@ -559,7 +560,7 @@ export async function runOptimizeDeps(
: 'browser',
define,
format: 'esm',
target: config.build.target || undefined,
target: isBuild ? config.build.target || undefined : ESBUILD_MODULES_TARGET,
external: config.optimizeDeps?.exclude,
logLevel: 'error',
splitting: true,
Expand All @@ -571,7 +572,12 @@ export async function runOptimizeDeps(
...plugins,
esbuildDepPlugin(flatIdDeps, flatIdToExports, config)
],
...esbuildOptions
...esbuildOptions,
supported: {
'dynamic-import': true,
'import-meta': true,
...esbuildOptions.supported
}
})

const meta = result.metafile!
Expand Down
6 changes: 6 additions & 0 deletions playground/lib/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const path = require('path')
* @type {import('vite').UserConfig}
*/
module.exports = {
esbuild: {
supported: {
// Force esbuild inject helpers to test regex
'object-rest-spread': false
}
},
build: {
rollupOptions: {
output: {
Expand Down
Loading