import-alias-loader
v2.0.3
Published
A webpack loader used to resolve .js/.jsx file import alias(through AST) . Support `import()` syntax
Downloads
4
Maintainers
Readme
import-alias-loader
A webpack loader used to resolve .js/.jsx file import alias(through AST) . Support import()
syntax
EXAMPLE
from
import './[email protected]';
import('../[email protected]').then(res => console.log(res));
const name2 = import('../../[email protected]');
export const year = 100;
export { tabConfig as name } from './[email protected]';
const str = `
import name from './[email protected]';
`;
to
import "./color.en.js";
import("../nation.en.test").then(res => console.log(res));
const name2 = import("../../city.en.js");
export const year = 100;
export { tabConfig as name } from "./config.en.js";
const str = `
import name from './[email protected]';
`;
Installation
npm i import-alias-loader
API
{
enforce: 'pre', // run before other loaders
test: /\.(js|jsx)$/,
exclude: /(node_modules)/,
use: [{
loader: 'import-alias-loader',
options: {
alias: {
'@i18n': 'en',
'@color': (importPath, resourcePath) => importPath.replace('@color', 'red')
},
plugins: ['jsx'] // use for @babel/parser https://babeljs.io/docs/en/babel-parser#plugins
}
}]
};