Prevent style sheets from being removed by tree shaking #3542
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Prevent an issue where CSS styles were sometimes stripped out by webpack tree shaking. When performing production builds with optimizations, this caused the table to appear without styling.
These optimizations are turned on (though often only for production mode) in some default Vue CLI or create-react-app configurations.
Details
Tabulator 5 was restructured to use ES6 modules, and its package.json includes a
sideEffects: false
declaration.Some applications use a common piece of webpack magic to embed styles via
import 'filename.css'
. In production (but sometimes not development mode!), all such side-effect-only imports will be stripped out, because Tabulator declares itself to have no side effects.See active webpack issue discussion for examples of other tools that have been surprised by this behavior. It is particularly annoying for projects that want to use new Tabulator features without upgrading their entire build tool. (since vue cli and create react app manage the webpack config internally)
The easiest fix is for tabulator.js to explicitly declare that CSS and SCSS files have side effects. (see webpack docs). Eg, this is used by bootstrap-vue.
Testing
A specific internal app of ours uses
vue-cli
to build a component that declaresimport 'tabulator-tables/dist/css/tabulator_bootstrap4.css';
.(behavior seen for vue CLI 3 projects; not sure about vue CLI 4)
This was tested using
npm link
for a local copy, before and after this PR change.Before side effects:
After:
Further notes
Our team really appreciates Tabulator! Since this has bitten several of our Vue.js projects recently, I've posted the initial PR for visibility.... but I recognize that the test case depends on specific webpack config details. If you'd like me to create a more elaborate test case for evaluation, please just ask and I can continue adding to this PR over the next few days.