Skip to content

Commit fc76187

Browse files
committed
fix: update from rollup config
1 parent 6460cbe commit fc76187

File tree

1 file changed

+122
-83
lines changed

1 file changed

+122
-83
lines changed

scripts/rolldown.ts

Lines changed: 122 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -53,78 +53,110 @@ export function createConfigsForPackage({
5353
* Released under the ${pkg.license} License.
5454
*/`
5555

56-
const stubs = {
57-
[resolve(`dist/${name}.cjs`)]: resolve(`dist/${name}.cjs.js`),
58-
[resolve(`dist/${name}.mjs`)]: resolve(`dist/${name}.esm-bundler.js`),
59-
[resolve(`dist/${name}.runtime.mjs`)]: resolve(
60-
`dist/${name}.runtime.esm-bundler.js`
61-
),
62-
[resolve(`dist/${name}.prod.cjs`)]: resolve(`dist/${name}.cjs.prod.js`)
56+
function resolveStubs(name: string, ns = '') {
57+
return {
58+
[`dist/${ns}${name}.cjs`]: `${ns}${name}.cjs.js`,
59+
[`dist/${ns}${name}.mjs`]: `${ns}${name}.esm-bundler.js`,
60+
[`dist/${ns}${name}.runtime.mjs`]: `${ns}${name}.runtime.esm-bundler.js`,
61+
[`dist/${ns}${name}.prod.cjs`]: `${ns}${name}.cjs.prod.js`
62+
}
6363
}
6464

65-
const outputConfigs: Record<string, OutputOptions> = {
66-
mjs: {
67-
file: resolve(`dist/${name}.mjs`),
68-
format: `es`
69-
},
70-
'mjs-node': {
71-
file: resolve(`dist/${name}.node.mjs`),
72-
format: `es`
73-
},
74-
browser: {
75-
file: resolve(`dist/${name}.esm-browser.js`),
76-
format: `es`
77-
},
78-
cjs: {
79-
file: resolve(`dist/${name}.cjs`),
80-
format: `cjs`
81-
},
82-
global: {
83-
file: resolve(`dist/${name}.global.js`),
84-
format: `iife`
85-
},
86-
// runtime-only builds, for '@intlify/core' and 'vue-i18n' package only
87-
'mjs-runtime': {
88-
file: resolve(`dist/${name}.runtime.mjs`),
89-
format: `es`
90-
},
91-
'mjs-node-runtime': {
92-
file: resolve(`dist/${name}.runtime.node.mjs`),
93-
format: `es`
94-
},
95-
'browser-runtime': {
96-
file: resolve(`dist/${name}.runtime.esm-browser.js`),
97-
format: 'es'
98-
},
99-
'global-runtime': {
100-
file: resolve(`dist/${name}.runtime.global.js`),
101-
format: 'iife'
65+
function resolveOutputConfigs(
66+
name: string,
67+
ns = ''
68+
): Record<string, OutputOptions> {
69+
return {
70+
mjs: {
71+
file: resolve(`dist/${ns}${name}.mjs`),
72+
format: `es`
73+
},
74+
'mjs-node': {
75+
file: resolve(`dist/${ns}${name}.node.mjs`),
76+
format: `es`
77+
},
78+
browser: {
79+
file: resolve(`dist/${ns}${name}.esm-browser.js`),
80+
format: `es`
81+
},
82+
cjs: {
83+
file: resolve(`dist/${ns}${name}.cjs`),
84+
format: `cjs`
85+
},
86+
global: {
87+
file: resolve(`dist/${ns}${name}.global.js`),
88+
format: `iife`
89+
},
90+
// runtime-only builds, for '@intlify/core' and 'vue-i18n' package only
91+
'mjs-runtime': {
92+
file: resolve(`dist/${ns}${name}.runtime.mjs`),
93+
format: `es`
94+
},
95+
'mjs-node-runtime': {
96+
file: resolve(`dist/${ns}${name}.runtime.node.mjs`),
97+
format: `es`
98+
},
99+
'browser-runtime': {
100+
file: resolve(`dist/${ns}${name}.runtime.esm-browser.js`),
101+
format: 'es'
102+
},
103+
'global-runtime': {
104+
file: resolve(`dist/${ns}${name}.runtime.global.js`),
105+
format: 'iife'
106+
}
102107
}
103108
}
104109

110+
let stubs = resolveStubs(name)
111+
if (name === 'vue-i18n-core') {
112+
stubs = Object.assign({}, stubs, resolveStubs(name, 'petite-'))
113+
}
114+
115+
const outputConfigs = resolveOutputConfigs(name)
116+
105117
const resolvedFormats = (
106118
formats ||
107119
packageOptions.formats || ['esm-bundler', 'cjs']
108120
)
109121
.filter(Boolean)
110122
.filter((format: string) => outputConfigs[format])
111123

112-
const packageConfigs = prodOnly
124+
let packageConfigs = prodOnly
113125
? []
114126
: resolvedFormats.map((format: string) =>
115127
createConfig(format, outputConfigs[format])
116128
)
117129

130+
const petiteOutputConfigs =
131+
name === 'vue-i18n-core' ? resolveOutputConfigs(name, 'petite-') : {}
132+
133+
if (name === 'vue-i18n-core') {
134+
packageConfigs = [
135+
...packageConfigs,
136+
...resolvedFormats.map(format =>
137+
createConfig(format, petiteOutputConfigs[format])
138+
)
139+
]
140+
}
141+
118142
if (!devOnly) {
119143
resolvedFormats.forEach((format: string) => {
120144
if (packageOptions.prod === false) {
121145
return
122146
}
123147
if (format === 'cjs') {
124-
packageConfigs.push(createProductionConfig(format))
148+
packageConfigs.push(createProductionConfig(format, name))
149+
if (name === 'vue-i18n-core') {
150+
packageConfigs.push(createProductionConfig(format, name, 'petite-'))
151+
}
125152
}
126153
if (/^(global|browser)(-runtime)?/.test(format)) {
127-
packageConfigs.push(createMinifiedConfig(format))
154+
packageConfigs.push(createMinifiedConfig(format, outputConfigs[format]))
155+
if (name === 'vue-i18n-core') {
156+
packageConfigs.push(
157+
createMinifiedConfig(format, petiteOutputConfigs[format])
158+
)
159+
}
128160
}
129161
})
130162
}
@@ -148,12 +180,10 @@ export function createConfigsForPackage({
148180
/browser/.test(format) && !packageOptions.enableNonBrowserBranches
149181
// const isCJSBuild = format === 'cjs'
150182
const isNodeBuild =
151-
String(output.file).includes('.node.') ||
152-
format === 'cjs' ||
153-
format === 'cjs-lite'
183+
String(output.file).includes('.node.') || format === 'cjs'
154184
const isGlobalBuild = /global/.test(format)
155185
const isRuntimeOnlyBuild = /runtime/.test(format)
156-
const isLite = /petite-vue-i18n/.test(name)
186+
const isLite = /petite-vue-i18n/.test(String(output.file))
157187

158188
// output.dir = resolve('dist')
159189
output.sourcemap = sourceMap
@@ -176,7 +206,14 @@ export function createConfigsForPackage({
176206
output.name = packageOptions.name
177207
}
178208

179-
const entryFile = /runtime/.test(format) ? `src/runtime.ts` : `src/index.ts`
209+
const entryFile =
210+
name !== 'vue-i18n-core'
211+
? /runtime/.test(format)
212+
? `src/runtime.ts`
213+
: `src/index.ts`
214+
: !/petite-vue-i18n/.test(String(output.file))
215+
? `src/index.ts`
216+
: `src/petite.ts`
180217

181218
function resolveDefine() {
182219
const defines: Record<string, string> = {
@@ -335,46 +372,48 @@ export function createConfigsForPackage({
335372
}
336373
}
337374

338-
function createProductionConfig(format: string): RolldownOptions {
375+
function createProductionConfig(
376+
format: string,
377+
name: string,
378+
ns = ''
379+
): RolldownOptions {
339380
const extension = format === 'cjs' || format === 'mjs' ? format : 'js'
340381
const descriptor = format === 'cjs' || format === 'mjs' ? '' : `.${format}`
341382
return createConfig(format, {
342-
file: resolve(`dist/${name}${descriptor}.prod.${extension}`),
383+
file: resolve(`dist/${ns}${name}${descriptor}.prod.${extension}`),
343384
format: outputConfigs[format].format
344385
})
345386
}
346387

347-
function createMinifiedConfig(format: string): RolldownOptions {
348-
return createConfig(
349-
format,
388+
function createMinifiedConfig(
389+
format: string,
390+
output: OutputOptions
391+
): RolldownOptions {
392+
const newOutput = {
393+
file: String(output.file).replace(/\.js$/, '.prod.js'),
394+
format: output.format
395+
}
396+
return createConfig(format, newOutput, [
350397
{
351-
file: resolve(
352-
String(outputConfigs[format].file).replace(/\.js$/, '.prod.js')
353-
),
354-
format: outputConfigs[format].format
355-
},
356-
[
357-
{
358-
name: 'swc-minify',
359-
async renderChunk(contents, _, { format }) {
360-
const { code } = await minifySwc(contents, {
361-
module: format === 'es',
362-
format: {
363-
comments: false
364-
},
365-
compress: {
366-
ecma: 2016,
367-
pure_getters: true
368-
},
369-
safari10: true,
370-
mangle: true
371-
})
372-
// swc removes banner
373-
return { code: banner + code, map: null }
374-
}
398+
name: 'swc-minify',
399+
async renderChunk(contents, _, { format }) {
400+
const { code } = await minifySwc(contents, {
401+
module: format === 'es',
402+
format: {
403+
comments: false
404+
},
405+
compress: {
406+
ecma: 2016,
407+
pure_getters: true
408+
},
409+
safari10: true,
410+
mangle: true
411+
})
412+
// swc removes banner
413+
return { code: banner + code, map: null }
375414
}
376-
]
377-
)
415+
}
416+
])
378417
}
379418

380419
return packageConfigs

0 commit comments

Comments
 (0)