-
Notifications
You must be signed in to change notification settings - Fork 4
/
rollup.config.js
181 lines (147 loc) Β· 3.98 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
// rollup.config.js
const commonjs = require('rollup-plugin-commonjs');
const nodeResolve = require('rollup-plugin-node-resolve');
const replace = require('rollup-plugin-replace');
const typescript = require('rollup-plugin-typescript');
const terser = require("rollup-plugin-terser").terser;
const filesize = require('rollup-plugin-filesize');
const templateLiteralIndentFix = require('./rollup-plugins/template-literal-indent-fix');
const productionPruning = require('./rollup-plugins/production-pruning');
const { version } = require('./package.json');
const BUILD_DIR = 'build';
const WEB_FORMAT = 'iife';
const NODE_FORMAT = 'cjs';
const SOURCEMAP = true;
const SOURCEMAP_IN_PRODUCTION = false;
const INDENT = false;
const fileSizesObject = {};
const BASE_PLUGINS = [
typescript(),
replace({ __VERSION__: version }),
nodeResolve(),
commonjs(),
templateLiteralIndentFix(),
filesize({
render: function (options, bundle, { minSize, gzipSize, brotliSize, bundleSize }) {
fileSizesObject[bundle.file] = { minSize, bundleSize, gzipSize, brotliSize };
return bundle.file
},
}),
];
const configurations = [];
// { type, files, basePath }
function createConfigurations(options) {
const { files, basePath, ...baseOptions } = options;
files.forEach((file) => {
const path = `${basePath}/${file}.ts`;
const fileOptions = { ...baseOptions, file, path };
createConfiguration(fileOptions);
});
}
// { type, file, path }
function createConfiguration(options) {
const developmentWebConfiguration = createDevelopmentConfiguration(options);
const productionWebConfiguration = createProductionConfiguration(options);
const nodeConfiguration = createNodeConfiguration(options);
configurations.push(
developmentWebConfiguration,
productionWebConfiguration,
nodeConfiguration
);
}
function createNodeConfiguration({ type, file, path }) {
const outputFile = `./${BUILD_DIR}/${type}/${file}.js`;
const configuration = {
input: path,
plugins: [
...BASE_PLUGINS,
],
output: {
file: outputFile,
format: NODE_FORMAT,
},
};
if (!type) {
configuration.output.file = `./${BUILD_DIR}/${file}.js`;
}
return configuration;
}
function createDevelopmentConfiguration({ type, file, path, name }) {
const outputFile = `./${BUILD_DIR}/umd/${type}.${file}.development.js`.toLowerCase();
const configuration = {
input: path,
plugins: [
...BASE_PLUGINS,
],
output: {
file: outputFile,
format: WEB_FORMAT,
name: `_ADJS.${type}.${file}`,
indent: INDENT,
sourcemap: SOURCEMAP,
},
};
if (name) {
configuration.output.name = name;
}
if (!type) {
configuration.output.file = `./${BUILD_DIR}/umd/${file}.development.js`;
}
return configuration;
}
function createProductionConfiguration({ type, file, path, name, prune = true }) {
const configuration = {
input: path,
plugins: [
...BASE_PLUGINS,
prune ? productionPruning() : null,
terser(),
],
output: {
file: `./${BUILD_DIR}/umd/${type}.${file}.production.min.js`.toLowerCase(),
name: `_ADJS.${type}.${file}`,
format: WEB_FORMAT,
indent: INDENT,
sourcemap: SOURCEMAP_IN_PRODUCTION,
},
};
if (name) {
configuration.output.name = name;
}
if (!type) {
configuration.output.file = `./${BUILD_DIR}/umd/${file}.production.min.js`;
}
return configuration;
}
createConfigurations({
type: 'Plugins',
basePath: './src/plugins',
files: [
'AutoRender',
'AutoRefresh',
'DeveloperTools',
'GenericPlugin',
'Sticky',
'Responsive',
]
});
createConfigurations({
type: 'Networks',
basePath: './src/networks',
files: [
'DFP',
'Mock',
'Noop',
]
});
createConfiguration({
name: 'AdJS',
path: './src/index.ts',
file: 'core',
});
configurations.push(createProductionConfiguration({
path: './src/debug.ts',
prune: false,
file: 'debug',
}));
module.exports = { configurations, fileSizesObject };