Skip to content

Commit 8567a06

Browse files
author
Franck Freiburger
committed
wip(build): start working on a nodejs bundle
1 parent 66df634 commit 8567a06

File tree

3 files changed

+332
-6
lines changed

3 files changed

+332
-6
lines changed

build/rollup.config-node.mjs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { fileURLToPath } from 'url'
2+
import path from 'path';
3+
4+
import typescript from '@rollup/plugin-typescript';
5+
import alias from '@rollup/plugin-alias';
6+
import json from '@rollup/plugin-json';
7+
import replace from '@rollup/plugin-replace';
8+
import terser from '@rollup/plugin-terser'
9+
10+
const __dirname = fileURLToPath(new URL('.', import.meta.url))
11+
12+
13+
import pkg from '../package.json' assert { type: 'json' };
14+
15+
const genSourcemap = false;
16+
const vueTarget = '3';
17+
18+
let vueVersion; // expected vue version
19+
switch ( vueTarget ) {
20+
case '2':
21+
vueVersion = (await import('vue-template-compiler/package.json', { assert: { type: 'json' } })).default.version;
22+
break;
23+
case '3':
24+
vueVersion = (await import('@vue/compiler-sfc/package.json', { assert: { type: 'json' } })).default.version;
25+
break;
26+
default:
27+
throw new Error(`invalid vueTarget: ${ vueTarget }`)
28+
}
29+
30+
31+
/**
32+
* @type {import('rollup').RollupOptions}
33+
*/
34+
const config = {
35+
input: './src/index.ts',
36+
output: {
37+
file: `dist/vue${ vueTarget }-sfc-loader-node.mjs`,
38+
format: 'module',
39+
},
40+
plugins: [
41+
json(),
42+
replace({
43+
preventAssignment: true,
44+
values: {
45+
'process.env.GEN_SOURCEMAP': JSON.stringify(genSourcemap),
46+
'process.env.VERSION': JSON.stringify(pkg.version),
47+
'process.env.VUE_VERSION': JSON.stringify(vueVersion),
48+
},
49+
}),
50+
alias({
51+
entries: [
52+
{ find: './createSFCModule', replacement: `./createVue${ vueTarget }SFCModule` },
53+
]
54+
}),
55+
typescript({
56+
compilerOptions: {
57+
target: 'ES2017', // keep async/await
58+
allowSyntheticDefaultImports: true,
59+
}
60+
}), // beware: order is important !
61+
terser({
62+
compress: false,
63+
mangle: false,
64+
output: {
65+
comments: false,
66+
beautify: true,
67+
},
68+
}),
69+
],
70+
};
71+
72+
export default config;

package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"tests": "jest --runInBand \"tests/.*\\.test.js\"",
3838
"dev": "webpack --mode=development --config ./build/webpack.config.js --progress --watch",
3939
"build": "rimraf ./dist/ && cross-env-shell webpack --mode=production --config ./build/webpack.config.js --progress --env targetsBrowsers=\\\"$npm_package_browserslist\\\"",
40+
"build-node": "rollup --config ./build/rollup.config-node.mjs" ,
4041
"docs": "cross-env-shell \"node build/evalHtmlComments.js README.md $npm_package_version && node build/evalHtmlComments.js docs/examples.md $npm_package_version && typedoc --plugin typedoc-plugin-markdown --mode file --tsconfig ./build/tsconfig.json --inputFiles ./src/index.ts --out ./docs/api --readme none --stripInternal --namedAnchors true\"",
4142
"pushDocs": "yarn run docs && git add docs/ && git add README.md && cross-env-shell git commit -m \\\"chore(docs): v$npm_package_version API docs & examples \\\" docs",
4243
"release": "standard-version --header \"\""
@@ -85,6 +86,7 @@
8586
"jest": "29",
8687
"lodash-es": "^4.17.21",
8788
"lru-cache": "^6.0.0",
89+
"memory-fs": "^0.5.0",
8890
"path-browserify": "^1.0.1",
8991
"process": "^0.11.10",
9092
"puppeteer": "^13.1.1",
@@ -109,6 +111,16 @@
109111
"webpack": "^5.89.0",
110112
"webpack-bundle-analyzer": "^4.5.0",
111113
"webpack-cli": "^5.1.4",
112-
"memory-fs": "^0.5.0"
114+
"@rollup/plugin-alias": "^5.1.0",
115+
"@rollup/plugin-babel": "^6.0.4",
116+
"@rollup/plugin-commonjs": "^25.0.7",
117+
"@rollup/plugin-json": "^6.1.0",
118+
"@rollup/plugin-node-resolve": "^15.2.3",
119+
"@rollup/plugin-replace": "^5.0.5",
120+
"@rollup/plugin-terser": "^0.4.4",
121+
"@rollup/plugin-virtual": "^3.0.2",
122+
"@rollup/plugin-typescript": "^11.1.6",
123+
"rollup": "^4.9.5",
124+
"tslib": "^2.6.2"
113125
}
114126
}

0 commit comments

Comments
 (0)