Skip to content

Commit a74480a

Browse files
committed
feat(app-vite): replace esbuild with rolldown (still WIP)
1 parent 5d9dd88 commit a74480a

29 files changed

+213
-193
lines changed

app-vite/lib/app-devserver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class AppDevserver extends AppTool {
5353
quasarConf.sourceFiles
5454
])
5555

56-
this.registerDiff('esbuild', quasarConf => [
56+
this.registerDiff('rolldown', quasarConf => [
5757
quasarConf.build.env,
5858
quasarConf.build.rawDefine,
5959
quasarConf.metaConf.fileEnv,

app-vite/lib/app-extension/api-classes/IndexAPI.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class IndexAPI extends BaseAPI {
147147
}
148148

149149
/**
150-
* Extend Bex scripts (background/content-script) Esbuild config
150+
* Extend Bex scripts (background/content-script) Rolldown config
151151
*
152152
* @param {function} fn
153153
* (cfg: Object, api) => undefined
@@ -157,7 +157,7 @@ export class IndexAPI extends BaseAPI {
157157
}
158158

159159
/**
160-
* Extend Electron Main thread Esbuild config
160+
* Extend Electron Main thread Rolldown config
161161
*
162162
* @param {function} fn
163163
* (cfg: Object, api) => undefined
@@ -167,7 +167,7 @@ export class IndexAPI extends BaseAPI {
167167
}
168168

169169
/**
170-
* Extend Electron Preload thread Esbuild config
170+
* Extend Electron Preload thread Rolldown config
171171
*
172172
* @param {function} fn
173173
* (cfg: Object, api) => undefined
@@ -177,7 +177,7 @@ export class IndexAPI extends BaseAPI {
177177
}
178178

179179
/**
180-
* Extend PWA custom service worker Esbuild config
180+
* Extend PWA custom service worker Rolldown config
181181
* (when using Workbox InjectManifest mode)
182182
*
183183
* @param {function} fn
@@ -188,7 +188,7 @@ export class IndexAPI extends BaseAPI {
188188
}
189189

190190
/**
191-
* Extend SSR Webserver Esbuild config
191+
* Extend SSR Webserver Rolldown config
192192
*
193193
* @param {function} fn
194194
* (cfg: Object, api) => undefined

app-vite/lib/app-tool.js

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { join } from 'node:path'
22
import fse from 'fs-extra'
33

44
import { build as viteBuild } from 'vite'
5-
import { build as esBuild, context as esContextBuild } from 'esbuild'
5+
import { build as rolldownBuild, watch as rolldownWatch } from 'rolldown'
66

77
import { progress } from './utils/logger.js'
88

@@ -31,58 +31,59 @@ export class AppTool {
3131
done('___ compiled with success by Vite')
3232
}
3333

34-
async watchWithEsbuild(threadName, esbuildConfig, onRebuildSuccess) {
35-
let resolve
36-
37-
esbuildConfig.plugins.push({
38-
name: 'quasar:on-rebuild',
39-
setup(build) {
40-
let isFirst = true
41-
let done
42-
43-
build.onStart(() => {
44-
done = progress(
45-
'Compiling of ___ with Esbuild in progress...',
46-
threadName
47-
)
48-
})
49-
50-
build.onEnd(result => {
51-
if (result.errors.length !== 0) return
52-
53-
done('___ compiled with success by Esbuild')
54-
55-
if (isFirst === true) {
56-
isFirst = false
57-
resolve()
58-
return
59-
}
60-
61-
onRebuildSuccess()
62-
})
34+
watchWithRolldown(threadName, rolldownConfig, onRebuildSuccess) {
35+
const watcher = rolldownWatch({
36+
...rolldownConfig,
37+
watch: {
38+
exclude: 'node_modules/**'
6339
}
6440
})
6541

66-
const esbuildCtx = await esContextBuild(esbuildConfig)
67-
await esbuildCtx.watch()
42+
let resolve
43+
let isFirst = true
44+
let done
45+
46+
watcher.on('event', event => {
47+
if (event.code === 'BUNDLE_START') {
48+
done = progress(
49+
'Compiling of ___ with Rolldown in progress...',
50+
threadName
51+
)
52+
} else if (event.code === 'BUNDLE_END') {
53+
event.result.close()
54+
55+
done('___ compiled with success by Rolldown')
56+
57+
if (isFirst === true) {
58+
isFirst = false
59+
resolve()
60+
return
61+
}
62+
63+
onRebuildSuccess()
64+
} else if (event.code === 'ERROR') {
65+
console.error(event.error)
66+
event.result.close()
67+
}
68+
})
6869

6970
return new Promise(res => {
7071
resolve = () => {
71-
res(esbuildCtx)
72+
res(watcher)
7273
}
7374
})
7475
}
7576

76-
async buildWithEsbuild(threadName, esbuildConfig) {
77+
async buildWithRolldown(threadName, rolldownConfig) {
7778
const done = progress(
78-
'Compiling of ___ with Esbuild in progress...',
79+
'Compiling of ___ with Rolldown in progress...',
7980
threadName
8081
)
8182

82-
const esbuildResult = await esBuild(esbuildConfig)
83+
const rolldownResult = await rolldownBuild(rolldownConfig)
8384

84-
done('___ compiled with success by Esbuild')
85-
return esbuildResult
85+
done('___ compiled with success by Rolldown')
86+
return rolldownResult
8687
}
8788

8889
cleanArtifacts(dir) {

app-vite/lib/cmd/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ appBuilder
227227

228228
/**
229229
* We're done, but there may be some underlying tools which
230-
* haven't freed up the Node's JS execution stack yet (like esbuild or Vite).
230+
* haven't freed up the Node's JS execution stack yet (like Rolldown or Vite).
231231
* So, we're forcing the process to exit to avoid losing time.
232232
*/
233233
process.exit(0)

app-vite/lib/cmd/help.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ console.log(`
2929
clean, c Clean dev/build cache, /dist folder & entry points
3030
new, n Quickly scaffold page/layout/component/... vue file
3131
mode, m Add/remove Quasar Modes for your App
32-
inspect Inspect Vite/esbuild configs used under the hood
32+
inspect Inspect Vite/Rolldown configs used under the hood
3333
- keeps into account your quasar.config file
3434
and your installed App Extensions
3535
ext, e Manage Quasar App Extensions

app-vite/lib/cmd/info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ print({ key: 'Important local packages', section: true })
9494
'vite',
9595
'vite-plugin-checker',
9696
'eslint',
97-
'esbuild',
97+
'rolldown',
9898
'typescript',
9999
'workbox-build',
100100
'register-service-worker',

app-vite/lib/cmd/inspect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ if (argv.path) {
118118
import util from 'node:util'
119119

120120
cfgEntries.forEach(cfgEntry => {
121-
const tool = cfgEntry.object.configFile !== void 0 ? 'Vite' : 'esbuild'
121+
const tool = cfgEntry.object.configFile !== void 0 ? 'Vite' : 'Rolldown'
122122

123123
console.log()
124124
log(`Showing "${cfgEntry.name}" config (for ${tool}) with depth of ${depth}`)

app-vite/lib/config-tools.js

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const cliPkgDependencies = Object.keys(cliPkg.dependencies || {})
1616
/* Should match Vite's own hard-coded values */
1717
export const BASELINE_WIDELY_AVAILABLE_TARGET_STRING =
1818
'baseline-widely-available'
19-
const ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET = [
19+
const BASELINE_WIDELY_AVAILABLE = [
2020
'chrome111',
2121
'edge111',
2222
'firefox114',
@@ -266,15 +266,15 @@ export function extendViteConfig(viteConf, quasarConf, invokeParams) {
266266
return promise.then(() => viteConf)
267267
}
268268

269-
export function createNodeEsbuildConfig(quasarConf, { format }) {
269+
export function createNodeRolldownConfig(quasarConf, { format }) {
270270
const {
271271
ctx: {
272272
pkg: { appPkg },
273273
cacheProxy
274274
}
275275
} = quasarConf
276276

277-
const externalsList = cacheProxy.getRuntime('externalEsbuildParam', () =>
277+
const externalsList = cacheProxy.getRuntime('externalRolldownParam', () =>
278278
[
279279
...cliPkgDependencies,
280280
...Object.keys(appPkg.dependencies || {}),
@@ -287,70 +287,91 @@ export function createNodeEsbuildConfig(quasarConf, { format }) {
287287

288288
return {
289289
platform: 'node',
290-
target: quasarConf.build.target.node,
291-
format,
292-
bundle: true,
293-
sourcemap: quasarConf.metaConf.debugging === true ? 'inline' : false,
294-
minify: quasarConf.build.minify !== false,
295-
alias: {
296-
...quasarConf.build.alias
290+
291+
output: {
292+
format,
293+
codeSplitting: false,
294+
sourcemap: quasarConf.metaConf.debugging === true ? 'inline' : false
295+
},
296+
297+
resolve: {
298+
alias: {
299+
...quasarConf.build.alias
300+
},
301+
extensions:
302+
format === 'esm'
303+
? ['.mjs', '.js', '.cjs', '.ts', '.json']
304+
: ['.cjs', '.js', '.mjs', '.ts', '.json']
297305
},
298-
resolveExtensions:
299-
format === 'esm'
300-
? ['.mjs', '.js', '.cjs', '.ts', '.json']
301-
: ['.cjs', '.js', '.mjs', '.ts', '.json'],
306+
307+
transform: {
308+
target: quasarConf.build.target.node,
309+
minify: quasarConf.build.minify !== false,
310+
define: getBuildSystemDefine({
311+
buildEnv: quasarConf.build.env,
312+
buildRawDefine: quasarConf.build.rawDefine,
313+
fileEnv: quasarConf.metaConf.fileEnv
314+
})
315+
},
316+
302317
// we use a fresh list since this can be tampered with by the user:
303318
external: [...externalsList],
304-
define: getBuildSystemDefine({
305-
buildEnv: quasarConf.build.env,
306-
buildRawDefine: quasarConf.build.rawDefine,
307-
fileEnv: quasarConf.metaConf.fileEnv
308-
}),
319+
309320
plugins: []
310321
}
311322
}
312323

313-
export function createBrowserEsbuildConfig(quasarConf) {
324+
export function createBrowserRolldownConfig(quasarConf) {
314325
const { browser } = quasarConf.build.target
315326
const target =
316327
browser === BASELINE_WIDELY_AVAILABLE_TARGET_STRING
317-
? ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET
328+
? BASELINE_WIDELY_AVAILABLE
318329
: browser
319330

320331
return {
321332
platform: 'browser',
322-
target,
323-
format: 'iife',
324-
bundle: true,
325-
sourcemap: quasarConf.metaConf.debugging === true ? 'inline' : false,
326-
minify: quasarConf.build.minify !== false,
327-
alias: {
328-
...quasarConf.build.alias
333+
334+
output: {
335+
format: 'iife',
336+
codeSplitting: false,
337+
sourcemap: quasarConf.metaConf.debugging === true ? 'inline' : false
329338
},
330-
define: getBuildSystemDefine({
331-
buildEnv: quasarConf.build.env,
332-
buildRawDefine: quasarConf.build.rawDefine,
333-
fileEnv: quasarConf.metaConf.fileEnv
334-
}),
339+
340+
resolve: {
341+
alias: {
342+
...quasarConf.build.alias
343+
}
344+
},
345+
346+
transform: {
347+
target,
348+
minify: quasarConf.build.minify !== false,
349+
define: getBuildSystemDefine({
350+
buildEnv: quasarConf.build.env,
351+
buildRawDefine: quasarConf.build.rawDefine,
352+
fileEnv: quasarConf.metaConf.fileEnv
353+
})
354+
},
355+
335356
plugins: []
336357
}
337358
}
338359

339-
export function extendEsbuildConfig(
340-
esbuildConf,
360+
export function extendRolldownConfig(
361+
rolldownConfig,
341362
quasarConfTarget,
342363
ctx,
343364
methodName
344365
) {
345366
// example: quasarConf.ssr.extendSSRWebserverConf
346367
if (typeof quasarConfTarget[methodName] === 'function') {
347-
quasarConfTarget[methodName](esbuildConf)
368+
quasarConfTarget[methodName](rolldownConfig)
348369
}
349370

350371
const promise = ctx.appExt.runAppExtensionHook(methodName, async hook => {
351-
log(`Extension(${hook.api.extId}): Running "${methodName}(esbuildConf)"`)
352-
await hook.fn(esbuildConf, hook.api)
372+
log(`Extension(${hook.api.extId}): Running "${methodName}(rolldownConfig)"`)
373+
await hook.fn(rolldownConfig, hook.api)
353374
})
354375

355-
return promise.then(() => esbuildConf)
376+
return promise.then(() => rolldownConfig)
356377
}

app-vite/lib/modes/bex/bex-builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class QuasarModeBuilder extends AppBuilder {
2020
this.quasarConf,
2121
entry
2222
)
23-
await this.buildWithEsbuild(`Bex Script (${entry.name})`, contentConfig)
23+
await this.buildWithRolldown(`Bex Script (${entry.name})`, contentConfig)
2424
}
2525

2626
copyBexAssets(this.quasarConf)

0 commit comments

Comments
 (0)