Skip to content

Commit 4a3c273

Browse files
author
Franck Freiburger
committed
wip(build): build vue2/vue3 js/esm for nodejs
1 parent b6cfadd commit 4a3c273

File tree

1 file changed

+60
-52
lines changed

1 file changed

+60
-52
lines changed

build/rollup.config-node.mjs

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,70 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url))
99

1010
import pkg from '../package.json' assert { type: 'json' };
1111

12-
const vueTarget = '3';
13-
const outputFormat = 'module';
12+
1413
const genSourcemap = false;
1514

15+
async function configFactory({ name, vueTarget, libraryTargetModule }) {
1616

17-
let vueVersion; // expected vue version
18-
switch ( vueTarget ) {
19-
case '2':
20-
vueVersion = (await import('vue-template-compiler/package.json', { assert: { type: 'json' } })).default.version;
21-
break;
22-
case '3':
23-
vueVersion = (await import('@vue/compiler-sfc/package.json', { assert: { type: 'json' } })).default.version;
24-
break;
25-
default:
26-
throw new Error(`invalid vueTarget: ${ vueTarget }`)
17+
let vueVersion; // expected vue version
18+
switch ( vueTarget ) {
19+
case '2':
20+
vueVersion = (await import('vue-template-compiler/package.json', { assert: { type: 'json' } })).default.version;
21+
break;
22+
case '3':
23+
vueVersion = (await import('@vue/compiler-sfc/package.json', { assert: { type: 'json' } })).default.version;
24+
break;
25+
default:
26+
throw new Error(`invalid vueTarget: ${ vueTarget }`)
27+
}
28+
29+
/**
30+
* @type {import('rollup').RollupOptions}
31+
*/
32+
const config = {
33+
input: './src/index.ts',
34+
output: {
35+
file: `dist/vue${ vueTarget }-sfc-loader-node.${ libraryTargetModule ? 'mjs' : 'js' }`,
36+
format: libraryTargetModule ? 'module' : 'commonjs',
37+
},
38+
plugins: [
39+
replace({
40+
preventAssignment: true,
41+
values: {
42+
'process.env.GEN_SOURCEMAP': JSON.stringify(genSourcemap),
43+
'process.env.VERSION': JSON.stringify(pkg.version),
44+
'process.env.VUE_VERSION': JSON.stringify(vueVersion),
45+
},
46+
}),
47+
alias({
48+
entries: [
49+
{ find: './createSFCModule', replacement: `./createVue${ vueTarget }SFCModule` },
50+
]
51+
}),
52+
typescript({
53+
compilerOptions: {
54+
target: 'ES2017', // keep async/await
55+
allowSyntheticDefaultImports: true,
56+
}
57+
}), // beware: order is important !
58+
terser({
59+
compress: false,
60+
mangle: false,
61+
output: {
62+
comments: false,
63+
beautify: true,
64+
},
65+
}),
66+
],
67+
};
68+
return config;
2769
}
2870

2971

30-
/**
31-
* @type {import('rollup').RollupOptions}
32-
*/
33-
const config = {
34-
input: './src/index.ts',
35-
output: {
36-
file: `dist/vue${ vueTarget }-sfc-loader-node.${ outputFormat === 'module' ? 'mjs' : 'js' }`,
37-
format: outputFormat,
38-
},
39-
plugins: [
40-
replace({
41-
preventAssignment: true,
42-
values: {
43-
'process.env.GEN_SOURCEMAP': JSON.stringify(genSourcemap),
44-
'process.env.VERSION': JSON.stringify(pkg.version),
45-
'process.env.VUE_VERSION': JSON.stringify(vueVersion),
46-
},
47-
}),
48-
alias({
49-
entries: [
50-
{ find: './createSFCModule', replacement: `./createVue${ vueTarget }SFCModule` },
51-
]
52-
}),
53-
typescript({
54-
compilerOptions: {
55-
target: 'ES2017', // keep async/await
56-
allowSyntheticDefaultImports: true,
57-
}
58-
}), // beware: order is important !
59-
terser({
60-
compress: false,
61-
mangle: false,
62-
output: {
63-
comments: false,
64-
beautify: true,
65-
},
66-
}),
67-
],
68-
};
6972

70-
export default config;
73+
export default [
74+
await configFactory({name: 'vue2', vueTarget: '2', libraryTargetModule: false }),
75+
await configFactory({name: 'vue2esm', vueTarget: '2', libraryTargetModule: true }),
76+
await configFactory({name: 'vue3', vueTarget: '3', libraryTargetModule: false }),
77+
await configFactory({name: 'vue3esm', vueTarget: '3', libraryTargetModule: true }),
78+
];

0 commit comments

Comments
 (0)