This is a:
Environment:
Updated Swiper from 5 to 6.
The library should work
While the library is working perfectly locally, it is completely broken when building for Production (w/ Tree Shaking)
After some investigations I found out these side effects that are cut off by webpack:
https://github.com/nolimits4web/swiper/blob/9ed4c97717fc17ab46f62bd3fbaa39f1c96f4ae6/src/utils/dom.js#L80-L82
Adding this particular file to array of sideEffects in library's package.json solved my problem but there are other files that have similar side effects. For example, this one:
https://github.com/nolimits4web/swiper/blob/1b08355540bdda8707debfc72721c8e0a12274c2/src/swiper.js#L10-L18
...and styles mentioned in #3673
sideEffects: false in package.json can be considered as short-term solution to ensure everything is working finesideEffects: [...] after reviewing each source file...Some minimal reproduction repo? I agree to add styles to side effects as proposed in #3673. But example with Dom lib seems not valid to me. This file is imported and used (called) almost in every file. So dropping it out of bundle seems like bundler issue for me
Thanks for quick response. Just tried to play around webpack and terser and can't reproduce the issue indeed.
However when I install new Angular app and integrate Swiper into it then the issue persist: Swiper just can't see any methods of dom7 ('children' is not a function)
Please don't close the issue so far. I will try to figure out whether it is Angular or Webpack is the source of problem and come back. Not sure that my knowledge will be enough to figure it out though
Dom7 uses Array subclassing, (e.g. class Dom7 extends Array), not sure how Angular works but maybe it tries to add some reactivity to array, thinks it usual array and don't inherit Dom7 props properly?
Same issue with Vue (https://github.com/vuejs/vue/issues/9259) but it is solved with proposed there code snippet
Well I created issue on angular CLI but they insist that dom.js HAS a top-level side effect. Technically it's true Webpack's definition of "side effect":
A "side effect" is defined as code that performs a special behavior when imported, other than exposing one or more exports.
Please see the last comment of the issue I created (already closed)
@nolimits4web I ran into the same issue. I made a minimal reproduction repo https://github.com/ierehon1905/swiper-minimal-repo. Hope it helps.
Hi, I have the same problem with a Gatsby project: in the development all works fine but when I build the project the styles are excluded.
To solve it I've been adding a "fake" use of it:
import style from "swiper/swiper-bundle.css"
console.log(style)
require('swiper/swiper-bundle.css');
Using require instead of import inside webpack project can be used as a temporary solution.
sideEffects in package.json doesn't affect styles which are imported using require.
Most helpful comment
Hi, I have the same problem with a Gatsby project: in the development all works fine but when I build the project the styles are excluded.
To solve it I've been adding a "fake" use of it: