@uppercod/replace-import
v1.1.0
Published
Capture text fragments based on regular expressions that are executed for each line of the text
Downloads
178
Readme
@uppercod/replace-import
Allows replacing imports and exports in JS code, this package uses magic-string and es-module-lexer.
Install
npm install @uppercod/replace-import
Usage
import replaceImprot from "@uppercod/replace-import";
const { code, map, toString } = await replaceImport({
code: `
import style from "./style.css";
`,
/**
* @param {string} file
* @returns {boolean}
*/
filter: (file)=>file.endsWith(".css"),
/**
* @param {Token} token
* @returns {Promise<Token>|Token}
*/
replace(token){
token.toString =( )=>`const ${token.scope} = new URL("$`{token.src}`",import.meta.url);`
return token;
}
});