Skip to content

Commit 4347659

Browse files
committed
Replace rollup-multi-entry plugin with own plugin
Plugin-multi-entry introduced a breaking change in v7 of always creating a deterministic output which uses sort() - rollup/plugins#1879 For the legacy bundle, we need the order of dependencies to be fixed. Instead of continuing to use this dependency, we have our own "plugin" which concatenates those files. In the build, we make sure that `this` means `window` context and that the file as before. Async load suggestion by @tombye
1 parent bb7394e commit 4347659

1 file changed

Lines changed: 39 additions & 21 deletions

File tree

rollup.config.mjs

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
import { nodeResolve } from '@rollup/plugin-node-resolve';
2-
import multi from '@rollup/plugin-multi-entry';
32
import terser from '@rollup/plugin-terser';
43
import copy from 'rollup-plugin-copy';
54
import styles from "rollup-plugin-styler";
65
import postCSSReplace from 'postcss-replace';
6+
import fs from 'node:fs/promises';
7+
8+
9+
const LEGACY_BUNDLE_ID = 'legacy-bundle'
10+
// Simple file concatenation plugin
11+
const concatenateFiles = (files) => ({
12+
// checking ID as it's a virtual module
13+
// https://rollupjs.org/plugin-development/#a-simple-example
14+
resolveId(id) {
15+
if (id === LEGACY_BUNDLE_ID) return id;
16+
},
17+
async load(id) {
18+
if (id === LEGACY_BUNDLE_ID) {
19+
const contents = await Promise.all(
20+
files.map(file => fs.readFile(file, 'utf-8'))
21+
);
22+
23+
return contents.join('\n');
24+
}
25+
}
26+
});
727

828
const paths = {
929
src: 'app/assets/',
@@ -89,29 +109,27 @@ export default [
89109
},
90110
// ES5 JS compilation
91111
{
92-
input: [
93-
paths.npm + 'jquery/dist/jquery.min.js',
94-
paths.npm + 'timeago/jquery.timeago.js',
95-
paths.npm + 'textarea-caret/index.js',
96-
paths.npm + 'cbor-js/cbor.js',
97-
paths.src + 'javascripts/modules.js',
98-
paths.src + 'javascripts/stick-to-window-when-scrolling.js',
99-
paths.src + 'javascripts/templateFolderForm.js',
100-
paths.src + 'javascripts/main.js',
101-
],
112+
input: LEGACY_BUNDLE_ID,
113+
context: 'window',
114+
external: [],
102115
output: {
103-
dir: paths.dist + 'javascripts/',
104-
sourcemap: true
105-
},
106-
moduleContext: {
107-
'./node_modules/jquery/dist/jquery.min.js': 'window',
108-
'./node_modules/cbor-js/cbor.js': 'window',
116+
file: paths.dist + 'javascripts/all.js',
117+
format: 'cjs',
118+
sourcemap: true,
119+
exports: 'none',
120+
strict: false
109121
},
110122
plugins: [
111-
nodeResolve(),
112-
multi({
113-
entryFileName: 'all.js'
114-
}),
123+
concatenateFiles([
124+
paths.npm + 'jquery/dist/jquery.min.js',
125+
paths.npm + 'timeago/jquery.timeago.js',
126+
paths.npm + 'textarea-caret/index.js',
127+
paths.npm + 'cbor-js/cbor.js',
128+
paths.src + 'javascripts/modules.js',
129+
paths.src + 'javascripts/stick-to-window-when-scrolling.js',
130+
paths.src + 'javascripts/templateFolderForm.js',
131+
paths.src + 'javascripts/main.js'
132+
]),
115133
terser({
116134
ecma: '5'
117135
}),

0 commit comments

Comments
 (0)