feat: config file supports "type": "module" in package.json
This commit is contained in:
parent
40a1b64639
commit
694e134a52
|
@ -20,7 +20,7 @@ import assetPlugin from './plugins/asset'
|
||||||
import workerPlugin from './plugins/worker'
|
import workerPlugin from './plugins/worker'
|
||||||
import importMetaUrlPlugin from './plugins/importMetaUrl'
|
import importMetaUrlPlugin from './plugins/importMetaUrl'
|
||||||
import esmShimPlugin from './plugins/esm'
|
import esmShimPlugin from './plugins/esm'
|
||||||
import { isObject } from './utils'
|
import { isObject, isFilePathESM } from './utils'
|
||||||
|
|
||||||
export { defineConfig as defineViteConfig } from 'vite'
|
export { defineConfig as defineViteConfig } from 'vite'
|
||||||
|
|
||||||
|
@ -240,11 +240,7 @@ export async function loadConfigFromFile(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// electron does not support adding type: "module" to package.json
|
const isESM = isFilePathESM(resolvedPath)
|
||||||
let isESM = false
|
|
||||||
if (/\.m[jt]s$/.test(resolvedPath) || resolvedPath.endsWith('.ts')) {
|
|
||||||
isESM = true
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const bundled = await bundleConfigFile(resolvedPath, isESM)
|
const bundled = await bundleConfigFile(resolvedPath, isESM)
|
||||||
|
|
11
src/utils.ts
11
src/utils.ts
|
@ -73,3 +73,14 @@ export function loadPackageData(root = process.cwd()): PackageData | null {
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isFilePathESM(filePath: string): boolean {
|
||||||
|
if (/\.m[jt]s$/.test(filePath) || filePath.endsWith('.ts')) {
|
||||||
|
return true
|
||||||
|
} else if (/\.c[jt]s$/.test(filePath)) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
const pkg = loadPackageData()
|
||||||
|
return pkg?.type === 'module'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue