Skip to content

ikeq/vite-plugin-filter-replace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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';
        },
      },
    ]),
  ],
};

Options

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

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

License

MIT

About

Apply filename based replacements.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published