-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
189 lines (149 loc) · 4.26 KB
/
rollup.config.js
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import fs from "fs";
// for node modules
import { nodeResolve } from '@rollup/plugin-node-resolve';
// typescript
import typescript from "@rollup/plugin-typescript";
// to load resources
import loadHtml from "rollup-plugin-html";
import json from "@rollup/plugin-json";
// to copy external scripts from node_modules
import copy from 'rollup-plugin-copy-watch';
// clearn up tools
import del from "rollup-plugin-delete";
import cleanup from "rollup-plugin-cleanup";
import strip from "@rollup/plugin-strip";
import replace from '@rollup/plugin-replace';
// development flag
const DEV = !!process.env.ROLLUP_WATCH;
const RELEASE = !!process.env.NODE_BUILD_RELEASE;
const Ver = JSON.parse(fs.readFileSync('./script/version.json'));
const VERSION_TXT = `${Ver.major}.${Ver.minor}.${String(Ver.build)}${Ver.tag}`;
// bundle file name
const bundleName = `frameless-slideshow`;
// destination
const dist = `${RELEASE ? `release/${bundleName}-v${VERSION_TXT}` : 'dist'}`;
// sites
const GITHUB_URL = `https://github.com/gitcobra/frameless-slideshow`;
// write banner
let BANNER_TXT = '';
if( !DEV ) {
BANNER_TXT = `/*
title: ${bundleName}
version: ${VERSION_TXT}
github: ${GITHUB_URL}
*/`;
}
const CommonPlugins = [
nodeResolve(),
json({compact: true}),
loadHtml({
include: [
"res/**/*html",
"res/*.css",
],
htmlMinifierOptions: {
removeComments: true,
collapseWhitespace: true,
//minifyCSS: true,
},
}),
// unfortunately rollup-plugin-json uses Object.freeze (that doesn't work on HTA of course).
// so it replaces "Object.freeze({...})" with "Object({...})".
replace({
'Object.freeze': 'Object',
preventAssignment: true,
}),
];
const BuildConfig = [
{
input: ["src/entry.ts"],
external: ['hta-ctx-menu', 'hta-drop-target'],
output: {
format: "iife",
file: `${dist}/core/${bundleName}.js`,
sourcemap: false,
globals: {
'hta-ctx-menu': "HtaContextMenu",
'hta-drop-target': 'HtaDropTarget',
},
banner: BANNER_TXT,
},
plugins: [
...RELEASE ? [
del({
targets: [`release/**/*`],
hook: 'buildStart',
verbose: true,
}),
] : [],
...CommonPlugins,
typescript({
"exclude": ["./test/*.ts"],
"compilerOptions": {
"declaration": false,
"noUnusedParameters": false,
"noUnusedLocals": false,
},
}),
copy({
watch: DEV ? ['assets/**/*', 'hta/**/*'] : null,
targets: [
{ src: 'node_modules/hta-ctx-menu/release/hta-ctx-menu.js', dest: `${dist}/external/` },
{ src: 'node_modules/hta-drop-target/release/hta-drop-target.js', dest: `${dist}/external/` },
{ src: 'node_modules/JSON2/json2.js', dest: `${dist}/external/` },
{ src: 'assets/*/', dest: `${dist}/` },
{ src: `hta/frameless-slideshow${DEV ? '-dev' : ''}.hta`, dest: `${dist}/`, rename: 'frameless-slideshow.hta' },
]
}),
// remove DEV blocks
...RELEASE ? [
strip({
include: ["**/*.js", "**/*.ts"],
labels: ["DEV"],
}),
cleanup()
] : [],
],
onwarn: suppress_warnings,
//watch: {clearScreen: false},
}
];
// for test folder.
if( DEV ) {
const TEST_SRC = './test/';
// create output settings for each file in the test folder
fs.readdirSync(TEST_SRC).forEach(async (file) => {
if( !fs.statSync(TEST_SRC + file).isFile() || !/\.ts$/i.test(file) )
return;
BuildConfig.push({
input: [TEST_SRC + file],
//external: ['hta-ctx-menu'],
output: {
format: "iife",
dir: './test/testjs',
sourcemap: false,
globals: {
//[externalId]: "HtaContextMenu",
},
},
plugins: [
typescript({
"compilerOptions": {
"declaration": false,
"noUnusedParameters": false,
"noUnusedLocals": false,
}
}),
...CommonPlugins,
],
onwarn: suppress_warnings,
watch: {clearScreen: false},
});
});
}
export default BuildConfig;
function suppress_warnings(warning, defaultHandler) {
if (warning.code === 'THIS_IS_UNDEFINED')
return;
defaultHandler(warning);
}