cmux / koot

Koot是基于React和Koa的WEB全栈技术解决方案。
https://koot.js.org
Apache License 2.0
67 stars 13 forks source link

ESM 更新 #300

Open Diablohu opened 3 years ago

Diablohu commented 3 years ago

更新方式 https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

Packages

根层代码库

koot

koot-cli


判断项目类型决定,如果是 ESM 添加

output: {
    chunkFormat: 'module',
    chunkLoading: 'import',
}

package.json

{
    "type": "module"
}

正则替换

^[a-zA-Z]+[ ]*(.+?)[ ]*=[ ]*require\((.+?)\) -> import $1 from $2


其他问题

import { dirname } from 'path';
import { fileURLToPath } from 'url';

export default () => dirname(fileURLToPath(import.meta.url));

__filename

Diablohu commented 1 year ago

some notes

import(fileUrl).then(mod => mod.default)

import { glob, globSync } from 'glob'
import { osLocale } from 'os-locale'

import { createRequire } from 'module';
const require = createRequire(import.meta.url);