1 | warnCjsUsage()
|
---|
2 |
|
---|
3 | // type utils
|
---|
4 | module.exports.defineConfig = (config) => config
|
---|
5 |
|
---|
6 | // proxy cjs utils (sync functions)
|
---|
7 | Object.assign(module.exports, require('./dist/node-cjs/publicUtils.cjs'))
|
---|
8 |
|
---|
9 | // async functions, can be redirect from ESM build
|
---|
10 | const asyncFunctions = [
|
---|
11 | 'build',
|
---|
12 | 'createServer',
|
---|
13 | 'preview',
|
---|
14 | 'transformWithEsbuild',
|
---|
15 | 'resolveConfig',
|
---|
16 | 'optimizeDeps',
|
---|
17 | 'formatPostcssSourceMap',
|
---|
18 | 'loadConfigFromFile',
|
---|
19 | 'preprocessCSS',
|
---|
20 | ]
|
---|
21 | asyncFunctions.forEach((name) => {
|
---|
22 | module.exports[name] = (...args) =>
|
---|
23 | import('./dist/node/index.js').then((i) => i[name](...args))
|
---|
24 | })
|
---|
25 |
|
---|
26 | function warnCjsUsage() {
|
---|
27 | if (process.env.VITE_CJS_IGNORE_WARNING) return
|
---|
28 | const logLevelIndex = process.argv.findIndex((arg) =>
|
---|
29 | /^(?:-l|--logLevel)/.test(arg),
|
---|
30 | )
|
---|
31 | if (logLevelIndex > 0) {
|
---|
32 | const logLevelValue = process.argv[logLevelIndex + 1]
|
---|
33 | if (logLevelValue === 'silent' || logLevelValue === 'error') {
|
---|
34 | return
|
---|
35 | }
|
---|
36 | if (/silent|error/.test(process.argv[logLevelIndex])) {
|
---|
37 | return
|
---|
38 | }
|
---|
39 | }
|
---|
40 | const yellow = (str) => `\u001b[33m${str}\u001b[39m`
|
---|
41 | console.warn(
|
---|
42 | yellow(
|
---|
43 | `The CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.`,
|
---|
44 | ),
|
---|
45 | )
|
---|
46 | if (process.env.VITE_CJS_TRACE) {
|
---|
47 | const e = {}
|
---|
48 | const stackTraceLimit = Error.stackTraceLimit
|
---|
49 | Error.stackTraceLimit = 100
|
---|
50 | Error.captureStackTrace(e)
|
---|
51 | Error.stackTraceLimit = stackTraceLimit
|
---|
52 | console.log(
|
---|
53 | e.stack
|
---|
54 | .split('\n')
|
---|
55 | .slice(1)
|
---|
56 | .filter((line) => !line.includes('(node:'))
|
---|
57 | .join('\n'),
|
---|
58 | )
|
---|
59 | }
|
---|
60 | }
|
---|