更全面的正则: cjs2esm

This commit is contained in:
草鞋没号 2020-10-05 21:25:22 +08:00
parent e0613b86f8
commit e49e7eefe4
2 changed files with 8 additions and 10 deletions

View File

@ -45,13 +45,11 @@ const config: UserConfig = {
{
name: '@rollup/plugin-replace-electron-store',
transform(code, id) {
// const Store = require('electron-store')
const electronStoreReg = /(const|let|var)[\n\s]+(\w+)[\n\s]*=[\n\s]*require\(["|']electron-store["|']\)/g
// const Store = require('electron-store') -> import Store from 'electron-store'
const electronStoreReg = /(const|let|var)[\n\s]+(\w+)[\n\s]*=[\n\s]*require\(["|'](.+)["|']\)/g
const res = code.match(electronStoreReg)
/*@replace = import Store from 'electron-store'*/
// const replaceStore = /\/\*\s*@replace\s*=\s*([\S\s]+)\s*\*\//g
if (res) {
code = code.replace(electronStoreReg, `import $2 from 'electron-store'`)
code = code.replace(electronStoreReg, `import $2 from '$3'`)
}
return code
},

View File

@ -3509,10 +3509,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
typescript@^3.9.7:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==
typescript@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.3.tgz#153bbd468ef07725c1df9c77e8b453f8d36abba5"
integrity sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==
ultron@~1.1.0:
version "1.1.1"
@ -3597,7 +3597,7 @@ vary@^1.1.2:
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=
vite@^1.0.0-rc.1:
vite@^1.0.0-rc.4:
version "1.0.0-rc.4"
resolved "https://registry.yarnpkg.com/vite/-/vite-1.0.0-rc.4.tgz#210106136861b231704e6381ac9eb1bcd655d4f0"
integrity sha512-D9gpKKaE2U0YpIxNrSn+nlFPBT0sfg68Y1EReYW8YHMhbNFcxwS7RZIa1W/8Pq6yDfVRAhbOZNijv1mLG5pCEg==