-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add api
option to allow switching to sass
modern compiler
#166
Conversation
df5fc13
to
195975a
Compare
This comment was marked as outdated.
This comment was marked as outdated.
2573095
to
0b83227
Compare
ba8fdd7
to
7399ec1
Compare
f867454
to
cd05bcd
Compare
This comment was marked as resolved.
This comment was marked as resolved.
cd05bcd
to
2969beb
Compare
2969beb
to
43a3241
Compare
LG - merging for further review. |
@@ -219,63 +77,112 @@ export = function plugin( | |||
} | |||
}, | |||
|
|||
transform(code, filePath) { | |||
async transform(code, filePath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job @marcalexiei - One thing - I noticed you're using async
here - Since we're (currently) supporting node versions ">= 10" I'm not sure we can just assume that all clients have support for async/await - Seems we may have to release a new (major) version of the plugin that makes this change. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, when I say "we're supporting..." I mean by way of our 'package.json' file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Async functions are supported from Node version 7.6.0. so this shouldn't be a breaking change.
(I haven't tested it out 😅).
Anyway if we are releasing this as a breaking change I would consider to make api: modern
the default value.
Created a new issue #173
Also I would like to do another change before the next release:
I'm trying to use processor
to generate CSS modules:
sass({
processor: async (styles, filePath) => {
let scopedClassNames = {};
const postcssProcessResult = await postcss([
postcssModules({
getJSON: (_, json) => {
if (json) scopedClassNames = json;
},
}),
]).process(styles, {
from: filePath,
});
return { ...scopedClassNames, css: postcssProcessResult.css };
},
Right now the plugin always returns the css string as export default
and I haven't found a clean solution to change it that using processor
options.
Have you implemented something similar that I can use or do you know another way?
My possible solution is to allow processor
output a new property (e.g.: cssModuleMap
) that, if present will be used as default
export. What do you think?
If you want to discuss this further I will open a separate issue since it is out of scope in this PR 😁.
New
api
optionsass
importer functions #154Add new optional
api
option to allow opt-in forsass
modern compiler API.Allowed values are:
legacy
(defaultOne) to preserve backward compatibility (consider to change this in a new major)modern
usescompileStringAsync
to compile sass code to css. The compile result transformations are the same oflegacy
option value.Due to the new API structure the two syntax are handled inside a switch with two different blocks.
Code examples
Refactors
In order to support the new syntax and retain backward compatibility different refactors have been made:
processRenderResponse
has been moved in a separate file insideutils
getImporterList
has been moved in a separate file insideutils
and renamed togetImporterListLegacy
, the same file houses the modern function variant:getImporterListModern
src/types
rollup
typessass
related types are imported fromsass
RollupPluginSassOptions
now is a type due the newapi
optionPluginState
has been renamed toRollupPluginSassState
and moved heresrc/utils/index
content has been divided into 2 files with self-explanatory names:src/utils/logger
src/utils/helpers
transform
function now is anasync
functionPending PR tasks
silence deprecation warning in legacy testsused sass 1.78 which doesn't have legacy-js-api warningapi
optioncheck logger function usages and consider to a prefix so user can clearly understand that they are coming from the plugin (e.g.:can be done in a separate PR[rollup-plugin-sass]:
)Follow up
sass
runtimes using dynamic resolve (see web pack)Warning
Pending PRs: