#javascript #rollupjs #polyfills
#язык JavaScript #rollupjs #полифиллы
Вопрос:
У меня есть следующее rollup.config.js
(я вставил только соответствующую информацию по этому вопросу):
import html from '@web/rollup-plugin-html'; import polyfillsLoader from '@web/rollup-plugin-polyfills-loader'; const htmlPlugin = html({ inputPath: 'index.html', inject: false, }); polyfillsLoader({ modernOutput: { name: 'modern', }, // Feature detection for loading legacy bundles legacyOutput: {name: 'legacy', test: '!('noModule' in HTMLScriptElement.prototype)'}, // List of polyfills to inject (each has individual feature detection) polyfills: { hash: true, coreJs: true, regeneratorRuntime: true, fetch: true, webcomponents: true, // Custom configuration for loading Lit's polyfill-support module, // required for interfacing with the webcomponents polyfills custom: [ { name: 'lit-polyfill-support', path: 'node_modules/lit/polyfill-support.js', test: '!('attachShadow' in Element.prototype)', module: false, }, ], }, }),
Это действительно вводит следующий сценарий в мою сборку:
lt;scriptgt;(function () { function polyfillsLoader() { function loadScript(src, type, attributes = []) { return new Promise(function (resolve) { var script = document.createElement('script'); function onLoaded() { if (script.parentElement) { script.parentElement.removeChild(script); } resolve(); } script.src = src; script.onload = onLoaded; attributes.forEach(att =gt; { script.setAttribute(att.name, att.value); }); script.onerror = function () { console.error('[polyfills-loader] failed to load: ' src ' check the network tab for HTTP status.'); onLoaded(); }; if (type) script.type = type; document.head.appendChild(script); }); } var polyfills = []; if (!('noModule' in HTMLScriptElement.prototype)) { polyfills.push(loadScript('./polyfills/regenerator-runtime.de2e6a3a74a500cae72a3cab1a403efc.js')); } if (!('fetch' in window)) { polyfills.push(loadScript('./polyfills/fetch.a1ad5fb96dc0cb61b9454244c9bd7fe6.js')); } if (!('attachShadow' in Element.prototype) || !('getRootNode' in Element.prototype) || window.ShadyDOM amp;amp; window.ShadyDOM.force) { polyfills.push(loadScript('./polyfills/webcomponents.d7ffce1754011cfedff5f846f12e0c11.js')); } if (!('noModule' in HTMLScriptElement.prototype) amp;amp; 'getRootNode' in Element.prototype) { polyfills.push(loadScript('./polyfills/custom-elements-es5-adapter.3342b468203af1a14ca005e80d14148f.js')); } if (!('attachShadow' in Element.prototype)) { polyfills.push(loadScript('./polyfills/lit-polyfill-support.82aa27f27be323af5a455ac87919622a.js')); } function loadFiles() { if (!('noModule' in HTMLScriptElement.prototype)) { [function () { return loadScript('./legacy-my-header-d84233c1.js', 'module', []); }, function () { return loadScript('./legacy-my-footer-353e3024.js', 'module', []); }, function () { return loadScript('./legacy-my-breadcrumbs-6977da2c.js', 'module', []); }, function () { return loadScript('./legacy-my-anchor-menu-3a71e855.js', 'module', []); }, function () { return loadScript('./legacy-my-contact-box-605983a9.js', 'module', []); }, function () { return loadScript('./legacy-my-transition-96158dc5.js', 'module', []); }, function () { return loadScript('./legacy-my-animated-slot-d7901404.js', 'module', []); }].reduce(function (a, c) { return a.then(c); }, Promise.resolve()); } else { [function () { return loadScript('./my-header-df4bd84c.js', 'module', []); }, function () { return loadScript('./my-footer-2e03a59d.js', 'module', []); }, function () { return loadScript('./my-breadcrumbs-ebb2c4c1.js', 'module', []); }, function () { return loadScript('./my-anchor-menu-9f6da4d8.js', 'module', []); }, function () { return loadScript('./my-contact-box-77b64be7.js', 'module', []); }, function () { return loadScript('./my-transition-b8f34c3f.js', 'module', []); }, function () { return loadScript('./my-animated-slot-7cfd347d.js', 'module', []); }].reduce(function (a, c) { return a.then(c); }, Promise.resolve()); } } if (polyfills.length) { Promise.all(polyfills).then(loadFiles); } else { loadFiles(); } } if (!('noModule' in HTMLScriptElement.prototype)) { var s = document.createElement('script'); function onLoaded() { document.head.removeChild(s); polyfillsLoader(); } s.src = "./polyfills/core-js.26813355b620c9d0fe88992b4621ff45.js"; s.onload = onLoaded; s.onerror = function () { console.error('[polyfills-loader] failed to load: ' s.src ' check the network tab for HTTP status.'); onLoaded(); }; document.head.appendChild(s); } else { polyfillsLoader(); } })();lt;/scriptgt;
Это дает мне ошибку:
Ожидается ‘)’
Что я сделал не так?