vite-plugin-removelog
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

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.


Readme

Keywords

Package Sidebar

Install

npm i vite-plugin-removelog

Weekly Downloads

22

Version

0.2.2

License

MIT

Unpacked Size

9.27 kB

Total Files

7

Last publish

Collaborators

  • markthree