|
8 | 8 | *
|
9 | 9 | */
|
10 | 10 |
|
| 11 | +import assert from 'assert'; |
| 12 | + |
11 | 13 | import deepMerge from 'deepmerge';
|
12 | 14 | import license from 'rollup-plugin-license';
|
13 | 15 | import resolve from '@rollup/plugin-node-resolve';
|
@@ -190,3 +192,46 @@ export function makeBaseBundleConfig(options) {
|
190 | 192 |
|
191 | 193 | return deepMerge(sharedBundleConfig, isAddOn ? addOnBundleConfig : standAloneBundleConfig);
|
192 | 194 | }
|
| 195 | + |
| 196 | +export function makeMinificationVariants(existingConfigs) { |
| 197 | + const newConfigs = []; |
| 198 | + |
| 199 | + // ensure we've got an array of configs rather than a single config |
| 200 | + existingConfigs = Array.isArray(existingConfigs) ? existingConfigs : [existingConfigs]; |
| 201 | + |
| 202 | + existingConfigs.forEach(existingConfig => { |
| 203 | + const { plugins } = existingConfig; |
| 204 | + |
| 205 | + // The license plugin has to be last, so it ends up after terser. Otherwise, terser will remove the license banner. |
| 206 | + assert( |
| 207 | + getLastElement(plugins).name === 'rollup-plugin-license', |
| 208 | + `Last plugin in given options should be \`rollup-plugin-license\`. Found ${getLastElement(plugins).name}`, |
| 209 | + ); |
| 210 | + |
| 211 | + const minificationVariants = [ |
| 212 | + { |
| 213 | + output: { |
| 214 | + file: `${existingConfig.output.file}.js`, |
| 215 | + }, |
| 216 | + plugins, |
| 217 | + }, |
| 218 | + { |
| 219 | + output: { |
| 220 | + file: `${existingConfig.output.file}.min.js`, |
| 221 | + }, |
| 222 | + plugins: insertAt(plugins, -2, terserPlugin), |
| 223 | + }, |
| 224 | + ]; |
| 225 | + |
| 226 | + minificationVariants.forEach(variant => { |
| 227 | + const mergedConfig = deepMerge(existingConfig, variant, { |
| 228 | + // this makes it so that instead of concatenating the `plugin` properties of the two objects, the first value is |
| 229 | + // just overwritten by the second value |
| 230 | + arrayMerge: (first, second) => second, |
| 231 | + }); |
| 232 | + newConfigs.push(mergedConfig); |
| 233 | + }); |
| 234 | + }); |
| 235 | + |
| 236 | + return newConfigs; |
| 237 | +} |
0 commit comments