Skip to content

feat(index): add noImporter option (options.noImporter) #307

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ Alternatively, for bootstrap-sass:

It's important to only prepend it with `~`, because `~/` resolves to the home directory. webpack needs to distinguish between `bootstrap` and `~bootstrap` because CSS and Sass files have no special syntax for importing relative files. Writing `@import "file"` is the same as `@import "./file";`

### Disabling imports for faster compile time

Function calls associated with the advanced file resolution described above can add up to a significant time on projects with a large number of scss files.
E.g. on a project with some 130 components each requiring an .scss file, sass build took 240 seconds with the importer, and 3 seconds without. To disable the
advanced import resolution, pass `noImporter: true` in the `sassLoader` options.


### Environment variables

If you want to prepend Sass code before the actual entry file, you can simply set the `data` option. In this case, the sass-loader will not override the `data` option but just append the entry's content. This is especially useful when some of your Sass variables depend on the environment:
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ module.exports = function (content) {
sassOptions.importer = sassOptions.importer ? proxyCustomImporters(sassOptions.importer, resourcePath) : [];
sassOptions.importer.push(getWebpackImporter());

// For larger projects, using the webpack importer can really add up: 4 minutes versus 3 seconds on a
// modest project with a 130 components and a dozen common definition files required in each scss file
if (sassOptions.noImporter === true) {
sassOptions.importer = undefined;
}

// `node-sass` uses `includePaths` to resolve `@import` paths. Append the currently processed file.
sassOptions.includePaths = sassOptions.includePaths ? [].concat(sassOptions.includePaths) : [];
sassOptions.includePaths.push(path.dirname(resourcePath));
Expand Down