Skip to content

Commit 73ffe7e

Browse files
committed
feat: 升级vite5->rolldown-vite
1 parent effd137 commit 73ffe7e

6 files changed

Lines changed: 2555 additions & 1257 deletions

File tree

packages/fes-builder-vite/package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
"@babel/core": "^7.23.3",
3333
"@fesjs/utils": "^3.0.3",
3434
"@rollup/pluginutils": "^5.1.0",
35-
"@vitejs/plugin-basic-ssl": "^1.0.2",
36-
"@vitejs/plugin-legacy": "^5.2.0",
37-
"@vitejs/plugin-vue": "^4.5.0",
38-
"@vitejs/plugin-vue-jsx": "^3.1.0",
35+
"@vitejs/plugin-basic-ssl": "^2.1.0",
36+
"@vitejs/plugin-legacy": "^7.0.0",
37+
"@vitejs/plugin-vue": "^6.0.1",
38+
"@vitejs/plugin-vue-jsx": "^5.0.1",
3939
"autoprefixer": "^10.4.4",
4040
"colorette": "^2.0.16",
4141
"connect-history-api-fallback": "^2.0.0",
@@ -51,9 +51,12 @@
5151
"pathe": "^0.2.0",
5252
"postcss-flexbugs-fixes": "^5.0.2",
5353
"postcss-safe-parser": "^6.0.0",
54+
"rolldown-vite": "^7.1.0",
5455
"rollup-plugin-visualizer": "^5.9.3",
55-
"terser": "^5.24.0",
56-
"vite": "^5.0.3"
56+
"terser": "^5.24.0"
57+
},
58+
"devDependencies": {
59+
"@types/node": "^22.12.0"
5760
},
5861
"typings": "./types.d.ts"
5962
}

packages/fes-builder-vite/src/commands/build/getBuildConfig.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { splitVendorChunkPlugin } from 'vite';
21
import legacy from '@vitejs/plugin-legacy';
32
import { getInnerCommonConfig } from '../../common/getConfig';
43

@@ -39,7 +38,6 @@ export default async (api) => {
3938
targets,
4039
...api.config.viteLegacy,
4140
}),
42-
splitVendorChunkPlugin(),
4341
],
4442
build: {
4543
...build,

packages/fes-builder-vite/src/commands/build/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { existsSync } from 'node:fs';
12
import { build } from 'vite';
2-
import { existsSync } from 'fs';
33
import getBuildConfig from './getBuildConfig';
44

55
export default function (api) {
@@ -33,7 +33,8 @@ export default function (api) {
3333
if (process.env.RM_TMPDIR !== 'none') {
3434
rimraf.sync(paths.absTmpPath);
3535
}
36-
} catch (err) {
36+
}
37+
catch (err) {
3738
// throw build error
3839
throw err;
3940
}

packages/fes-builder-vite/src/common/vite-plugin-html.js

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
import process from 'node:process';
2-
import { render } from 'ejs';
3-
import { expand } from 'dotenv-expand';
2+
import { createFilter } from '@rollup/pluginutils';
3+
import { dim } from 'colorette';
4+
import consola from 'consola';
45
import dotenv from 'dotenv';
5-
import path, { dirname, join } from 'pathe';
6-
import fse from 'fs-extra';
7-
import { normalizePath } from 'vite';
8-
import { parse } from 'node-html-parser';
6+
import { expand } from 'dotenv-expand';
7+
import { render } from 'ejs';
98
import fg from 'fast-glob';
10-
import consola from 'consola';
11-
import { dim } from 'colorette';
9+
import fse from 'fs-extra';
1210
import { minify } from 'html-minifier-terser';
13-
import { createFilter } from '@rollup/pluginutils';
11+
import { parse } from 'node-html-parser';
12+
import path, { dirname, join } from 'pathe';
13+
import { normalizePath } from 'vite';
1414
import history from './connectHistoryMiddleware';
1515

1616
function lookupFile(dir, formats, pathOnly = false) {
1717
for (const format of formats) {
1818
const fullPath = join(dir, format);
19-
if (fse.pathExistsSync(fullPath) && fse.statSync(fullPath).isFile())
19+
if (fse.pathExistsSync(fullPath) && fse.statSync(fullPath).isFile()) {
2020
return pathOnly ? fullPath : fse.readFileSync(fullPath, 'utf-8');
21+
}
2122
}
2223
const parentDir = dirname(dir);
23-
if (parentDir !== dir)
24+
if (parentDir !== dir) {
2425
return lookupFile(parentDir, formats, pathOnly);
26+
}
2527
}
2628

2729
function loadEnv(mode, envDir, prefix = '') {
28-
if (mode === 'local')
30+
if (mode === 'local') {
2931
throw new Error(`"local" cannot be used as a mode name because it conflicts with the .local postfix for .env files.`);
32+
}
3033

3134
const env = {};
3235
const envFiles = [`.env.${mode}.local`, `.env.${mode}`, `.env.local`, `.env`];
@@ -39,11 +42,13 @@ function loadEnv(mode, envDir, prefix = '') {
3942
ignoreProcessEnv: true,
4043
});
4144
for (const [key, value] of Object.entries(parsed)) {
42-
if (key.startsWith(prefix) && env[key] === undefined)
45+
if (key.startsWith(prefix) && env[key] === undefined) {
4346
env[key] = value;
47+
}
4448

45-
else if (key === 'NODE_ENV')
49+
else if (key === 'NODE_ENV') {
4650
process.env.VITE_USER_NODE_ENV = value;
51+
}
4752
}
4853
}
4954
}
@@ -103,14 +108,15 @@ function createPlugin(userOptions = {}) {
103108
const keys = Object.keys(proxy);
104109
let indexPage = null;
105110
for (const page of _pages) {
106-
if (page.filename !== 'index.html')
111+
if (page.filename !== 'index.html') {
107112
rewrites.push(createRewire(page.template, page, baseUrl, keys));
113+
}
108114

109-
else
110-
indexPage = page;
115+
else { indexPage = page; }
111116
}
112-
if (indexPage)
117+
if (indexPage) {
113118
rewrites.push(createRewire('', indexPage, baseUrl, keys));
119+
}
114120

115121
server.middlewares.use(
116122
history(viteConfig, {
@@ -148,14 +154,16 @@ function createPlugin(userOptions = {}) {
148154
if (isMpa(viteConfig) || pages.length) {
149155
for (const page of pages) {
150156
const dir = path.dirname(page.template);
151-
if (!ignoreDirs.includes(dir))
157+
if (!ignoreDirs.includes(dir)) {
152158
outputDirs.push(dir);
159+
}
153160
}
154161
}
155162
else {
156163
const dir = path.dirname(template);
157-
if (!ignoreDirs.includes(dir))
164+
if (!ignoreDirs.includes(dir)) {
158165
outputDirs.push(dir);
166+
}
159167
}
160168
const cwd = path.resolve(viteConfig.root, viteConfig.build.outDir);
161169
const htmlFiles = await fg(
@@ -176,8 +184,9 @@ function createPlugin(userOptions = {}) {
176184
await Promise.all(
177185
htmlDirs.map(async (item) => {
178186
const isEmpty = await isDirEmpty(item);
179-
if (isEmpty)
187+
if (isEmpty) {
180188
return fse.remove(item);
189+
}
181190
}),
182191
);
183192
},
@@ -198,8 +207,9 @@ function createInput({ pages = [], template = DEFAULT_TEMPLATE }, viteConfig) {
198207
return input;
199208
}
200209
const dir = path.dirname(template);
201-
if (ignoreDirs.includes(dir))
210+
if (ignoreDirs.includes(dir)) {
202211
return undefined;
212+
}
203213

204214
const file = path.basename(template);
205215
const key = file.replace(/\.html/, '');
@@ -227,11 +237,11 @@ async function renderHtml(html, config) {
227237

228238
function getPage({ pages = [], entry, template = DEFAULT_TEMPLATE, inject = {} }, name, viteConfig) {
229239
let page;
230-
if (isMpa(viteConfig) || pages?.length)
240+
if (isMpa(viteConfig) || pages?.length) {
231241
page = getPageConfig(name, pages, DEFAULT_TEMPLATE);
242+
}
232243

233-
else
234-
page = createSpaPage(entry, template, inject);
244+
else { page = createSpaPage(entry, template, inject); }
235245

236246
return page;
237247
}
@@ -242,8 +252,9 @@ function isMpa(viteConfig) {
242252
}
243253

244254
function removeEntryScript(html, verbose = false) {
245-
if (!html)
255+
if (!html) {
246256
return html;
257+
}
247258

248259
const root = parse(html);
249260
const scriptNodes = root.querySelectorAll('script[type=module]') || [];
@@ -255,8 +266,8 @@ function removeEntryScript(html, verbose = false) {
255266
verbose
256267
&& removedNode.length
257268
&& consola.warn(`vite-plugin-html: Since you have already configured entry, ${dim(
258-
removedNode.toString(),
259-
)} is deleted. You may also delete it from the index.html.
269+
removedNode.toString(),
270+
)} is deleted. You may also delete it from the index.html.
260271
`);
261272
return root.toString();
262273
}
@@ -286,8 +297,9 @@ function createRewire(reg, page, baseUrl, proxyUrlKeys) {
286297
const pathname = parsedUrl.pathname;
287298
const excludeBaseUrl = pathname.replace(baseUrl, '/');
288299
const template = path.resolve(baseUrl, page.template);
289-
if (excludeBaseUrl === '/')
300+
if (excludeBaseUrl === '/') {
290301
return template;
302+
}
291303

292304
const isApiUrl = proxyUrlKeys.some(item => pathname.startsWith(path.resolve(baseUrl, item)));
293305
return isApiUrl ? parsedUrl.path : template;
@@ -311,12 +323,14 @@ function getOptions(_minify) {
311323
}
312324

313325
async function minifyHtml(html, minify$1) {
314-
if (typeof minify$1 === 'boolean' && !minify$1)
326+
if (typeof minify$1 === 'boolean' && !minify$1) {
315327
return html;
328+
}
316329

317330
let minifyOptions = minify$1;
318-
if (typeof minify$1 === 'boolean' && minify$1)
331+
if (typeof minify$1 === 'boolean' && minify$1) {
319332
minifyOptions = getOptions(minify$1);
333+
}
320334

321335
const res = await minify(html, minifyOptions);
322336
return res;
@@ -329,8 +343,9 @@ function createMinifyHtmlPlugin({ _minify = true } = {}) {
329343
async generateBundle(_, outBundle) {
330344
if (_minify) {
331345
for (const bundle of Object.values(outBundle)) {
332-
if (bundle.type === 'asset' && htmlFilter(bundle.fileName) && typeof bundle.source === 'string')
346+
if (bundle.type === 'asset' && htmlFilter(bundle.fileName) && typeof bundle.source === 'string') {
333347
bundle.source = await minifyHtml(bundle.source, _minify);
348+
}
334349
}
335350
}
336351
},

packages/fes-preset-built-in/src/plugins/features/targets.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ export default (api) => {
33
key: 'targets',
44
config: {
55
default: {
6-
chrome: '64',
7-
ios: '11',
6+
chrome: '107',
7+
ios: '16',
8+
firefox: '104',
9+
edge: '107',
810
},
911
schema(joi) {
1012
return joi.object();

0 commit comments

Comments
 (0)