vite 2.0.4 → 2.1.2

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.

Potentially problematic release.


This version of vite might be problematic. Click here for more details.

package/dist/node/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var require$$0$1 = require('events');
4
- var build = require('./chunks/dep-1bdbec90.js');
4
+ var build = require('./chunks/dep-efe32886.js');
5
5
  var os = require('os');
6
6
  var path = require('path');
7
7
  var tty = require('tty');
@@ -16,6 +16,7 @@ require('resolve');
16
16
  require('module');
17
17
  require('readline');
18
18
  require('crypto');
19
+ require('esbuild');
19
20
  require('worker_threads');
20
21
  require('assert');
21
22
  require('https');
@@ -727,7 +728,7 @@ function getCharsetPriority(charset, accepted, index) {
727
728
  var priority = {o: -1, q: 0, s: 0};
728
729
 
729
730
  for (var i = 0; i < accepted.length; i++) {
730
- var spec = specify(charset, accepted[i], index);
731
+ var spec = specify$3(charset, accepted[i], index);
731
732
 
732
733
  if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
733
734
  priority = spec;
@@ -742,7 +743,7 @@ function getCharsetPriority(charset, accepted, index) {
742
743
  * @private
743
744
  */
744
745
 
745
- function specify(charset, spec, index) {
746
+ function specify$3(charset, spec, index) {
746
747
  var s = 0;
747
748
  if(spec.charset.toLowerCase() === charset.toLowerCase()){
748
749
  s |= 1;
@@ -770,8 +771,8 @@ function preferredCharsets(accept, provided) {
770
771
  if (!provided) {
771
772
  // sorted list of all charsets
772
773
  return accepts
773
- .filter(isQuality)
774
- .sort(compareSpecs)
774
+ .filter(isQuality$3)
775
+ .sort(compareSpecs$3)
775
776
  .map(getFullCharset);
776
777
  }
777
778
 
@@ -780,7 +781,7 @@ function preferredCharsets(accept, provided) {
780
781
  });
781
782
 
782
783
  // sorted list of accepted charsets
783
- return priorities.filter(isQuality).sort(compareSpecs).map(function getCharset(priority) {
784
+ return priorities.filter(isQuality$3).sort(compareSpecs$3).map(function getCharset(priority) {
784
785
  return provided[priorities.indexOf(priority)];
785
786
  });
786
787
  }
@@ -790,7 +791,7 @@ function preferredCharsets(accept, provided) {
790
791
  * @private
791
792
  */
792
793
 
793
- function compareSpecs(a, b) {
794
+ function compareSpecs$3(a, b) {
794
795
  return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
795
796
  }
796
797
 
@@ -808,7 +809,7 @@ function getFullCharset(spec) {
808
809
  * @private
809
810
  */
810
811
 
811
- function isQuality(spec) {
812
+ function isQuality$3(spec) {
812
813
  return spec.q > 0;
813
814
  }
814
815
  charset.preferredCharsets = preferredCharsets_1;
@@ -851,7 +852,7 @@ function parseAcceptEncoding(accept) {
851
852
 
852
853
  if (encoding) {
853
854
  accepts[j++] = encoding;
854
- hasIdentity = hasIdentity || specify$1('identity', encoding);
855
+ hasIdentity = hasIdentity || specify$2('identity', encoding);
855
856
  minQuality = Math.min(minQuality, encoding.q || 1);
856
857
  }
857
858
  }
@@ -912,7 +913,7 @@ function getEncodingPriority(encoding, accepted, index) {
912
913
  var priority = {o: -1, q: 0, s: 0};
913
914
 
914
915
  for (var i = 0; i < accepted.length; i++) {
915
- var spec = specify$1(encoding, accepted[i], index);
916
+ var spec = specify$2(encoding, accepted[i], index);
916
917
 
917
918
  if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
918
919
  priority = spec;
@@ -927,7 +928,7 @@ function getEncodingPriority(encoding, accepted, index) {
927
928
  * @private
928
929
  */
929
930
 
930
- function specify$1(encoding, spec, index) {
931
+ function specify$2(encoding, spec, index) {
931
932
  var s = 0;
932
933
  if(spec.encoding.toLowerCase() === encoding.toLowerCase()){
933
934
  s |= 1;
@@ -953,8 +954,8 @@ function preferredEncodings(accept, provided) {
953
954
  if (!provided) {
954
955
  // sorted list of all encodings
955
956
  return accepts
956
- .filter(isQuality$1)
957
- .sort(compareSpecs$1)
957
+ .filter(isQuality$2)
958
+ .sort(compareSpecs$2)
958
959
  .map(getFullEncoding);
959
960
  }
960
961
 
@@ -963,7 +964,7 @@ function preferredEncodings(accept, provided) {
963
964
  });
964
965
 
965
966
  // sorted list of accepted encodings
966
- return priorities.filter(isQuality$1).sort(compareSpecs$1).map(function getEncoding(priority) {
967
+ return priorities.filter(isQuality$2).sort(compareSpecs$2).map(function getEncoding(priority) {
967
968
  return provided[priorities.indexOf(priority)];
968
969
  });
969
970
  }
@@ -973,7 +974,7 @@ function preferredEncodings(accept, provided) {
973
974
  * @private
974
975
  */
975
976
 
976
- function compareSpecs$1(a, b) {
977
+ function compareSpecs$2(a, b) {
977
978
  return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
978
979
  }
979
980
 
@@ -991,7 +992,7 @@ function getFullEncoding(spec) {
991
992
  * @private
992
993
  */
993
994
 
994
- function isQuality$1(spec) {
995
+ function isQuality$2(spec) {
995
996
  return spec.q > 0;
996
997
  }
997
998
  encoding.preferredEncodings = preferredEncodings_1;
@@ -1083,7 +1084,7 @@ function getLanguagePriority(language, accepted, index) {
1083
1084
  var priority = {o: -1, q: 0, s: 0};
1084
1085
 
1085
1086
  for (var i = 0; i < accepted.length; i++) {
1086
- var spec = specify$2(language, accepted[i], index);
1087
+ var spec = specify$1(language, accepted[i], index);
1087
1088
 
1088
1089
  if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
1089
1090
  priority = spec;
@@ -1098,7 +1099,7 @@ function getLanguagePriority(language, accepted, index) {
1098
1099
  * @private
1099
1100
  */
1100
1101
 
1101
- function specify$2(language, spec, index) {
1102
+ function specify$1(language, spec, index) {
1102
1103
  var p = parseLanguage(language);
1103
1104
  if (!p) return null;
1104
1105
  var s = 0;
@@ -1131,8 +1132,8 @@ function preferredLanguages(accept, provided) {
1131
1132
  if (!provided) {
1132
1133
  // sorted list of all languages
1133
1134
  return accepts
1134
- .filter(isQuality$2)
1135
- .sort(compareSpecs$2)
1135
+ .filter(isQuality$1)
1136
+ .sort(compareSpecs$1)
1136
1137
  .map(getFullLanguage);
1137
1138
  }
1138
1139
 
@@ -1141,7 +1142,7 @@ function preferredLanguages(accept, provided) {
1141
1142
  });
1142
1143
 
1143
1144
  // sorted list of accepted languages
1144
- return priorities.filter(isQuality$2).sort(compareSpecs$2).map(function getLanguage(priority) {
1145
+ return priorities.filter(isQuality$1).sort(compareSpecs$1).map(function getLanguage(priority) {
1145
1146
  return provided[priorities.indexOf(priority)];
1146
1147
  });
1147
1148
  }
@@ -1151,7 +1152,7 @@ function preferredLanguages(accept, provided) {
1151
1152
  * @private
1152
1153
  */
1153
1154
 
1154
- function compareSpecs$2(a, b) {
1155
+ function compareSpecs$1(a, b) {
1155
1156
  return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
1156
1157
  }
1157
1158
 
@@ -1169,7 +1170,7 @@ function getFullLanguage(spec) {
1169
1170
  * @private
1170
1171
  */
1171
1172
 
1172
- function isQuality$2(spec) {
1173
+ function isQuality$1(spec) {
1173
1174
  return spec.q > 0;
1174
1175
  }
1175
1176
  language.preferredLanguages = preferredLanguages_1;
@@ -1274,7 +1275,7 @@ function getMediaTypePriority(type, accepted, index) {
1274
1275
  var priority = {o: -1, q: 0, s: 0};
1275
1276
 
1276
1277
  for (var i = 0; i < accepted.length; i++) {
1277
- var spec = specify$3(type, accepted[i], index);
1278
+ var spec = specify(type, accepted[i], index);
1278
1279
 
1279
1280
  if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
1280
1281
  priority = spec;
@@ -1289,7 +1290,7 @@ function getMediaTypePriority(type, accepted, index) {
1289
1290
  * @private
1290
1291
  */
1291
1292
 
1292
- function specify$3(type, spec, index) {
1293
+ function specify(type, spec, index) {
1293
1294
  var p = parseMediaType(type);
1294
1295
  var s = 0;
1295
1296
 
@@ -1340,8 +1341,8 @@ function preferredMediaTypes(accept, provided) {
1340
1341
  if (!provided) {
1341
1342
  // sorted list of all types
1342
1343
  return accepts
1343
- .filter(isQuality$3)
1344
- .sort(compareSpecs$3)
1344
+ .filter(isQuality)
1345
+ .sort(compareSpecs)
1345
1346
  .map(getFullType);
1346
1347
  }
1347
1348
 
@@ -1350,7 +1351,7 @@ function preferredMediaTypes(accept, provided) {
1350
1351
  });
1351
1352
 
1352
1353
  // sorted list of accepted types
1353
- return priorities.filter(isQuality$3).sort(compareSpecs$3).map(function getType(priority) {
1354
+ return priorities.filter(isQuality).sort(compareSpecs).map(function getType(priority) {
1354
1355
  return provided[priorities.indexOf(priority)];
1355
1356
  });
1356
1357
  }
@@ -1360,7 +1361,7 @@ function preferredMediaTypes(accept, provided) {
1360
1361
  * @private
1361
1362
  */
1362
1363
 
1363
- function compareSpecs$3(a, b) {
1364
+ function compareSpecs(a, b) {
1364
1365
  return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
1365
1366
  }
1366
1367
 
@@ -1378,7 +1379,7 @@ function getFullType(spec) {
1378
1379
  * @private
1379
1380
  */
1380
1381
 
1381
- function isQuality$3(spec) {
1382
+ function isQuality(spec) {
1382
1383
  return spec.q > 0;
1383
1384
  }
1384
1385
 
@@ -12510,7 +12511,7 @@ function validMime (type) {
12510
12511
 
12511
12512
  var bytes_1 = bytes;
12512
12513
  var format_1 = format;
12513
- var parse_1 = parse;
12514
+ var parse_1 = parse$1;
12514
12515
 
12515
12516
  /**
12516
12517
  * Module variables.
@@ -12548,7 +12549,7 @@ var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb)$/i;
12548
12549
 
12549
12550
  function bytes(value, options) {
12550
12551
  if (typeof value === 'string') {
12551
- return parse(value);
12552
+ return parse$1(value);
12552
12553
  }
12553
12554
 
12554
12555
  if (typeof value === 'number') {
@@ -12627,7 +12628,7 @@ function format(value, options) {
12627
12628
  * @public
12628
12629
  */
12629
12630
 
12630
- function parse(val) {
12631
+ function parse$1(val) {
12631
12632
  if (typeof val === 'number' && !isNaN(val)) {
12632
12633
  return val;
12633
12634
  }
@@ -12740,7 +12741,7 @@ var ms = function(val, options) {
12740
12741
  options = options || {};
12741
12742
  var type = typeof val;
12742
12743
  if (type === 'string' && val.length > 0) {
12743
- return parse$1(val);
12744
+ return parse(val);
12744
12745
  } else if (type === 'number' && isNaN(val) === false) {
12745
12746
  return options.long ? fmtLong(val) : fmtShort(val);
12746
12747
  }
@@ -12758,7 +12759,7 @@ var ms = function(val, options) {
12758
12759
  * @api private
12759
12760
  */
12760
12761
 
12761
- function parse$1(str) {
12762
+ function parse(str) {
12762
12763
  str = String(str);
12763
12764
  if (str.length > 100) {
12764
12765
  return;
@@ -12865,7 +12866,7 @@ function plural(ms, n, name) {
12865
12866
  return Math.ceil(ms / n) + ' ' + name + 's';
12866
12867
  }
12867
12868
 
12868
- var debug = build.createCommonjsModule(function (module, exports) {
12869
+ var debug$1 = build.createCommonjsModule(function (module, exports) {
12869
12870
  /**
12870
12871
  * This is the common logic for both the Node.js and web browser
12871
12872
  * implementations of `debug()`.
@@ -13076,7 +13077,7 @@ function coerce(val) {
13076
13077
  */
13077
13078
 
13078
13079
  var browser = build.createCommonjsModule(function (module, exports) {
13079
- exports = module.exports = debug;
13080
+ exports = module.exports = debug$1;
13080
13081
  exports.log = log;
13081
13082
  exports.formatArgs = formatArgs;
13082
13083
  exports.save = save;
@@ -13268,7 +13269,7 @@ var node = build.createCommonjsModule(function (module, exports) {
13268
13269
  * Expose `debug()` as the module.
13269
13270
  */
13270
13271
 
13271
- exports = module.exports = debug;
13272
+ exports = module.exports = debug$1;
13272
13273
  exports.init = init;
13273
13274
  exports.log = log;
13274
13275
  exports.formatArgs = formatArgs;
@@ -13667,7 +13668,7 @@ function setWriteHeadHeaders (statusCode) {
13667
13668
  var Buffer = build.safeBuffer.Buffer;
13668
13669
 
13669
13670
 
13670
- var debug$1 = src('compression');
13671
+ var debug = src('compression');
13671
13672
 
13672
13673
 
13673
13674
 
@@ -13781,7 +13782,7 @@ function compression (options) {
13781
13782
  };
13782
13783
 
13783
13784
  function nocompress (msg) {
13784
- debug$1('no compression: %s', msg);
13785
+ debug('no compression: %s', msg);
13785
13786
  addListeners(res, _on, listeners);
13786
13787
  listeners = null;
13787
13788
  }
@@ -13838,7 +13839,7 @@ function compression (options) {
13838
13839
  }
13839
13840
 
13840
13841
  // compression stream
13841
- debug$1('%s compression', method);
13842
+ debug('%s compression', method);
13842
13843
  stream = method === 'gzip'
13843
13844
  ? zlib_1__default.createGzip(opts)
13844
13845
  : zlib_1__default.createDeflate(opts);
@@ -13904,7 +13905,7 @@ function shouldCompress (req, res) {
13904
13905
  var type = res.getHeader('Content-Type');
13905
13906
 
13906
13907
  if (type === undefined || !compressible_1(type)) {
13907
- debug$1('%s not compressible', type);
13908
+ debug('%s not compressible', type);
13908
13909
  return false
13909
13910
  }
13910
13911
 
@@ -13937,21 +13938,30 @@ function toBuffer (chunk, encoding) {
13937
13938
  }
13938
13939
  compression_1.filter = filter;
13939
13940
 
13940
- async function serve(config, port = 5000) {
13941
+ async function preview(config, port = 5000) {
13941
13942
  const app = build.connect();
13943
+ const httpServer = await build.resolveHttpServer(config.server, app);
13944
+ // cors
13945
+ const { cors } = config.server;
13946
+ if (cors !== false) {
13947
+ app.use(build.lib(typeof cors === 'boolean' ? {} : cors));
13948
+ }
13949
+ // proxy
13950
+ if (config.server.proxy) {
13951
+ app.use(build.proxyMiddleware(httpServer, config));
13952
+ }
13942
13953
  app.use(compression_1());
13943
13954
  const distDir = path__default.resolve(config.root, config.build.outDir);
13944
13955
  app.use(config.base, build.sirv(distDir, {
13945
13956
  etag: true,
13946
13957
  single: true
13947
13958
  }));
13948
- const server = await build.resolveHttpServer(config.server, app);
13949
13959
  const options = config.server || {};
13950
13960
  const hostname = options.host || 'localhost';
13951
13961
  const protocol = options.https ? 'https' : 'http';
13952
13962
  const logger = config.logger;
13953
13963
  const base = config.base;
13954
- server.listen(port, () => {
13964
+ httpServer.listen(port, () => {
13955
13965
  logger.info(build.source.cyan(`\n vite v${require('vite/package.json').version}`) +
13956
13966
  build.source.green(` build preview server running at:\n`));
13957
13967
  const interfaces = os__default.networkInterfaces();
@@ -14022,7 +14032,7 @@ cli
14022
14032
  .action(async (root, options) => {
14023
14033
  // output structure is preserved even after bundling so require()
14024
14034
  // is ok here
14025
- const { createServer } = await Promise.resolve().then(function () { return require('./chunks/dep-1bdbec90.js'); }).then(function (n) { return n.index$1; });
14035
+ const { createServer } = await Promise.resolve().then(function () { return require('./chunks/dep-efe32886.js'); }).then(function (n) { return n.index$1; });
14026
14036
  try {
14027
14037
  const server = await createServer({
14028
14038
  root,
@@ -14056,7 +14066,7 @@ cli
14056
14066
  .option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
14057
14067
  .option('-m, --mode <mode>', `[string] set env mode`)
14058
14068
  .action(async (root, options) => {
14059
- const { build: build$1 } = await Promise.resolve().then(function () { return require('./chunks/dep-1bdbec90.js'); }).then(function (n) { return n.build$1; });
14069
+ const { build: build$1 } = await Promise.resolve().then(function () { return require('./chunks/dep-efe32886.js'); }).then(function (n) { return n.build$1; });
14060
14070
  const buildOptions = cleanOptions(options);
14061
14071
  try {
14062
14072
  await build$1({
@@ -14079,7 +14089,7 @@ cli
14079
14089
  .command('optimize [root]')
14080
14090
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
14081
14091
  .action(async (root, options) => {
14082
- const { optimizeDeps } = await Promise.resolve().then(function () { return require('./chunks/dep-1bdbec90.js'); }).then(function (n) { return n.index; });
14092
+ const { optimizeDeps } = await Promise.resolve().then(function () { return require('./chunks/dep-efe32886.js'); }).then(function (n) { return n.index; });
14083
14093
  try {
14084
14094
  const config = await build.resolveConfig({
14085
14095
  root,
@@ -14109,7 +14119,7 @@ cli
14109
14119
  open: options.open
14110
14120
  }
14111
14121
  }, 'serve', 'development');
14112
- await serve(config, options.port);
14122
+ await preview(config, options.port);
14113
14123
  }
14114
14124
  catch (e) {
14115
14125
  build.createLogger(options.logLevel).error(build.source.red(`error when starting preview server:\n${e.stack}`));
@@ -21,6 +21,7 @@ import { RequestOptions as RequestOptions_2 } from 'https';
21
21
  import { ResolveIdResult } from 'rollup';
22
22
  import { RollupOptions } from 'rollup';
23
23
  import { RollupOutput } from 'rollup';
24
+ import { Server } from 'http';
24
25
  import { ServerResponse } from 'http';
25
26
  import { SourceDescription } from 'rollup';
26
27
  import { SourceMap } from 'rollup';
@@ -913,7 +914,7 @@ export declare interface CSSModulesOptions {
913
914
  generateScopedName?: string | ((name: string, filename: string, css: string) => string);
914
915
  hashPrefix?: string;
915
916
  /**
916
- * default: 'camelCase'
917
+ * default: null
917
918
  */
918
919
  localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly' | null;
919
920
  }
@@ -1106,6 +1107,7 @@ export declare interface HmrOptions {
1106
1107
  path?: string;
1107
1108
  timeout?: number;
1108
1109
  overlay?: boolean;
1110
+ server?: Server;
1109
1111
  }
1110
1112
 
1111
1113
  export declare type HMRPayload =
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var build = require('./chunks/dep-1bdbec90.js');
5
+ var build = require('./chunks/dep-efe32886.js');
6
6
  require('os');
7
7
  require('fs');
8
8
  require('path');
@@ -18,6 +18,7 @@ require('resolve');
18
18
  require('module');
19
19
  require('readline');
20
20
  require('crypto');
21
+ require('esbuild');
21
22
  require('worker_threads');
22
23
  require('assert');
23
24
  require('https');