Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8ff2ac
commit 1b19340
Showing
7 changed files
with
2,272 additions
and
32 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const { extname } = require('path') | ||
|
||
function namedAssetImportPlugin({ types: t }) { | ||
const visited = new WeakSet() | ||
|
||
return { | ||
visitor: { | ||
ImportDeclaration(path, { opts: { loaderMap } }) { | ||
const sourcePath = path.node.source.value | ||
const ext = extname(sourcePath).substr(1) | ||
|
||
if (visited.has(path.node) || sourcePath.indexOf('!') !== -1) { | ||
return | ||
} | ||
|
||
if (loaderMap[ext]) { | ||
path.replaceWithMultiple( | ||
path.node.specifiers.map(specifier => { | ||
if (t.isImportDefaultSpecifier(specifier)) { | ||
const newDefaultImport = t.importDeclaration( | ||
[ | ||
t.importDefaultSpecifier( | ||
t.identifier(specifier.local.name) | ||
), | ||
], | ||
t.stringLiteral(sourcePath) | ||
) | ||
|
||
visited.add(newDefaultImport) | ||
return newDefaultImport | ||
} | ||
|
||
const newImport = t.importDeclaration( | ||
[ | ||
t.importSpecifier( | ||
t.identifier(specifier.local.name), | ||
t.identifier(specifier.imported.name) | ||
), | ||
], | ||
t.stringLiteral( | ||
loaderMap[ext][specifier.imported.name] | ||
? loaderMap[ext][specifier.imported.name].replace( | ||
/\[path\]/, | ||
sourcePath | ||
) | ||
: sourcePath | ||
) | ||
) | ||
|
||
visited.add(newImport) | ||
return newImport | ||
}) | ||
) | ||
} | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
module.exports = namedAssetImportPlugin |
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,9 @@ | ||
{ | ||
"name": "babel-plugin-named-asset-import", | ||
"version": "0.11.1", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"peerDependencies": { | ||
"@babel/core": "^7.1.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# docz-plugin-svgr [MOVED] | ||
# docz-plugin-svgr [DEPRECATED] | ||
|
||
In order to improve monorepo performance, we moved it to [another repo](https://github.com/pedronauck/docz-plugin-svgr)! | ||
This plugin is deprecated. Now svgr loader is built in docz. |
Oops, something went wrong.