|
| 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; |
0 commit comments