Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESM 更新 #300

Open
22 tasks
Diablohu opened this issue Aug 6, 2021 · 1 comment
Open
22 tasks

ESM 更新 #300

Diablohu opened this issue Aug 6, 2021 · 1 comment
Labels

Comments

@Diablohu
Copy link
Member

Diablohu commented Aug 6, 2021

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

Packages

  • Root
  • create-koot-app
  • koot
  • koot-webpack
  • koot-cli
  • koot-electron
  • koot-qiankun

根层代码库

  • camelcase v7
  • chalk v5
  • inquirer v9

koot

  • chalk v5
  • execa v6
  • inquirer v9
  • is-port-reachable v4
  • ora v6
  • os-locale v6

koot-cli

  • chalk v5
  • latest-version v7
  • npm-email v4
  • ora v6
  • os-locale v6
  • package-json v8

判断项目类型决定,如果是 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
Copy link
Member Author

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant