1.0.2 โ€ข Published 8 months ago

@marcuwynu23/webpack-plugin-alias-resolver v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

webpack-plugin-alias-resolver

๐Ÿ”ง A Webpack plugin that rewrites alias-based imports (like @/) into relative paths during build time. Useful for TypeScript or Babel outputs that retain unresolved alias paths.


๐Ÿ“ฆ Installation

npm install --save-dev @marcuwynu23/webpack-plugin-alias-resolver

Webpack is a peer dependency. Ensure it's installed:

npm install --save-dev webpack

๐Ÿš€ Usage

Add to your webpack.config.js:

import AliasResolverPlugin from "@marcuwynu23/webpack-plugin-alias-resolver";

export default {
  // ...your config
  plugins: [
    new AliasResolverPlugin({
      alias: "@/",
      baseDir: "js-generated", // folder where alias actually resolves to
      targetDir: "js-generated", // folder to scan and fix
      fileTypes: ["js", "ts", "json"], // file extensions to rewrite
    }),
  ],
};

โš™๏ธ Options

OptionTypeDefaultDescription
aliasstring"@/"The alias prefix used in your imports (@/, ~/, etc.)
baseDirstring"dist"Where the alias path actually resolves to (usually output dir)
targetDirstring"dist"Directory to scan and rewrite imports in
fileTypesstring \| string[]"js"File types to rewrite. Use "js", "ts", "both", or an array like ["js", "json"]

โœจ What It Does

This plugin searches files inside targetDir and rewrites lines like:

import { thing } from "@/utils/helper";

โžก๏ธ into:

import { thing } from "../../utils/helper";

This is useful when you're compiling code and the final output still contains unresolved aliases.


๐Ÿ’ก Example Project Structure

project/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ utils/helper.ts
โ”œโ”€โ”€ js-generated/
โ”‚   โ””โ”€โ”€ utils/helper.js       โ† compiled output
โ”œโ”€โ”€ webpack.config.js

๐Ÿงช TypeScript Support

This plugin is fully written in TypeScript and ships with type declarations.


๐Ÿ“ License

MIT ยฉ 2025 Your Name

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago