rollup-plugin-sass
rollup-plugin-sass copied to clipboard
add `api` option to allow switching to `sass` modern compiler
New api option
- Close #159
- Close #154
- Related to #152
Add new optional api option to allow opt-in for sass modern compiler API.
Allowed values are:
legacy(defaultOne) to preserve backward compatibility (consider to change this in a new major)modernusescompileStringAsyncto compile sass code to css. The compile result transformations are the same oflegacyoption value.
Due to the new API structure the two syntax are handled inside a switch with two different blocks.
Code examples
// should default to legacy when `api` is not specified
sass({ options: { data: '', outputStyle: 'compact' } });
// should error when LegacyOptions are used with `api: 'modern'`
// @ts-expect-error
sass({ api: 'modern', options: { data: '', outputStyle: 'compact' } });
// should only accept api parameter
sass({ api: 'modern' });
// should correctly infer modern API options
sass({ api: 'modern', options: { style: 'compressed' } });
Refactors
In order to support the new syntax and retain backward compatibility different refactors have been made:
processRenderResponsehas been moved in a separate file insideutilsgetImporterListhas been moved in a separate file insideutilsand renamed togetImporterListLegacy, the same file houses the modern function variant:getImporterListModernsrc/types- removed unused
rolluptypes - removed sass types aliases, now
sassrelated types are imported fromsass RollupPluginSassOptionsnow is a type due the newapioption- relevant unit tests are added
PluginStatehas been renamed toRollupPluginSassStateand moved here
- removed unused
src/utils/indexcontent has been divided into 2 files with self-explanatory names:src/utils/loggersrc/utils/helpers
- Plugin
transformfunction now is anasyncfunction
Pending PR tasks
- [x] find a way to dedupe test code (use macro)
- ~~silence deprecation warning in legacy tests~~ used sass 1.78 which doesn't have legacy-js-api warning
- [x] update README documentation
- [x] add
apioption - [x] add reference to NodePackageImporter
- [x] add
- ~~check logger function usages and consider to a prefix so user can clearly understand that they are coming from the plugin (e.g.:
[rollup-plugin-sass]:)~~ can be done in a separate PR
Follow up
- Check #140
- drop old versions of node
- convert package to ESM
- add support to other
sassruntimes using dynamic resolve (see web pack) - ...
- Consider using a modern package to resolve files (e.g.: import-meta-resolve)
[!WARNING] Pending PRs:
- #165
- #163