|
1 | 1 | import { nodeResolve } from '@rollup/plugin-node-resolve'; |
2 | | -import multi from '@rollup/plugin-multi-entry'; |
3 | 2 | import terser from '@rollup/plugin-terser'; |
4 | 3 | import copy from 'rollup-plugin-copy'; |
5 | 4 | import styles from "rollup-plugin-styler"; |
6 | 5 | 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 | +}); |
7 | 27 |
|
8 | 28 | const paths = { |
9 | 29 | src: 'app/assets/', |
@@ -89,29 +109,27 @@ export default [ |
89 | 109 | }, |
90 | 110 | // ES5 JS compilation |
91 | 111 | { |
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: [], |
102 | 115 | 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 |
109 | 121 | }, |
110 | 122 | 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 | + ]), |
115 | 133 | terser({ |
116 | 134 | ecma: '5' |
117 | 135 | }), |
|
0 commit comments