1.0.0 • Published 8 months ago

@awenovations/vite-plugin-replace v1.0.0

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

Vite Plugin Replace

With this plugin text in sourcecode could be replaced before bundling.

Fork Details

Originally forked from leanupjs/vite-plugin-replace, because it doesn't seem to be maintained anymore and is now out of date with critical vulns.

Fork Changes

Updates all packages and peer dependencies to the latest.

Motivation

The initial reason for implementing a new plugin to replace it was that the approach of @rollup/plugin-replace is not flexible enough. So we looked at what JavaScript replace actually offers us.

Declaration of the Replacement (interface):

interface Replacement {
  from: RegExp | string;
  to: string | Function
}
AttributeTypeDescription
fromregexp | string
tostring | string

Installation

npm i -D vite-plugin-replace

Usage

import packageJson from "./package.json";
import { replaceCodePlugin } from "vite-plugin-replace";

module.exports = mergeConfig(config, {
  plugins: [
    replaceCodePlugin({
      replacements: [
        {
          from: "__CLI_NAME__",
          to: packageJson.name,
        },
        {
          from: /__CLI_VERSION__/g,
          to: packageJson.version,
        },
      ],
    }),
  ],
});
1.0.0

8 months ago