Skip to content

Commit

Permalink
fix(swiper): fix if loaded as lazy component
Browse files Browse the repository at this point in the history
fixes #4073
  • Loading branch information
nolimits4web committed Sep 14, 2022
1 parent c01b23c commit 32f3be9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scripts/build-core-lazy-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ function buildLazyComponentsJs(components, cb) {
return fs.existsSync(`./src/core/components/${component}/${component}.js`);
});

const swiperContent = fs.readFileSync(
path.resolve(__dirname, '../node_modules/swiper/swiper-bundle.js'),
);

rollup({
treeshake: false,
input: componentsToProcess.map(
Expand All @@ -144,6 +148,7 @@ function buildLazyComponentsJs(components, cb) {
delimiters: ['', ''],
'process.env.NODE_ENV': JSON.stringify(env), // or 'production'
'process.env.FORMAT': JSON.stringify(format),
[`import Swiper from 'swiper/bundle';`]: swiperContent,
}),
nodeResolve({ mainFields: ['module', 'main', 'jsnext'] }),
babel({ babelHelpers: 'bundled' }),
Expand Down Expand Up @@ -229,7 +234,9 @@ function buildLazyComponentsJs(components, cb) {
.replace(/var window = getWindow\(\);/g, '')
.replace(/var document = getDocument\(\);/g, '')
.replace(/getDocument\(\);/g, 'document')
.replace(/getWindow\(\);/g, 'window');
.replace(/getWindow\(\);/g, 'window')
.replace(/(const|var|let) window = window/g, '')
.replace(/(const|var|let) document = document/g, '');

fileContent = `${fileIntro}\n ${fileContent.trim()}${outro}`;
if (fileName.indexOf('swiper') >= 0) {
Expand Down

0 comments on commit 32f3be9

Please sign in to comment.