This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch from umijs/umi-next#580 * feat(father): add babel transformer * example(father): test babel transformer * chore: remove unused code * chore(father): update pnpm-lock * feat(father): replace babel-plugin with @umijs/babel-preset-umi
- Loading branch information
1 parent
2a69b6e
commit c98d1b2
Showing
12 changed files
with
209 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
const path = require('path'); | ||
|
||
export default { | ||
esm: {}, | ||
esm: { | ||
output: 'dist/esm', | ||
}, | ||
umd: { | ||
output: 'dist/umd', | ||
}, | ||
alias: { | ||
'@': path.resolve(__dirname, './src'), | ||
}, | ||
platform: 'browser', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Content { | ||
say() { | ||
return 'Hello father 3'; | ||
} | ||
} | ||
|
||
export default new Content().say(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
export default 'Hello father 3'; | ||
import content from '@/content'; | ||
/* | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
// const content = 'Hello' | ||
function App() { | ||
return <div>{content}</div>; | ||
} | ||
// @ts-ignore | ||
const root = ReactDOM.createRoot(document.getElementById('root')); | ||
root.render(<App />); | ||
*/ | ||
console.log(content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": true, | ||
"declarationMap": true, | ||
"esModuleInterop": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"target": "es2015", | ||
"jsx": "react", | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// @ts-ignore | ||
import mapToRelative from 'babel-plugin-module-resolver/lib/mapToRelative'; | ||
// @ts-ignore | ||
import normalizeOptions from 'babel-plugin-module-resolver/lib/normalizeOptions'; | ||
// @ts-ignore | ||
import resolvePath from 'babel-plugin-module-resolver/lib/resolvePath'; | ||
// @ts-ignore | ||
import * as utils from 'babel-plugin-module-resolver/lib/utils'; | ||
import path from 'path'; | ||
|
||
interface INormalizeOptions { | ||
cwd: string; | ||
extensions: Array<string>; | ||
alias: Array<[RegExp, Function]>; | ||
} | ||
|
||
function resolvePathFromAliasConfig( | ||
sourcePath: string, | ||
currentFile: string, | ||
opts: Record<string, object>, | ||
) { | ||
if (utils.isRelativePath(sourcePath)) { | ||
return sourcePath; | ||
} | ||
|
||
const normalizedOpts: INormalizeOptions = normalizeOptions(currentFile, opts); | ||
|
||
const absoluteCurrentFile = path.resolve(currentFile); | ||
|
||
let aliasedSourceFile!: Array<string>; | ||
normalizedOpts.alias.find(([regExp, substitute]) => { | ||
const execResult = regExp.exec(sourcePath); | ||
|
||
if (execResult === null) { | ||
return false; | ||
} | ||
|
||
aliasedSourceFile = substitute(execResult); | ||
return true; | ||
}); | ||
|
||
if (!aliasedSourceFile) { | ||
return resolvePath(sourcePath, absoluteCurrentFile, normalizedOpts); | ||
} | ||
|
||
if (Array.isArray(aliasedSourceFile)) { | ||
return aliasedSourceFile | ||
.map((asf) => { | ||
if (utils.isRelativePath(asf)) { | ||
return utils.toLocalPath( | ||
utils.toPosixPath( | ||
mapToRelative.default( | ||
normalizedOpts.cwd, | ||
absoluteCurrentFile, | ||
asf, | ||
), | ||
), | ||
); | ||
} | ||
|
||
return asf; | ||
}) | ||
.find((src) => | ||
utils.nodeResolvePath( | ||
src, | ||
path.dirname(absoluteCurrentFile), | ||
normalizedOpts.extensions, | ||
), | ||
); | ||
} | ||
|
||
return utils.toLocalPath( | ||
utils.toPosixPath( | ||
mapToRelative(normalizedOpts.cwd, absoluteCurrentFile, aliasedSourceFile), | ||
), | ||
); | ||
} | ||
|
||
export default resolvePathFromAliasConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters