vite 3.0.0-alpha.4 → 3.0.0-alpha.5

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.
@@ -1,4 +1,4 @@
1
- import { w as getAugmentedNamespace, x as getDefaultExportFromCjs } from './dep-aea1d487.js';
1
+ import { x as getAugmentedNamespace, y as getDefaultExportFromCjs } from './dep-0232e200.js';
2
2
 
3
3
  import { fileURLToPath as __cjs_fileURLToPath } from 'url';
4
4
  import { dirname as __cjs_dirname } from 'path';
@@ -424,6 +424,11 @@ function looseEqual(a, b) {
424
424
  if (aValidType || bValidType) {
425
425
  return aValidType && bValidType ? a.getTime() === b.getTime() : false;
426
426
  }
427
+ aValidType = isSymbol(a);
428
+ bValidType = isSymbol(b);
429
+ if (aValidType || bValidType) {
430
+ return a === b;
431
+ }
427
432
  aValidType = isArray(a);
428
433
  bValidType = isArray(b);
429
434
  if (aValidType || bValidType) {
@@ -520,7 +525,7 @@ const hasOwn = (val, key) => hasOwnProperty.call(val, key);
520
525
  const isArray = Array.isArray;
521
526
  const isMap = (val) => toTypeString(val) === '[object Map]';
522
527
  const isSet = (val) => toTypeString(val) === '[object Set]';
523
- const isDate = (val) => val instanceof Date;
528
+ const isDate = (val) => toTypeString(val) === '[object Date]';
524
529
  const isFunction = (val) => typeof val === 'function';
525
530
  const isString = (val) => typeof val === 'string';
526
531
  const isSymbol = (val) => typeof val === 'symbol';
@@ -604,7 +609,13 @@ const getGlobalThis = () => {
604
609
  : typeof global !== 'undefined'
605
610
  ? global
606
611
  : {}));
607
- };
612
+ };
613
+ const identRE = /^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/;
614
+ function genPropsAccessExp(name) {
615
+ return identRE.test(name)
616
+ ? `__props.${name}`
617
+ : `__props[${JSON.stringify(name)}]`;
618
+ }
608
619
 
609
620
  var shared_esmBundler = {
610
621
  __proto__: null,
@@ -619,6 +630,7 @@ var shared_esmBundler = {
619
630
  escapeHtml: escapeHtml,
620
631
  escapeHtmlComment: escapeHtmlComment,
621
632
  extend: extend,
633
+ genPropsAccessExp: genPropsAccessExp,
622
634
  generateCodeFrame: generateCodeFrame,
623
635
  getGlobalThis: getGlobalThis,
624
636
  hasChanged: hasChanged,
@@ -2452,6 +2464,14 @@ function getConstantType(node, context) {
2452
2464
  // static then they don't need to be blocks since there will be no
2453
2465
  // nested updates.
2454
2466
  if (codegenNode.isBlock) {
2467
+ // except set custom directives.
2468
+ for (let i = 0; i < node.props.length; i++) {
2469
+ const p = node.props[i];
2470
+ if (p.type === 7 /* DIRECTIVE */) {
2471
+ constantCache.set(node, 0 /* NOT_CONSTANT */);
2472
+ return 0 /* NOT_CONSTANT */;
2473
+ }
2474
+ }
2455
2475
  context.removeHelper(OPEN_BLOCK);
2456
2476
  context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
2457
2477
  codegenNode.isBlock = false;
@@ -2858,6 +2878,7 @@ function createStructuralDirectiveTransform(name, fn) {
2858
2878
  }
2859
2879
 
2860
2880
  const PURE_ANNOTATION = `/*#__PURE__*/`;
2881
+ const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
2861
2882
  function createCodegenContext(ast, { mode = 'function', prefixIdentifiers = mode === 'module', sourceMap = false, filename = `template.vue.html`, scopeId = null, optimizeImports = false, runtimeGlobalName = `Vue`, runtimeModuleName = `vue`, ssrRuntimeModuleName = 'vue/server-renderer', ssr = false, isTS = false, inSSR = false }) {
2862
2883
  const context = {
2863
2884
  mode,
@@ -2934,9 +2955,7 @@ function generate(ast, options = {}) {
2934
2955
  // function mode const declarations should be inside with block
2935
2956
  // also they should be renamed to avoid collision with user properties
2936
2957
  if (hasHelpers) {
2937
- push(`const { ${ast.helpers
2938
- .map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
2939
- .join(', ')} } = _Vue`);
2958
+ push(`const { ${ast.helpers.map(aliasHelper).join(', ')} } = _Vue`);
2940
2959
  push(`\n`);
2941
2960
  newline();
2942
2961
  }
@@ -2996,7 +3015,6 @@ function generate(ast, options = {}) {
2996
3015
  function genFunctionPreamble(ast, context) {
2997
3016
  const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName, ssrRuntimeModuleName } = context;
2998
3017
  const VueBinding = runtimeGlobalName;
2999
- const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
3000
3018
  // Generate const declaration for helpers
3001
3019
  // In prefix mode, we place the const declaration at top so it's done
3002
3020
  // only once; But if we not prefixing, we place the declaration inside the
@@ -3714,14 +3732,14 @@ function processIf(node, dir, context, processCodegen) {
3714
3732
  }
3715
3733
  }
3716
3734
  function createIfBranch(node, dir) {
3735
+ const isTemplateIf = node.tagType === 3 /* TEMPLATE */;
3717
3736
  return {
3718
3737
  type: 10 /* IF_BRANCH */,
3719
3738
  loc: node.loc,
3720
3739
  condition: dir.name === 'else' ? undefined : dir.exp,
3721
- children: node.tagType === 3 /* TEMPLATE */ && !findDir(node, 'for')
3722
- ? node.children
3723
- : [node],
3724
- userKey: findProp(node, `key`)
3740
+ children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
3741
+ userKey: findProp(node, `key`),
3742
+ isTemplateIf
3725
3743
  };
3726
3744
  }
3727
3745
  function createCodegenNodeForBranch(branch, keyIndex, context) {
@@ -3757,6 +3775,7 @@ function createChildrenCodegenNode(branch, keyIndex, context) {
3757
3775
  // check if the fragment actually contains a single valid child with
3758
3776
  // the rest being comments
3759
3777
  if ((process.env.NODE_ENV !== 'production') &&
3778
+ !branch.isTemplateIf &&
3760
3779
  children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
3761
3780
  patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
3762
3781
  patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
@@ -4333,7 +4352,7 @@ const transformElement = (node, context) => {
4333
4352
  (tag === 'svg' || tag === 'foreignObject'));
4334
4353
  // props
4335
4354
  if (props.length > 0) {
4336
- const propsBuildResult = buildProps(node, context);
4355
+ const propsBuildResult = buildProps(node, context, undefined, isComponent, isDynamicComponent);
4337
4356
  vnodeProps = propsBuildResult.props;
4338
4357
  patchFlag = propsBuildResult.patchFlag;
4339
4358
  dynamicPropNames = propsBuildResult.dynamicPropNames;
@@ -4475,9 +4494,8 @@ function resolveComponentType(node, context, ssr = false) {
4475
4494
  context.components.add(tag);
4476
4495
  return toValidAssetId(tag, `component`);
4477
4496
  }
4478
- function buildProps(node, context, props = node.props, ssr = false) {
4497
+ function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
4479
4498
  const { tag, loc: elementLoc, children } = node;
4480
- const isComponent = node.tagType === 1 /* COMPONENT */;
4481
4499
  let properties = [];
4482
4500
  const mergeArgs = [];
4483
4501
  const runtimeDirectives = [];
@@ -4496,8 +4514,8 @@ function buildProps(node, context, props = node.props, ssr = false) {
4496
4514
  if (isStaticExp(key)) {
4497
4515
  const name = key.content;
4498
4516
  const isEventHandler = isOn(name);
4499
- if (!isComponent &&
4500
- isEventHandler &&
4517
+ if (isEventHandler &&
4518
+ (!isComponent || isDynamicComponent) &&
4501
4519
  // omit the flag for click handlers because hydration gives click
4502
4520
  // dedicated fast path.
4503
4521
  name.toLowerCase() !== 'onclick' &&
@@ -4752,10 +4770,11 @@ function buildProps(node, context, props = node.props, ssr = false) {
4752
4770
  classProp.value = createCallExpression(context.helper(NORMALIZE_CLASS), [classProp.value]);
4753
4771
  }
4754
4772
  if (styleProp &&
4755
- !isStaticExp(styleProp.value) &&
4756
4773
  // the static style is compiled into an object,
4757
4774
  // so use `hasStyleBinding` to ensure that it is a dynamic style binding
4758
4775
  (hasStyleBinding ||
4776
+ (styleProp.value.type === 4 /* SIMPLE_EXPRESSION */ &&
4777
+ styleProp.value.content.trim()[0] === `[`) ||
4759
4778
  // v-bind:style and style both exist,
4760
4779
  // v-bind:style with static literal object
4761
4780
  styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
@@ -4953,7 +4972,7 @@ function processSlotOutlet(node, context) {
4953
4972
  }
4954
4973
  }
4955
4974
  if (nonNameProps.length > 0) {
4956
- const { props, directives } = buildProps(node, context, nonNameProps);
4975
+ const { props, directives } = buildProps(node, context, nonNameProps, false, false);
4957
4976
  slotProps = props;
4958
4977
  if (directives.length) {
4959
4978
  context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
@@ -5124,11 +5143,7 @@ const transformText = (node, context) => {
5124
5143
  const next = children[j];
5125
5144
  if (isText(next)) {
5126
5145
  if (!currentContainer) {
5127
- currentContainer = children[i] = {
5128
- type: 8 /* COMPOUND_EXPRESSION */,
5129
- loc: child.loc,
5130
- children: [child]
5131
- };
5146
+ currentContainer = children[i] = createCompoundExpression([child], child.loc);
5132
5147
  }
5133
5148
  // merge adjacent text node into current
5134
5149
  currentContainer.children.push(` + `, next);
@@ -5597,6 +5612,7 @@ var compilerCore_esmBundler = {
5597
5612
  findProp: findProp,
5598
5613
  generate: generate,
5599
5614
  getBaseTransformPreset: getBaseTransformPreset,
5615
+ getConstantType: getConstantType,
5600
5616
  getInnerRange: getInnerRange,
5601
5617
  getMemoedVNodeCall: getMemoedVNodeCall,
5602
5618
  getVNodeBlockHelper: getVNodeBlockHelper,
@@ -8178,7 +8194,9 @@ const transformVText = (dir, node, context) => {
8178
8194
  return {
8179
8195
  props: [
8180
8196
  compilerCore.createObjectProperty(compilerCore.createSimpleExpression(`textContent`, true), exp
8181
- ? compilerCore.createCallExpression(context.helperString(compilerCore.TO_DISPLAY_STRING), [exp], loc)
8197
+ ? compilerCore.getConstantType(exp, context) > 0
8198
+ ? exp
8199
+ : compilerCore.createCallExpression(context.helperString(compilerCore.TO_DISPLAY_STRING), [exp], loc)
8182
8200
  : compilerCore.createSimpleExpression('', true))
8183
8201
  ]
8184
8202
  };
@@ -8390,19 +8408,38 @@ const transformShow = (dir, node, context) => {
8390
8408
  };
8391
8409
  };
8392
8410
 
8393
- const warnTransitionChildren = (node, context) => {
8411
+ const transformTransition = (node, context) => {
8394
8412
  if (node.type === 1 /* ELEMENT */ &&
8395
8413
  node.tagType === 1 /* COMPONENT */) {
8396
8414
  const component = context.isBuiltInComponent(node.tag);
8397
8415
  if (component === TRANSITION) {
8398
8416
  return () => {
8399
- if (node.children.length && hasMultipleChildren(node)) {
8417
+ if (!node.children.length) {
8418
+ return;
8419
+ }
8420
+ // warn multiple transition children
8421
+ if (hasMultipleChildren(node)) {
8400
8422
  context.onError(createDOMCompilerError(59 /* X_TRANSITION_INVALID_CHILDREN */, {
8401
8423
  start: node.children[0].loc.start,
8402
8424
  end: node.children[node.children.length - 1].loc.end,
8403
8425
  source: ''
8404
8426
  }));
8405
8427
  }
8428
+ // check if it's s single child w/ v-show
8429
+ // if yes, inject "persisted: true" to the transition props
8430
+ const child = node.children[0];
8431
+ if (child.type === 1 /* ELEMENT */) {
8432
+ for (const p of child.props) {
8433
+ if (p.type === 7 /* DIRECTIVE */ && p.name === 'show') {
8434
+ node.props.push({
8435
+ type: 6 /* ATTRIBUTE */,
8436
+ name: 'persisted',
8437
+ value: undefined,
8438
+ loc: node.loc
8439
+ });
8440
+ }
8441
+ }
8442
+ }
8406
8443
  };
8407
8444
  }
8408
8445
  }
@@ -8618,6 +8655,7 @@ function stringifyNode(node, context) {
8618
8655
  }
8619
8656
  function stringifyElement(node, context) {
8620
8657
  let res = `<${node.tag}`;
8658
+ let innerHTML = '';
8621
8659
  for (let i = 0; i < node.props.length; i++) {
8622
8660
  const p = node.props[i];
8623
8661
  if (p.type === 6 /* ATTRIBUTE */) {
@@ -8626,25 +8664,35 @@ function stringifyElement(node, context) {
8626
8664
  res += `="${shared.escapeHtml(p.value.content)}"`;
8627
8665
  }
8628
8666
  }
8629
- else if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind') {
8630
- const exp = p.exp;
8631
- if (exp.content[0] === '_') {
8632
- // internally generated string constant references
8633
- // e.g. imported URL strings via compiler-sfc transformAssetUrl plugin
8634
- res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
8635
- continue;
8636
- }
8637
- // constant v-bind, e.g. :foo="1"
8638
- let evaluated = evaluateConstant(exp);
8639
- if (evaluated != null) {
8640
- const arg = p.arg && p.arg.content;
8641
- if (arg === 'class') {
8642
- evaluated = shared.normalizeClass(evaluated);
8667
+ else if (p.type === 7 /* DIRECTIVE */) {
8668
+ if (p.name === 'bind') {
8669
+ const exp = p.exp;
8670
+ if (exp.content[0] === '_') {
8671
+ // internally generated string constant references
8672
+ // e.g. imported URL strings via compiler-sfc transformAssetUrl plugin
8673
+ res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
8674
+ continue;
8643
8675
  }
8644
- else if (arg === 'style') {
8645
- evaluated = shared.stringifyStyle(shared.normalizeStyle(evaluated));
8676
+ // constant v-bind, e.g. :foo="1"
8677
+ let evaluated = evaluateConstant(exp);
8678
+ if (evaluated != null) {
8679
+ const arg = p.arg && p.arg.content;
8680
+ if (arg === 'class') {
8681
+ evaluated = shared.normalizeClass(evaluated);
8682
+ }
8683
+ else if (arg === 'style') {
8684
+ evaluated = shared.stringifyStyle(shared.normalizeStyle(evaluated));
8685
+ }
8686
+ res += ` ${p.arg.content}="${shared.escapeHtml(evaluated)}"`;
8646
8687
  }
8647
- res += ` ${p.arg.content}="${shared.escapeHtml(evaluated)}"`;
8688
+ }
8689
+ else if (p.name === 'html') {
8690
+ // #5439 v-html with constant value
8691
+ // not sure why would anyone do this but it can happen
8692
+ innerHTML = evaluateConstant(p.exp);
8693
+ }
8694
+ else if (p.name === 'text') {
8695
+ innerHTML = shared.escapeHtml(shared.toDisplayString(evaluateConstant(p.exp)));
8648
8696
  }
8649
8697
  }
8650
8698
  }
@@ -8652,8 +8700,13 @@ function stringifyElement(node, context) {
8652
8700
  res += ` ${context.scopeId}`;
8653
8701
  }
8654
8702
  res += `>`;
8655
- for (let i = 0; i < node.children.length; i++) {
8656
- res += stringifyNode(node.children[i], context);
8703
+ if (innerHTML) {
8704
+ res += innerHTML;
8705
+ }
8706
+ else {
8707
+ for (let i = 0; i < node.children.length; i++) {
8708
+ res += stringifyNode(node.children[i], context);
8709
+ }
8657
8710
  }
8658
8711
  if (!shared.isVoidTag(node.tag)) {
8659
8712
  res += `</${node.tag}>`;
@@ -8666,7 +8719,7 @@ function stringifyElement(node, context) {
8666
8719
  // here, e.g. `{{ 1 }}` or `{{ 'foo' }}`
8667
8720
  // in addition, constant exps bail on presence of parens so you can't even
8668
8721
  // run JSFuck in here. But we mark it unsafe for security review purposes.
8669
- // (see compiler-core/src/transformExpressions)
8722
+ // (see compiler-core/src/transforms/transformExpression)
8670
8723
  function evaluateConstant(exp) {
8671
8724
  if (exp.type === 4 /* SIMPLE_EXPRESSION */) {
8672
8725
  return new Function(`return ${exp.content}`)();
@@ -8703,7 +8756,7 @@ const ignoreSideEffectTags = (node, context) => {
8703
8756
 
8704
8757
  const DOMNodeTransforms = [
8705
8758
  transformStyle,
8706
- ...([warnTransitionChildren] )
8759
+ ...([transformTransition] )
8707
8760
  ];
8708
8761
  const DOMDirectiveTransforms = {
8709
8762
  cloak: compilerCore.noopDirectiveTransform,
@@ -1,5 +1,5 @@
1
1
  import require$$0 from 'postcss';
2
- import { v as commonjsGlobal } from './dep-aea1d487.js';
2
+ import { w as commonjsGlobal } from './dep-0232e200.js';
3
3
  import path$2 from 'path';
4
4
  import require$$1 from 'crypto';
5
5
  import fs__default from 'fs';
@@ -1,4 +1,4 @@
1
- import { v as commonjsGlobal } from './dep-aea1d487.js';
1
+ import { w as commonjsGlobal } from './dep-0232e200.js';
2
2
  import require$$1 from 'crypto';
3
3
  import 'fs';
4
4
  import 'path';
package/dist/node/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { performance } from 'perf_hooks';
2
2
  import { EventEmitter } from 'events';
3
- import { u as colors, i as createLogger, e as resolveConfig } from './chunks/dep-aea1d487.js';
3
+ import { v as colors, j as createLogger, e as resolveConfig } from './chunks/dep-0232e200.js';
4
4
  import { VERSION } from './constants.js';
5
5
  import 'fs';
6
6
  import 'path';
@@ -682,7 +682,7 @@ cli
682
682
  .action(async (root, options) => {
683
683
  // output structure is preserved even after bundling so require()
684
684
  // is ok here
685
- const { createServer } = await import('./chunks/dep-aea1d487.js').then(function (n) { return n.A; });
685
+ const { createServer } = await import('./chunks/dep-0232e200.js').then(function (n) { return n.B; });
686
686
  try {
687
687
  const server = await createServer({
688
688
  root,
@@ -724,10 +724,11 @@ cli
724
724
  `or specify minifier to use (default: esbuild)`)
725
725
  .option('--manifest [name]', `[boolean | string] emit build manifest json`)
726
726
  .option('--ssrManifest [name]', `[boolean | string] emit ssr manifest json`)
727
+ .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle (experimental)`)
727
728
  .option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
728
729
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
729
730
  .action(async (root, options) => {
730
- const { build } = await import('./chunks/dep-aea1d487.js').then(function (n) { return n.z; });
731
+ const { build } = await import('./chunks/dep-0232e200.js').then(function (n) { return n.A; });
731
732
  const buildOptions = cleanOptions(options);
732
733
  try {
733
734
  await build({
@@ -737,6 +738,7 @@ cli
737
738
  configFile: options.config,
738
739
  logLevel: options.logLevel,
739
740
  clearScreen: options.clearScreen,
741
+ force: options.force,
740
742
  build: buildOptions
741
743
  });
742
744
  }
@@ -750,7 +752,7 @@ cli
750
752
  .command('optimize [root]', 'pre-bundle dependencies')
751
753
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
752
754
  .action(async (root, options) => {
753
- const { optimizeDeps } = await import('./chunks/dep-aea1d487.js').then(function (n) { return n.y; });
755
+ const { optimizeDeps } = await import('./chunks/dep-0232e200.js').then(function (n) { return n.z; });
754
756
  try {
755
757
  const config = await resolveConfig({
756
758
  root,
@@ -773,7 +775,7 @@ cli
773
775
  .option('--https', `[boolean] use TLS + HTTP/2`)
774
776
  .option('--open [path]', `[boolean | string] open browser on startup`)
775
777
  .action(async (root, options) => {
776
- const { preview } = await import('./chunks/dep-aea1d487.js').then(function (n) { return n.B; });
778
+ const { preview } = await import('./chunks/dep-0232e200.js').then(function (n) { return n.C; });
777
779
  try {
778
780
  const server = await preview({
779
781
  root,
@@ -105,6 +105,11 @@ export interface UserConfig {
105
105
  * Preview specific options, e.g. host, port, https...
106
106
  */
107
107
  preview?: PreviewOptions;
108
+ /**
109
+ * Force dep pre-optimization regardless of whether deps have changed.
110
+ * @experimental
111
+ */
112
+ force?: boolean;
108
113
  /**
109
114
  * Dep optimization options
110
115
  */
@@ -238,3 +243,4 @@ export declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: st
238
243
  config: UserConfig;
239
244
  dependencies: string[];
240
245
  } | null>;
246
+ export declare function isDepsOptimizerEnabled(config: ResolvedConfig): boolean;
@@ -1,7 +1,7 @@
1
1
  import path, { resolve } from 'path';
2
2
  import { fileURLToPath } from 'url';
3
3
 
4
- var version = "3.0.0-alpha.4";
4
+ var version = "3.0.0-alpha.5";
5
5
 
6
6
  const VERSION = version;
7
7
  const DEFAULT_MAIN_FIELDS = [
@@ -573,11 +573,13 @@ export declare interface DepOptimizationOptions {
573
573
  */
574
574
  extensions?: string[];
575
575
  /**
576
- * Disables dependencies optimizations
576
+ * Disables dependencies optimizations, true disables the optimizer during
577
+ * build and dev. Pass 'build' or 'dev' to only disable the optimizer in
578
+ * one of the modes. Deps optimization is enabled by default in both
577
579
  * @default false
578
580
  * @experimental
579
581
  */
580
- disabled?: boolean;
582
+ disabled?: boolean | 'build' | 'dev';
581
583
  }
582
584
 
583
585
  export declare interface DepOptimizationProcessing {
@@ -596,6 +598,17 @@ export declare interface DepOptimizationResult {
596
598
  cancel: () => void;
597
599
  }
598
600
 
601
+ export declare interface DepsOptimizer {
602
+ metadata: DepOptimizationMetadata;
603
+ scanProcessing?: Promise<void>;
604
+ registerMissingImport: (id: string, resolved: string) => OptimizedDepInfo;
605
+ run: () => void;
606
+ isOptimizedDepFile: (id: string) => boolean;
607
+ isOptimizedDepUrl: (url: string) => boolean;
608
+ getOptimizedDepId: (depInfo: OptimizedDepInfo) => string;
609
+ options: DepOptimizationOptions;
610
+ }
611
+
599
612
  export declare interface ErrorPayload {
600
613
  type: 'error'
601
614
  err: {
@@ -1142,8 +1155,11 @@ export declare interface InternalResolveOptions extends ResolveOptions {
1142
1155
  isFromTsImporter?: boolean;
1143
1156
  tryEsmOnly?: boolean;
1144
1157
  scan?: boolean;
1158
+ getDepsOptimizer?: () => DepsOptimizer | undefined;
1145
1159
  }
1146
1160
 
1161
+ export declare function isDepsOptimizerEnabled(config: ResolvedConfig): boolean;
1162
+
1147
1163
  export declare interface JsonOptions {
1148
1164
  /**
1149
1165
  * Generate a named export for every property of the JSON object
@@ -1300,12 +1316,6 @@ export declare interface OptimizedDepInfo {
1300
1316
  exportsData?: Promise<ExportsData>;
1301
1317
  }
1302
1318
 
1303
- export declare interface OptimizedDeps {
1304
- metadata: DepOptimizationMetadata;
1305
- scanProcessing?: Promise<void>;
1306
- registerMissingImport: (id: string, resolved: string) => OptimizedDepInfo;
1307
- }
1308
-
1309
1319
  /**
1310
1320
  * Used by Vite CLI when running `vite optimize`
1311
1321
  */
@@ -1817,10 +1827,6 @@ export declare interface SendOptions {
1817
1827
  export declare type ServerHook = (server: ViteDevServer) => (() => void) | void | Promise<(() => void) | void>;
1818
1828
 
1819
1829
  export declare interface ServerOptions extends CommonServerOptions {
1820
- /**
1821
- * Force dep pre-optimization regardless of whether deps have changed.
1822
- */
1823
- force?: boolean;
1824
1830
  /**
1825
1831
  * Configure HMR-specific options (port, host, path & protocol)
1826
1832
  */
@@ -2162,6 +2168,11 @@ export declare interface UserConfig {
2162
2168
  * Preview specific options, e.g. host, port, https...
2163
2169
  */
2164
2170
  preview?: PreviewOptions;
2171
+ /**
2172
+ * Force dep pre-optimization regardless of whether deps have changed.
2173
+ * @experimental
2174
+ */
2175
+ force?: boolean;
2165
2176
  /**
2166
2177
  * Dep optimization options
2167
2178
  */
@@ -2314,7 +2325,6 @@ export declare interface ViteDevServer {
2314
2325
  * @param forceOptimize - force the optimizer to re-bundle, same as --force cli flag
2315
2326
  */
2316
2327
  restart(forceOptimize?: boolean): Promise<void>;
2317
- /* Excluded from this release type: _optimizedDeps */
2318
2328
  /* Excluded from this release type: _importGlobMap */
2319
2329
  /* Excluded from this release type: _ssrExternals */
2320
2330
  /* Excluded from this release type: _restartPromise */
@@ -1,4 +1,4 @@
1
- export { b as build, i as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, l as loadConfigFromFile, k as loadEnv, g as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, e as resolveConfig, q as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, j as searchForWorkspaceRoot, h as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-aea1d487.js';
1
+ export { b as build, j as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, i as isDepsOptimizerEnabled, l as loadConfigFromFile, q as loadEnv, g as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, e as resolveConfig, u as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, k as searchForWorkspaceRoot, h as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-0232e200.js';
2
2
  import 'fs';
3
3
  import 'path';
4
4
  import 'url';
@@ -1,15 +1,21 @@
1
1
  import type { BuildOptions as EsbuildBuildOptions } from 'esbuild';
2
2
  import { parse } from 'es-module-lexer';
3
3
  import type { ResolvedConfig } from '../config';
4
+ export { initDepsOptimizer, getDepsOptimizer } from './optimizer';
4
5
  export declare const debuggerViteDeps: (...args: any[]) => any;
5
6
  export declare type ExportsData = ReturnType<typeof parse> & {
6
7
  hasReExports?: true;
7
8
  jsxLoader?: true;
8
9
  };
9
- export interface OptimizedDeps {
10
+ export interface DepsOptimizer {
10
11
  metadata: DepOptimizationMetadata;
11
12
  scanProcessing?: Promise<void>;
12
13
  registerMissingImport: (id: string, resolved: string) => OptimizedDepInfo;
14
+ run: () => void;
15
+ isOptimizedDepFile: (id: string) => boolean;
16
+ isOptimizedDepUrl: (url: string) => boolean;
17
+ getOptimizedDepId: (depInfo: OptimizedDepInfo) => string;
18
+ options: DepOptimizationOptions;
13
19
  }
14
20
  export interface DepOptimizationOptions {
15
21
  /**
@@ -62,11 +68,13 @@ export interface DepOptimizationOptions {
62
68
  */
63
69
  extensions?: string[];
64
70
  /**
65
- * Disables dependencies optimizations
71
+ * Disables dependencies optimizations, true disables the optimizer during
72
+ * build and dev. Pass 'build' or 'dev' to only disable the optimizer in
73
+ * one of the modes. Deps optimization is enabled by default in both
66
74
  * @default false
67
75
  * @experimental
68
76
  */
69
- disabled?: boolean;
77
+ disabled?: boolean | 'build' | 'dev';
70
78
  }
71
79
  export interface DepOptimizationResult {
72
80
  metadata: DepOptimizationMetadata;
@@ -133,7 +141,7 @@ export interface DepOptimizationMetadata {
133
141
  * Used by Vite CLI when running `vite optimize`
134
142
  */
135
143
  export declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean): Promise<DepOptimizationMetadata>;
136
- export declare function createOptimizedDepsMetadata(config: ResolvedConfig, timestamp?: string): DepOptimizationMetadata;
144
+ export declare function initDepsOptimizerMetadata(config: ResolvedConfig, timestamp?: string): DepOptimizationMetadata;
137
145
  export declare function addOptimizedDepInfo(metadata: DepOptimizationMetadata, type: 'optimized' | 'discovered' | 'chunks', depInfo: OptimizedDepInfo): OptimizedDepInfo;
138
146
  /**
139
147
  * Creates the initial dep optimization metadata, loading it from the deps cache
@@ -145,12 +153,18 @@ export declare function loadCachedDepOptimizationMetadata(config: ResolvedConfig
145
153
  * find deps to pre-bundle and include user hard-coded dependencies
146
154
  */
147
155
  export declare function discoverProjectDependencies(config: ResolvedConfig, timestamp?: string): Promise<Record<string, OptimizedDepInfo>>;
156
+ /**
157
+ * Create the initial discovered deps list. At build time we only
158
+ * have the manually included deps. During dev, a scan phase is
159
+ * performed and knownDeps is the list of discovered deps
160
+ */
161
+ export declare function initialProjectDependencies(config: ResolvedConfig, timestamp?: string, knownDeps?: Record<string, string>): Promise<Record<string, OptimizedDepInfo>>;
148
162
  export declare function depsLogString(qualifiedIds: string[]): string;
149
163
  /**
150
164
  * Internally, Vite uses this function to prepare a optimizeDeps run. When Vite starts, we can get
151
165
  * the metadata and start the server without waiting for the optimizeDeps processing to be completed
152
166
  */
153
- export declare function runOptimizeDeps(config: ResolvedConfig, depsInfo: Record<string, OptimizedDepInfo>): Promise<DepOptimizationResult>;
167
+ export declare function runOptimizeDeps(resolvedConfig: ResolvedConfig, depsInfo: Record<string, OptimizedDepInfo>): Promise<DepOptimizationResult>;
154
168
  export declare function findKnownImports(config: ResolvedConfig): Promise<string[]>;
155
169
  export declare function newDepOptimizationProcessing(): DepOptimizationProcessing;
156
170
  export declare function depsFromOptimizedDepInfo(depsInfo: Record<string, OptimizedDepInfo>): {
@@ -0,0 +1,4 @@
1
+ import type { ResolvedConfig, ViteDevServer } from '..';
2
+ import type { DepsOptimizer } from '.';
3
+ export declare function getDepsOptimizer(config: ResolvedConfig): DepsOptimizer | undefined;
4
+ export declare function initDepsOptimizer(config: ResolvedConfig, server?: ViteDevServer): Promise<DepsOptimizer>;
@@ -1,4 +1,5 @@
1
1
  import type { CustomPluginOptions, LoadResult, PluginContext, ResolveIdResult, Plugin as RollupPlugin, TransformPluginContext, TransformResult } from 'rollup';
2
+ export type { PluginContext } from 'rollup';
2
3
  import type { UserConfig } from './config';
3
4
  import type { ServerHook } from './server';
4
5
  import type { IndexHtmlTransform } from './plugins/html';
@@ -1,4 +1,7 @@
1
+ import type { ResolvedConfig } from '..';
1
2
  import type { Plugin } from '../plugin';
2
3
  export declare const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = "ERR_OPTIMIZE_DEPS_PROCESSING_ERROR";
3
4
  export declare const ERR_OUTDATED_OPTIMIZED_DEP = "ERR_OUTDATED_OPTIMIZED_DEP";
4
- export declare function optimizedDepsPlugin(): Plugin;
5
+ export declare function registerWorkersSource(config: ResolvedConfig, id: string): void;
6
+ export declare function optimizedDepsPlugin(config: ResolvedConfig): Plugin;
7
+ export declare function optimizedDepsBuildPlugin(config: ResolvedConfig): Plugin;
@@ -1,5 +1,6 @@
1
+ import type { ResolvedConfig } from '..';
1
2
  import type { Plugin } from '../plugin';
2
3
  /**
3
4
  * A plugin to avoid an aliased AND optimized dep from being aliased in src
4
5
  */
5
- export declare function preAliasPlugin(): Plugin;
6
+ export declare function preAliasPlugin(config: ResolvedConfig): Plugin;
@@ -1,6 +1,7 @@
1
1
  import type { PartialResolvedId } from 'rollup';
2
2
  import type { Plugin } from '../plugin';
3
- import type { SSROptions, ViteDevServer } from '..';
3
+ import type { DepsOptimizer } from '../optimizer';
4
+ import type { SSROptions } from '..';
4
5
  import type { PackageCache, PackageData } from '../packages';
5
6
  export declare const browserExternalId = "__vite-browser-external";
6
7
  export interface ResolveOptions {
@@ -31,9 +32,10 @@ export interface InternalResolveOptions extends ResolveOptions {
31
32
  isFromTsImporter?: boolean;
32
33
  tryEsmOnly?: boolean;
33
34
  scan?: boolean;
35
+ getDepsOptimizer?: () => DepsOptimizer | undefined;
34
36
  }
35
37
  export declare function resolvePlugin(baseOptions: InternalResolveOptions): Plugin;
36
38
  export declare const idToPkgMap: Map<string, PackageData>;
37
- export declare function tryNodeResolve(id: string, importer: string | null | undefined, options: InternalResolveOptions, targetWeb: boolean, server?: ViteDevServer, ssr?: boolean): PartialResolvedId | undefined;
38
- export declare function tryOptimizedResolve(id: string, server: ViteDevServer, importer?: string): Promise<string | undefined>;
39
+ export declare function tryNodeResolve(id: string, importer: string | null | undefined, options: InternalResolveOptions, targetWeb: boolean, depsOptimizer?: DepsOptimizer, ssr?: boolean): PartialResolvedId | undefined;
40
+ export declare function tryOptimizedResolve(depsOptimizer: DepsOptimizer, id: string, importer?: string): Promise<string | undefined>;
39
41
  export declare function resolvePackageEntry(id: string, { dir, data, setResolvedCache, getResolvedCache }: PackageData, targetWeb: boolean, options: InternalResolveOptions): string | undefined;