UNPKG

545 BJavaScriptView Raw
1'use strict';
2// moves the last `var hackOptions={...}` block to the top of the output
3// this is hackier than it should be, but gets the job done for now
4export default function () {
5 return {
6 renderChunk(code) {
7 const pattern = /^var\s+hackOptions.*?\s?=\s?{[\s\S]*?^};$/gm;
8 const matches = code.match(pattern);
9 if (!matches) {
10 return {
11 code: code
12 };
13 }
14 const header = matches[matches.length - 1];
15 return {
16 code: code.replace(header, '').replace("'use strict';", `'use strict';\n${header}`)
17 };
18 }
19 };
20}