-
-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
165 lines (157 loc) · 3.66 KB
/
rollup.config.mjs
File metadata and controls
165 lines (157 loc) · 3.66 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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 browserBase64 = {
include: './src/filters/base64.ts',
delimiters: ['', ''],
'./base64-impl': '../build/base64-impl-browser'
}
const browserCrypto = {
include: './src/filters/crypto.ts',
delimiters: ['', ''],
'./crypto-impl': '../build/crypto-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', 'crypto'],
plugins: [versionInjection, typescript(tsconfig('ES2020'))],
treeshake,
input
}
const nodeEsm = {
output: [{
file: 'dist/liquid.node.mjs',
format: 'esm',
banner
}],
external: ['path', 'fs', 'stream', 'crypto'],
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(browserBase64),
replace(browserCrypto),
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(browserBase64),
replace(browserCrypto),
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(browserBase64),
replace(browserCrypto),
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