-
-
Notifications
You must be signed in to change notification settings - Fork 238
/
rollup.config.mjs
149 lines (141 loc) · 3.21 KB
/
rollup.config.mjs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { uglify } from 'rollup-plugin-uglify'
import typescript from 'rollup-plugin-typescript2'
import replace from 'rollup-plugin-replace'
import versionInjector from 'rollup-plugin-version-injector'
import { createRequire } from 'module'
const pkg = createRequire(import.meta.url)('./package.json')
const version = process.env.VERSION || pkg.version
const sourcemap = true
const banner = `/*
* liquidjs@${version}, https://github.com/harttle/liquidjs
* (c) 2016-${new Date().getFullYear()} harttle
* Released under the MIT License.
*/`
const treeshake = {
propertyReadSideEffects: false
}
const tsconfig = (target) => ({
check: true,
tsconfigOverride: {
include: ['src'],
exclude: ['test', 'benchmark'],
compilerOptions: {
target,
module: 'ES2015',
rootDir: 'src'
}
}
})
const versionInjection = versionInjector({
injectInComments: false,
injectInTags: {
fileRegexp: /\.(ts|js|html|css)$/,
tagId: 'VI',
dateFormat: 'mmmm d, yyyy HH:MM:ss'
},
packageJson: './package.json',
logLevel: 'info',
logger: console,
exclude: []
})
const input = './src/index.ts'
const browserFS = {
include: './src/liquid-options.ts',
delimiters: ['', ''],
'./fs/fs-impl': './build/fs-impl-browser'
}
const browserStream = {
include: './src/emitters/index.ts',
delimiters: ['', ''],
'./streamed-emitter': '../build/streamed-emitter-browser'
}
const esmRequire = {
include: './src/fs/fs-impl.ts',
delimiters: ['', ''],
'./node-require': '../build/node-require.mjs'
}
const nodeCjs = {
output: [{
file: 'dist/liquid.node.js',
format: 'cjs',
banner
}],
external: ['path', 'fs', 'stream'],
plugins: [versionInjection, typescript(tsconfig('ES2020'))],
treeshake,
input
}
const nodeEsm = {
output: [{
file: 'dist/liquid.node.mjs',
format: 'esm',
banner
}],
external: ['path', 'fs', 'stream'],
plugins: [
versionInjection,
replace(esmRequire),
typescript(tsconfig('es6'))
],
treeshake,
input
}
const browserEsm = {
output: [{
file: 'dist/liquid.browser.mjs',
format: 'esm',
banner
}],
external: ['path', 'fs'],
plugins: [
versionInjection,
replace(browserFS),
replace(browserStream),
typescript(tsconfig('es6'))
],
treeshake,
input
}
const browserUmd = {
output: [{
file: 'dist/liquid.browser.umd.js',
name: 'liquidjs',
format: 'umd',
sourcemap,
banner
}],
plugins: [
versionInjection,
replace(browserFS),
replace(browserStream),
typescript(tsconfig('es5'))
],
treeshake,
input
}
const browserMin = {
output: [{
file: 'dist/liquid.browser.min.js',
name: 'liquidjs',
format: 'umd',
sourcemap,
banner
}],
plugins: [
versionInjection,
replace(browserFS),
replace(browserStream),
typescript(tsconfig('es5')),
uglify()
],
treeshake,
input
}
const bundles = []
const env = process.env.BUNDLES || ''
if (env.includes('cjs')) bundles.push(nodeCjs)
if (env.includes('esm')) bundles.push(nodeEsm, browserEsm)
if (env.includes('umd')) bundles.push(browserUmd)
if (env.includes('min')) bundles.push(browserMin)
if (bundles.length === 0) bundles.push(nodeCjs, nodeEsm, browserEsm, browserUmd, browserMin)
export default bundles