2.0.3 • Published 3 years ago

import-alias-loader v2.0.3

Weekly downloads
11
License
ISC
Repository
-
Last release
3 years ago

import-alias-loader

A webpack loader used to resolve .js/.jsx file import alias(through AST) . Support import() syntax

EXAMPLE

from

import './color.@i18n.js';

import('../nation.@i18n.test').then(res => console.log(res));
const name2 = import('../../city.@i18n.js');

export const year = 100;
export { tabConfig as name } from './config.@i18n.js';

const str = `
    import name from './color.@i18n.js';
`;

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 './color.@i18n.js';
`;

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
        }
    }]
};