vite 3.0.0-beta.0 → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30209,14 +30209,27 @@ async function runOptimizeDeps(resolvedConfig, depsInfo, ssr = !!resolvedConfig.
30209
30209
  idToExports[id] = exportsData;
30210
30210
  flatIdToExports[flatId] = exportsData;
30211
30211
  }
30212
+ // esbuild automatically replaces process.env.NODE_ENV for platform 'browser'
30213
+ // In lib mode, we need to keep process.env.NODE_ENV untouched, so to at build
30214
+ // time we replace it by __vite_process_env_NODE_ENV. This placeholder will be
30215
+ // later replaced by the define plugin
30216
+ const define = {
30217
+ 'process.env.NODE_ENV': isBuild
30218
+ ? '__vite_process_env_NODE_ENV'
30219
+ : JSON.stringify(process.env.NODE_ENV || config.mode)
30220
+ };
30212
30221
  const start = performance.now();
30213
30222
  const result = await build$3({
30214
30223
  absWorkingDir: process.cwd(),
30215
30224
  entryPoints: Object.keys(flatIdDeps),
30216
30225
  bundle: true,
30217
- // Ensure resolution is handled by esbuildDepPlugin and
30218
- // avoid replacing `process.env.NODE_ENV` for 'browser'
30219
- platform: 'neutral',
30226
+ // We can't use platform 'neutral', as esbuild has custom handling
30227
+ // when the platform is 'node' or 'browser' that can't be emulated
30228
+ // by using mainFields and conditions
30229
+ platform: config.build.ssr && config.ssr?.target !== 'webworker'
30230
+ ? 'node'
30231
+ : 'browser',
30232
+ define,
30220
30233
  format: 'esm',
30221
30234
  target: config.build.target || undefined,
30222
30235
  external: config.optimizeDeps?.exclude,
@@ -38527,7 +38540,7 @@ const assetAttrsConfig = {
38527
38540
  const isAsyncScriptMap = new WeakMap();
38528
38541
  async function traverseHtml(html, filePath, visitor) {
38529
38542
  // lazy load compiler
38530
- const { parse, transform } = await import('./dep-50504393.js').then(function (n) { return n.c; });
38543
+ const { parse, transform } = await import('./dep-d0efd013.js').then(function (n) { return n.c; });
38531
38544
  // @vue/compiler-core doesn't like lowercase doctypes
38532
38545
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
38533
38546
  try {
@@ -39655,7 +39668,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
39655
39668
  logger: config.logger
39656
39669
  }));
39657
39670
  if (isModule) {
39658
- postcssPlugins.unshift((await import('./dep-926cae74.js').then(function (n) { return n.i; })).default({
39671
+ postcssPlugins.unshift((await import('./dep-cd58a191.js').then(function (n) { return n.i; })).default({
39659
39672
  ...modulesOptions,
39660
39673
  getJSON(cssFileName, _modules, outputFileName) {
39661
39674
  modules = _modules;
@@ -49217,7 +49230,7 @@ async function getCertificate(cacheDir) {
49217
49230
  return content;
49218
49231
  }
49219
49232
  catch {
49220
- const content = (await import('./dep-3f55e00c.js')).createCertificate();
49233
+ const content = (await import('./dep-35befe4f.js')).createCertificate();
49221
49234
  promises$2
49222
49235
  .mkdir(cacheDir, { recursive: true })
49223
49236
  .then(() => promises$2.writeFile(cachePath, content))
@@ -59146,7 +59159,8 @@ function definePlugin(config) {
59146
59159
  Object.assign(processNodeEnv, {
59147
59160
  'process.env.NODE_ENV': JSON.stringify(nodeEnv),
59148
59161
  'global.process.env.NODE_ENV': JSON.stringify(nodeEnv),
59149
- 'globalThis.process.env.NODE_ENV': JSON.stringify(nodeEnv)
59162
+ 'globalThis.process.env.NODE_ENV': JSON.stringify(nodeEnv),
59163
+ __vite_process_env_NODE_ENV: JSON.stringify(nodeEnv)
59150
59164
  });
59151
59165
  }
59152
59166
  const userDefine = {};
@@ -59179,6 +59193,9 @@ function definePlugin(config) {
59179
59193
  ...importMetaKeys,
59180
59194
  ...(replaceProcessEnv ? processEnv : {})
59181
59195
  };
59196
+ if (isBuild && !replaceProcessEnv) {
59197
+ replacements['__vite_process_env_NODE_ENV'] = 'process.env.NODE_ENV';
59198
+ }
59182
59199
  const replacementsKeys = Object.keys(replacements);
59183
59200
  const pattern = replacementsKeys.length
59184
59201
  ? new RegExp(
@@ -61498,6 +61515,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
61498
61515
  ssr = { target: 'node', format: 'cjs' };
61499
61516
  }
61500
61517
  const middlewareMode = config?.server?.middlewareMode;
61518
+ config = mergeConfig(config, externalConfigCompat(config, configEnv));
61501
61519
  const optimizeDeps = config.optimizeDeps || {};
61502
61520
  const BASE_URL = resolvedBase;
61503
61521
  const resolved = {
@@ -61838,5 +61856,67 @@ function isDepsOptimizerEnabled(config) {
61838
61856
  (command === 'build' && disabled === 'build') ||
61839
61857
  (command === 'serve' && optimizeDeps.disabled === 'dev'));
61840
61858
  }
61859
+ // esbuild doesn't transpile `require('foo')` into `import` statements if 'foo' is externalized
61860
+ // https://github.com/evanw/esbuild/issues/566#issuecomment-735551834
61861
+ function esbuildCjsExternalPlugin(externals) {
61862
+ return {
61863
+ name: 'cjs-external',
61864
+ setup(build) {
61865
+ const escape = (text) => `^${text.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')}$`;
61866
+ const filter = new RegExp(externals.map(escape).join('|'));
61867
+ build.onResolve({ filter: /.*/, namespace: 'external' }, (args) => ({
61868
+ path: args.path,
61869
+ external: true
61870
+ }));
61871
+ build.onResolve({ filter }, (args) => ({
61872
+ path: args.path,
61873
+ namespace: 'external'
61874
+ }));
61875
+ build.onLoad({ filter: /.*/, namespace: 'external' }, (args) => ({
61876
+ contents: `export * from ${JSON.stringify(args.path)}`
61877
+ }));
61878
+ }
61879
+ };
61880
+ }
61881
+ // Support `rollupOptions.external` when `legacy.buildRollupPluginCommonjs` is disabled
61882
+ function externalConfigCompat(config, { command }) {
61883
+ // Only affects the build command
61884
+ if (command !== 'build') {
61885
+ return {};
61886
+ }
61887
+ // Skip if using Rollup CommonJS plugin
61888
+ if (config.legacy?.buildRollupPluginCommonjs ||
61889
+ config.optimizeDeps?.disabled === 'build') {
61890
+ return {};
61891
+ }
61892
+ // Skip if no `external` configured
61893
+ const external = config?.build?.rollupOptions?.external;
61894
+ if (!external) {
61895
+ return {};
61896
+ }
61897
+ let normalizedExternal = external;
61898
+ if (typeof external === 'string') {
61899
+ normalizedExternal = [external];
61900
+ }
61901
+ // TODO: decide whether to support RegExp and function options
61902
+ // They're not supported yet because `optimizeDeps.exclude` currently only accepts strings
61903
+ if (!Array.isArray(normalizedExternal) ||
61904
+ normalizedExternal.some((ext) => typeof ext !== 'string')) {
61905
+ throw new Error(`[vite] 'build.rollupOptions.external' can only be an array of strings or a string.\n` +
61906
+ `You can turn on 'legacy.buildRollupPluginCommonjs' to support more advanced options.`);
61907
+ }
61908
+ const additionalConfig = {
61909
+ optimizeDeps: {
61910
+ exclude: normalizedExternal,
61911
+ esbuildOptions: {
61912
+ plugins: [
61913
+ // TODO: maybe it can be added globally/unconditionally?
61914
+ esbuildCjsExternalPlugin(normalizedExternal)
61915
+ ]
61916
+ }
61917
+ }
61918
+ };
61919
+ return additionalConfig;
61920
+ }
61841
61921
 
61842
61922
  export { getDefaultExportFromCjs as A, index$1 as B, build$1 as C, index as D, preview$1 as E, resolvePackageData as a, build as b, createServer as c, defineConfig as d, resolveConfig as e, formatPostcssSourceMap as f, resolveBaseUrl as g, mergeAlias as h, isDepsOptimizerEnabled as i, createFilter as j, send as k, loadConfigFromFile as l, mergeConfig as m, normalizePath$3 as n, optimizeDeps as o, preview as p, createLogger as q, resolvePackageEntry as r, sortUserPlugins as s, transformWithEsbuild as t, searchForWorkspaceRoot as u, loadEnv as v, resolveEnvPrefix as w, colors$1 as x, commonjsGlobal as y, getAugmentedNamespace as z };
@@ -1,4 +1,4 @@
1
- import { y as commonjsGlobal } from './dep-6736a7e2.js';
1
+ import { y as commonjsGlobal } from './dep-077259ad.js';
2
2
  import require$$1 from 'crypto';
3
3
  import 'node:fs';
4
4
  import 'node:path';
@@ -1,5 +1,5 @@
1
1
  import require$$0 from 'postcss';
2
- import { y as commonjsGlobal } from './dep-6736a7e2.js';
2
+ import { y as commonjsGlobal } from './dep-077259ad.js';
3
3
  import path$2 from 'path';
4
4
  import require$$1 from 'crypto';
5
5
  import require$$0__default from 'fs';
@@ -1,4 +1,4 @@
1
- import { z as getAugmentedNamespace, A as getDefaultExportFromCjs } from './dep-6736a7e2.js';
1
+ import { z as getAugmentedNamespace, A as getDefaultExportFromCjs } from './dep-077259ad.js';
2
2
 
3
3
  import { fileURLToPath as __cjs_fileURLToPath } from 'node:url';
4
4
  import { dirname as __cjs_dirname } from 'node:path';
package/dist/node/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { EventEmitter } from 'events';
3
- import { x as colors, q as createLogger, e as resolveConfig } from './chunks/dep-6736a7e2.js';
3
+ import { x as colors, q as createLogger, e as resolveConfig } from './chunks/dep-077259ad.js';
4
4
  import { VERSION } from './constants.js';
5
5
  import 'node:fs';
6
6
  import 'node:path';
@@ -694,7 +694,7 @@ cli
694
694
  .action(async (root, options) => {
695
695
  // output structure is preserved even after bundling so require()
696
696
  // is ok here
697
- const { createServer } = await import('./chunks/dep-6736a7e2.js').then(function (n) { return n.D; });
697
+ const { createServer } = await import('./chunks/dep-077259ad.js').then(function (n) { return n.D; });
698
698
  try {
699
699
  const server = await createServer({
700
700
  root,
@@ -741,7 +741,7 @@ cli
741
741
  .option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
742
742
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
743
743
  .action(async (root, options) => {
744
- const { build } = await import('./chunks/dep-6736a7e2.js').then(function (n) { return n.C; });
744
+ const { build } = await import('./chunks/dep-077259ad.js').then(function (n) { return n.C; });
745
745
  const buildOptions = cleanOptions(options);
746
746
  try {
747
747
  await build({
@@ -765,7 +765,7 @@ cli
765
765
  .command('optimize [root]', 'pre-bundle dependencies')
766
766
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
767
767
  .action(async (root, options) => {
768
- const { optimizeDeps } = await import('./chunks/dep-6736a7e2.js').then(function (n) { return n.B; });
768
+ const { optimizeDeps } = await import('./chunks/dep-077259ad.js').then(function (n) { return n.B; });
769
769
  try {
770
770
  const config = await resolveConfig({
771
771
  root,
@@ -788,7 +788,7 @@ cli
788
788
  .option('--https', `[boolean] use TLS + HTTP/2`)
789
789
  .option('--open [path]', `[boolean | string] open browser on startup`)
790
790
  .action(async (root, options) => {
791
- const { preview } = await import('./chunks/dep-6736a7e2.js').then(function (n) { return n.E; });
791
+ const { preview } = await import('./chunks/dep-077259ad.js').then(function (n) { return n.E; });
792
792
  try {
793
793
  const server = await preview({
794
794
  root,
@@ -1,7 +1,7 @@
1
1
  import path, { resolve } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
 
4
- var version = "3.0.0-beta.0";
4
+ var version = "3.0.0-beta.1";
5
5
 
6
6
  const VERSION = version;
7
7
  const DEFAULT_MAIN_FIELDS = [
@@ -1,4 +1,4 @@
1
- export { b as build, j as createFilter, q as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, i as isDepsOptimizerEnabled, l as loadConfigFromFile, v as loadEnv, h as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, g as resolveBaseUrl, e as resolveConfig, w as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, u as searchForWorkspaceRoot, k as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-6736a7e2.js';
1
+ export { b as build, j as createFilter, q as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, i as isDepsOptimizerEnabled, l as loadConfigFromFile, v as loadEnv, h as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, g as resolveBaseUrl, e as resolveConfig, w as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, u as searchForWorkspaceRoot, k as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-077259ad.js';
2
2
  export { VERSION as version } from './constants.js';
3
3
  export { version as esbuildVersion } from 'esbuild';
4
4
  export { VERSION as rollupVersion } from 'rollup';
@@ -31,7 +31,7 @@ var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
31
31
  var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
32
32
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
33
33
 
34
- var version = "3.0.0-beta.0";
34
+ var version = "3.0.0-beta.1";
35
35
 
36
36
  const VERSION = version;
37
37
  const VITE_PACKAGE_DIR = path$3.resolve(node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href))), '../../..');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "3.0.0-beta.0",
3
+ "version": "3.0.0-beta.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",