Skip to content

一.vite

前言

补充一些官方文档中没有的,但是实际开发中最好需要了解的内容

1.插件

  • unplugin-auto-import:自动引入组件

2.兼容性

sh
npm i @vitejs/plugin-legacy terser -D
  • vite.config.ts
ts
import legacyPlugin from '@vitejs/plugin-legacy'

build: {
    target: 'es2015',
    minify: 'terser',
    terserOptions: {
        compress: {
            //  生产环境时移除console
            drop_console: true,
            drop_debugger: true,
        },
    },
   ...
},
plugins: [
    // 浏览器兼容问题配置
    legacyPlugin({
        targets: ['chrome 52'],
        modernPolyfills: true,
        // additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
        // renderLegacyChunks: true,
        // polyfills: [
        //     'es.symbol',
        //     'es.promise',
        //     'es.promise.finally',
        //     'es/map',
        //     'es/set',
        //     'es.array.filter',
        //     'es.array.for-each',
        //     'es.array.flat-map',
        //     'es.object.define-properties',
        //     'es.object.define-property',
        //     'es.object.get-own-property-descriptor',
        //     'es.object.get-own-property-descriptors',
        //     'es.object.keys',
        //     'es.object.to-string',
        //     'web.dom-collections.for-each',
        //     'esnext.global-this',
        //     'esnext.string.match-all'
        // ]
    }),
...
]