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 resolve options for imports from css files. #474
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b54ec7b
Specify resolve option to be used with the sass-loader. This allows @…
0f9657f
Specify resolve option to be used with the css-loader. This allows @i…
b9e42be
Add functional test for sass imports via package.json sass property
382bc5f
Add functional test for css imports via package.json style property
9525e7a
Merge branch 'master' into resolve
weaverryan 7895f63
fixing CS
weaverryan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
What exactly does this do in the process? I know what
resolve.extensions
does at the root level - it allows you to omit the file extension. But what about here? If I sayimport 'foo-bar'
wherefoo-bar
is a module, what is the purpose of theextensions
?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.
The
resolve.extensions
value overrides the value at the root level. When you say@import 'foo-bar'
Webpack will first check for an alias calledfoo-bar
. If it does not find an alias forfoo-bar
it will check each directory specified inresolve.modules
for a directory calledfoo-bar
. Assuming it finds that directory, it will then look to see if there is a package.json file for the module. If there is, it will use theresolve.mainFields
setting to determine which file to import. If there is not then it will use theresolve.mainFiles
in conjunction withresolve.extentions
to determine what file to look for in that directory.If you were to say
@import './foo-bar'
then Webpack would look in the current directory for a file named foo-bar with an extension of.scss
,.sass
, or.css
in that order.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.
One more question: because this is being added to the sass loader, this resolution logic applies to files being imported from within a Sass file only, right? So, for example, if I were in
foo.css
(the earlier import),
./foo-barwould look for
foo-bar.cssbut not
foo-bar.scss` (because that rule only lives down here).What about less & stylus below? Do those also need these options?
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.
Yes, these are loader specific options. So
@import "./foo-bar"
infoo.css
would only look for./foo-bar.css
and notfoo-bar.scss
.These options can be specified for any loaders where appropriate so long as that loader uses Webpack to perform the import resolution.