index.cjs 1018 B

12345678910111213141516171819202122232425262728293031323334
  1. /* eslint-disable no-restricted-globals */
  2. // type utils
  3. module.exports.defineConfig = (config) => config
  4. // proxy cjs utils (sync functions)
  5. Object.assign(module.exports, require('./dist/node-cjs/publicUtils.cjs'))
  6. // async functions, can be redirect from ESM build
  7. const asyncFunctions = [
  8. 'build',
  9. 'createServer',
  10. 'preview',
  11. 'transformWithEsbuild',
  12. 'resolveConfig',
  13. 'optimizeDeps',
  14. 'formatPostcssSourceMap',
  15. 'loadConfigFromFile',
  16. 'preprocessCSS',
  17. ]
  18. asyncFunctions.forEach((name) => {
  19. module.exports[name] = (...args) =>
  20. import('./dist/node/index.js').then((i) => i[name](...args))
  21. })
  22. // some sync functions are marked not supported due to their complexity and uncommon usage
  23. const unsupportedCJS = ['resolvePackageEntry', 'resolvePackageData']
  24. unsupportedCJS.forEach((name) => {
  25. module.exports[name] = () => {
  26. throw new Error(
  27. `"${name}" is not supported in CJS build of Vite 4.\nPlease use ESM or dynamic imports \`const { ${name} } = await import('vite')\`.`,
  28. )
  29. }
  30. })