JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5272
  • Score
    100M100P100Q127379F
  • License MIT

Apply filename based replacements.

Package Exports

  • vite-plugin-filter-replace

Readme

vite-plugin-filter-replace npm

Apply filename based replacements.

import vue from '@vitejs/plugin-vue';
import replace from 'vite-plugin-filter-replace';

export default {
  plugins: [
    replace(
      [
        {
          filter: /\.css$/,
          replace: {
            from: /__foo__/g,
            to: 'foo',
          },
        },
        {
          filter: /\.css$/,
          replace: [
            { from: /__foo__/g, to: 'foo' },
            { from: /__(foo)__/g, to: '$1' },
          ],
        },
        {
          filter: ['node_modules/moment/dist/moment.js'],
          replace(source, path) {
            return 'some code';
          },
        },
      ],
      { enforce: 'pre' },
    ),
  ],
};

Options

function replace(replacements: Replacement[]): Plugin;
function replace(replacements: Replacement[], options: Options): Plugin;

interface Replacement {
  filter: RegExp | string | string[];
  replace: { from: RegExp | string | string[]; to: string | number };
}

interface Replacement {
  filter: RegExp | string | string[];
  replace: (source: string, path: string) => string;
}

interface Replacement {
  filter: RegExp | string | string[];
  replace: { from: RegExp | string | string[]; to: string | number }[];
}

interface Replacement {
  filter: RegExp | string | string[];
  replace: ((source: string, path: string) => string)[];
}

interface Options {
  enforce?: 'pre' | 'post';
  apply?: 'serve' | 'build';
}

License

MIT