0.2.2 • Published 2 years ago

vite-plugin-removelog v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

vite-plugin-removelog

生产环境下移除 consolevite 插件

动机 🦒

不希望开发时的日志在生产环境下被人看到

特性 🦖

  • 支持 .js.ts.jsx.tsx.vue

使用 🦕

安装

npm i vite-plugin-removelog -D

配置

// vite.config.js
import Removelog from "vite-plugin-removelog";

export default defineConfig({
  plugins: [Removelog()],
});

包含

// vite.config.js
import Removelog from "vite-plugin-removelog";

export default defineConfig({
  plugins: [
    Removelog({
      // 默认包含 log,warn,error
      include: ["log", "warn"],
    }),
  ],
});

规范

可以通过 normalize 来自定义哪些模块需要被作用

// vite.config.js
import Removelog from "vite-plugin-removelog";

export default defineConfig({
  plugins: [
    Removelog({
      // 返回 Truthy 时,模块被将作用
      normalize(id) {
        return /(\.vue|\.[jt]sx?)$/.test(id);
      },
    }),
  ],
});

忽略 node_modules

可以通过 ignoreNodeModules 忽略 node_modules 包的处理

// vite.config.js
import Removelog from "vite-plugin-removelog";

export default defineConfig({
  plugins: [
    Removelog({
      // 默认为 true
      ignoreNodeModules: true,
    }),
  ],
});

原理

该插件不传入 normalize 时由 vite 内置的 esbuild 进行转换,当传入 normalize 时,则为 gogocode 进行转换。

gogocode 实现的转换也是导出的 👇

import { gogocodeRemovelog } from "vite-plugin-removelog";

const code = `
const foo = 1
console.log("foo")
`;
const dest = gogocodeRemovelog(code);

console.log(dest); // const foo = 1

组织 🦔

欢迎关注 帝莎编程

License

Made with markthree

Published under MIT License.

0.2.2

2 years ago

0.1.0

3 years ago

0.2.1

3 years ago

0.1.2

3 years ago

0.2.0

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago