Repository navigation
Expand file tree
/
Copy pathrollup.shared.config.mjs
More file actions
88 lines (82 loc) · 2.04 KB
/
Copy pathrollup.shared.config.mjs
File metadata and controls
88 lines (82 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import typescript from '@rollup/plugin-typescript'
import CommonJS from '@rollup/plugin-commonjs'
import filesAsDataURIs from '@rollup/plugin-url'
import nodePolyfills from 'rollup-plugin-polyfill-node'
import nodeResolve from '@rollup/plugin-node-resolve'
import json from '@rollup/plugin-json'
import terser from '@rollup/plugin-terser'
const createEasyQRCodeAliasPlugin = (variant) => ({
name: `gc-easyqrcodejs-${variant}-alias`,
async resolveId(source, importer) {
if (
!source ||
source === 'easyqrcodejs' ||
!/(^|\/)easyqrcodejs$/.test(source)
) {
return null
}
const nextSource = source.replace(
/easyqrcodejs$/,
`easyqrcodejs.${variant}`
)
const resolved = await this.resolve(nextSource, importer, {
skipSelf: true
})
return resolved || nextSource
}
})
const createPlugins = ({ browser, minify = false }) =>
[
browser ? nodePolyfills() : null,
json(),
filesAsDataURIs({
include: [
'./src/assets/images/*.png',
'./src/assets/images/*.jpg',
'./src/assets/images/*.svg'
]
}),
createEasyQRCodeAliasPlugin(browser ? 'browser' : 'node'),
typescript({
sourceMap: false,
tsconfig: './tsconfig.json',
exclude: ['./src/assets/*', './bin/*']
}),
nodeResolve({
browser,
preferBuiltins: !browser
}),
CommonJS(
browser
? {
include: ['./node_modules/**/*.js'],
dynamicRequireTargets: ['./node_modules/**/*.js']
}
: {}
),
minify
? terser({
module: true,
format: { comments: false }
})
: null
].filter(Boolean)
export const createRollupConfig = ({
browser,
minify = false,
outputFile,
format
}) => ({
input: 'src/runtime-entry.ts',
output: {
file: outputFile,
format,
name: 'gc',
exports: 'default',
extend: true,
inlineDynamicImports: true,
sourcemap: false
},
external: browser ? [] : ['jsdom', 'xmldom'],
plugins: createPlugins({ browser, minify })
})