fix: 优化构建

This commit is contained in:
winixt 2022-08-26 15:22:48 +08:00
parent 7ec746f32e
commit bd4b3b80da
3 changed files with 25 additions and 7 deletions

View File

@ -32,7 +32,7 @@ function transformBrowserCode(code) {
{ {
modules: false, modules: false,
useBuiltIns: false, useBuiltIns: false,
targets: { chrome: '51' }, targets: { chrome: '64' },
}, },
], ],
], ],

View File

@ -1,6 +1,17 @@
import { splitVendorChunkPlugin } from 'vite';
import legacy from '@vitejs/plugin-legacy'; import legacy from '@vitejs/plugin-legacy';
import { getInnerCommonConfig } from '../../common/getConfig'; import { getInnerCommonConfig } from '../../common/getConfig';
function getEsbuildTarget(targets) {
const result = [];
['chrome', 'edge', 'firefox', 'hermes', 'ios', 'node', 'opera', 'rhino', 'safari'].forEach((key) => {
if (targets[key]) {
result.push(`${key}${targets[key]}`);
}
});
return result;
}
export default async (api) => { export default async (api) => {
const { deepmerge, getTargetsAndBrowsersList } = api.utils; const { deepmerge, getTargetsAndBrowsersList } = api.utils;
@ -24,14 +35,15 @@ export default async (api) => {
plugins: [ plugins: [
legacy({ legacy({
modernPolyfills: true, modernPolyfills: true,
renderLegacyChunks: false,
targets, targets,
}), }),
splitVendorChunkPlugin(),
], ],
build: { build: {
...build, ...build,
minify: 'terser',
terserOptions: build.terserOptions || api.config.terserOptions, terserOptions: build.terserOptions || api.config.terserOptions,
target: build.target || 'es2015', target: build.target || getEsbuildTarget(targets),
outDir: build.outDir || api.config.outputPath || 'dist', outDir: build.outDir || api.config.outputPath || 'dist',
assetsInlineLimit: build.assetsInlineLimit || api.config.inlineLimit || 8192, assetsInlineLimit: build.assetsInlineLimit || api.config.inlineLimit || 8192,
}, },

View File

@ -3,10 +3,16 @@ export default (api) => {
key: 'targets', key: 'targets',
config: { config: {
default: { default: {
chrome: 56, android: '61.0.0',
firefox: 67, chrome: '61.0.0',
safari: 10, edge: '16.0.0',
edge: 13, firefox: '60.0.0',
ios: '10.3.0',
node: '13.2.0',
opera: '48.0.0',
safari: '10.1.0',
samsung: '8.2.0',
browsers: ['defaults and not chrome < 61'],
}, },
schema(joi) { schema(joi) {
return joi.object(); return joi.object();