Giter Club home page Giter Club logo

vite-plugin-filter-replace's Introduction

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

vite-plugin-filter-replace's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vite-plugin-filter-replace's Issues

Incorrect example is used in readme

Replace

{
          filter: ['node_modules/moment/dist/moment.js'],
          replace(path, source) {
            return 'some code';
          },
        },

with

{
          filter: ['node_modules/moment/dist/moment.js'],
          replace(source, path) {
            return 'some code';
          },
        },

Import doesn't work.

Hi, there is an issue with the import.

image

Using:

import filterReplace from 'vite-plugin-filter-replace';

image

image

Doesnt work

I have js file contain below code:

 throw new Error("program has already exited __foo__");

I want to replace program to zzz and __foo__ to xxx I tried below code in vite.config.ts :

filterReplace([
      {
        filter: /\.js/,
        replace: [
          {from: /__foo__/g, to: 'xxx'},
          {from: 'program', to: 'zzz'},
        ],
      },
      {apply: 'build'}]),

but doesnt work. the generated file still has same string. What's wrong ?

didn't generate a sourcemap

When I build in vite, show some message in logs.

(vite-plugin-filter-replace plugin) Sourcemap is likely to be incorrect: a plugin (vite-plugin-filter-replace) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help
(vite-plugin-filter-replace plugin) Sourcemap is likely to be incorrect: a plugin (vite-plugin-filter-replace) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help
(vite-plugin-filter-replace plugin) Sourcemap is likely to be incorrect: a plugin (vite-plugin-filter-replace) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help
(vite-plugin-filter-replace plugin) Sourcemap is likely to be incorrect: a plugin (vite-plugin-filter-replace) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help
computing gzip size...
�[2mdist/emergency-assure/1.0.0/�[22m�[32mmanifest.json                          �[39m�[1m�[2m 5.14 kB�[22m�[1m�[22m�[2m │ gzip:  0.59 kB�[22m
�[2mdist/emergency-assure/1.0.0/�[22m�[36mroute-block-c0a8bdd8.js                �[39m�[1m�[2m 0.09 kB�[22m�[1m�[22m�[2m │ gzip:  0.10 kB�[22m�[2m │ map: 0.11 kB�[22m

how to fix it?

Generate test coverage report duplication

Using it with vite-test, when running unit tests on the cli, the plugin causes test coverage text duplication. When I remove the plugin from the mergeConfig the duplication will be disappeared.

With replace plugin:

Képernyőfotó 2024-06-11 - 12 04 13

Reporter is 'v8', but the issue is the same with 'istambul.'

Any fix or workaround?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.