1.0.1 • Published 3 years ago

vite-plugin-env-main v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

插件用途

根据环境不同,区分不同的入口文件。默认入口文件为/src/main.js,开发环境入口文件为/src/main.dev.js。 比如你想在开发阶段全量引入element-plus,在生产环境中按需引入,此时需要编写不同的入口文件。

安装插件

Install the plugin with npm:

npm install vite-plugin-env-main --save-dev

or yarn

yarn add vite-plugin-env-main -D

基本用法

在 vite.config.js 中配置插件:

// vite.config.js
import CreateEnvMain from "vite-plugin-env-main";

export default {
    plugins: [
        CreateEnvMain()
    ],
}

实现原理

插件的基本原理是在开发环境下,自动将index.html中的/src/main.js替换为/src/main.dev.js。所以你需要保证在index.html中,有如下默认代码:

// index.html
<script type="module" src="/src/main.js"></script>