index.cjs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* eslint-disable no-restricted-globals */
  2. warnCjsUsage()
  3. // type utils
  4. module.exports.defineConfig = (config) => config
  5. // proxy cjs utils (sync functions)
  6. // eslint-disable-next-line n/no-missing-require -- will be generated by build
  7. Object.assign(module.exports, require('./dist/node-cjs/publicUtils.cjs'))
  8. // async functions, can be redirect from ESM build
  9. const asyncFunctions = [
  10. 'build',
  11. 'createServer',
  12. 'preview',
  13. 'transformWithEsbuild',
  14. 'resolveConfig',
  15. 'optimizeDeps',
  16. 'formatPostcssSourceMap',
  17. 'loadConfigFromFile',
  18. 'preprocessCSS',
  19. ]
  20. asyncFunctions.forEach((name) => {
  21. module.exports[name] = (...args) =>
  22. import('./dist/node/index.js').then((i) => i[name](...args))
  23. })
  24. function warnCjsUsage() {
  25. if (process.env.VITE_CJS_IGNORE_WARNING) return
  26. const yellow = (str) => `\u001b[33m${str}\u001b[39m`
  27. const log = process.env.VITE_CJS_TRACE ? console.trace : console.warn
  28. log(
  29. yellow(
  30. `The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.`,
  31. ),
  32. )
  33. }