Skip to content

feat(importer): add support for custom file extensions (options.extensions) - #583

Closed
benembery wants to merge 3 commits into
webpack:masterfrom
benembery:feature/configurable-file-extensions
Closed

benembery wants to merge 3 commits into
webpack:masterfrom
benembery:feature/configurable-file-extensions

Conversation

@benembery

Copy link
Copy Markdown

We are looking to add custom extensions support. Enabling files to be swapped out at compile time.

The following example allows shows the how the extensions would be configured.

{
  loader: "sass-loader",
    options: {
      sourceMap: true,
      extensions: [`.myext.scss`, ".scss", ".sass", ".css"],
    }
}

In our use case, we supply an arg to webpack-cli that configures the custom extension we wish to build.

Would you be interested in adding this to sass-loader as a feature.

@jsf-clabot

jsf-clabot commented Jun 22, 2018 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@alexander-akait
alexander-akait requested a review from jhnns June 22, 2018 15:21
@benembery benembery changed the title Allow file extensions to be supplied through loader options. [RFC] Allow file extensions to be supplied through loader options. Jun 22, 2018
@codecov

codecov Bot commented Jun 25, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #583 into master will increase coverage by 0.15%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #583      +/-   ##
==========================================
+ Coverage   97.54%   97.69%   +0.15%     
==========================================
  Files           6        6              
  Lines         122      130       +8     
==========================================
+ Hits          119      127       +8     
  Misses          3        3
Impacted Files Coverage Δ
lib/webpackImporter.js 100% <100%> (ø) ⬆️
lib/importsToResolve.js 100% <100%> (ø) ⬆️
lib/normalizeOptions.js 96.55% <100%> (+0.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d0b35cb...238a1ee. Read the comment docs.

@jhnns

jhnns commented Jul 11, 2018

Copy link
Copy Markdown
Contributor

The change seems ok and I'm kind of surprised that the tests still work, because the resolving logic is very brittle and did break the build several times.

However, I need to think about this change because I want to simplify the resolving behavior. Can you elaborate on your use case a little bit? Why would you want to deviate from Sass' default resolving behavior?

Maybe, this change also needs to be aligned with #573

@benembery

Copy link
Copy Markdown
Author

Hi @jhnns,
Thanks for taking a look at this.

Our use is multi-tenant web applications, where we wish to build from the same source but with specific modifications per tenant.
For example, I would create a master file, colours.scss and have a tenant-specific version named colours.tenant.scss and would like that to be picked up by sass when I am compiling with that tenant.

We are currently doing this for js files with webpack using resolve:extensions in the webpack configuration.

If you need more information than this, let me know.

@michael-ciniawsky michael-ciniawsky changed the title [RFC] Allow file extensions to be supplied through loader options. feat(importer): add support for custom file extensions (options.extensions) Aug 23, 2018
@michael-ciniawsky michael-ciniawsky added this to the 7.2.0 milestone Aug 23, 2018
@codecov

codecov Bot commented Sep 18, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #583 into master will increase coverage by 0.15%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #583      +/-   ##
==========================================
+ Coverage   97.54%   97.69%   +0.15%     
==========================================
  Files           6        6              
  Lines         122      130       +8     
==========================================
+ Hits          119      127       +8     
  Misses          3        3
Impacted Files Coverage Δ
lib/webpackImporter.js 100% <100%> (ø) ⬆️
lib/importsToResolve.js 100% <100%> (ø) ⬆️
lib/normalizeOptions.js 96.55% <100%> (+0.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d0b35cb...238a1ee. Read the comment docs.

@alexander-akait

Copy link
Copy Markdown
Member

You can do this using:

{
  test: /\.scss$/,
  loader: "sass-loader",
  resolve: {
    extensions: [ 'my', 'custom', 'extensions', 'scss', 'sass', 'css']
  }
},

@benembery

Copy link
Copy Markdown
Author

I've tried this and it doesn't work as previously outlined in my use case.

@alexander-akait

Copy link
Copy Markdown
Member

@benembery can you create minimum reproducible test repo?

@benembery

Copy link
Copy Markdown
Author

Hi, I'm very sorry for the delay getting you an example.
https://github.com/benembery/multi-tenant-sass-example
If you need anymore information let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants