Skip to content
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 alias feature to rewrite urls #274

Merged
merged 3 commits into from
Mar 18, 2017

Conversation

bbtfr
Copy link
Contributor

@bbtfr bbtfr commented May 6, 2016

Hi guys,
I found sometimes, it's not easy to change the source file / input file of css-loader, e.g.: when we're using sass files in another package (bootstrap-sass), we'll get a lot of complains about Cannot resolve 'file' or 'directory' ....
There are tons of questions on Google about this.
For bootstrap, we may use $icon-font-path or bootstrap-loader, but for other projects, we have nothing.
resolve-url-loader is a solution, but it's based on source-map and makes the compilation much slower.
So what do you think if we rewrite urls in css-loader?

Here's an example to load bootstrap-sass with sass-loader, css-loader & style-loader

// webpack.config.js
// ## Webpack Configuration
var path = require('path');

module.exports = {
  entry: "./src/entry",
  output: {
    filename: 'bundle.js',
    path: path.resolve('./dist')
  },
  module: {
    // ### Loaders
    loaders: [
      { test: /\.js$/, loader: "babel" },
      { test: /\.scss$/, loader: "style!css!sass" },
      { test: /\.(woff|woff2|ttf|eot|svg)$/, loader: "url?limit=10000" }
    ]
  },
  cssLoader: {
    alias: {
      "../fonts/bootstrap": "bootstrap-sass/assets/fonts/bootstrap"
    }
  },
  sassLoader: {
    includePaths: [
      path.resolve("./node_modules/bootstrap-sass/assets/stylesheets")
    ]
  }
};
// stylesheet.scss
@charset "UTF-8";
@import "bootstrap";

cssLoader.alias use the same syntax with resolve.alias, https://webpack.github.io/docs/configuration.html#resolve-alias

@codecov-io
Copy link

codecov-io commented May 6, 2016

Codecov Report

Merging #274 into master will increase coverage by 0.11%.
The diff coverage is 100%.

@@            Coverage Diff            @@
##           master    #274      +/-   ##
=========================================
+ Coverage   98.19%   98.3%   +0.11%     
=========================================
  Files           9      10       +1     
  Lines         332     354      +22     
  Branches       75      79       +4     
=========================================
+ Hits          326     348      +22     
  Misses          6       6
Impacted Files Coverage Δ
lib/createResolver.js 100% <100%> (ø)
lib/loader.js 100% <100%> (ø)

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 04dabca...9e05a7c. Read the comment docs.

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alias is good idea 👍, can you check against webpack 2 / webpack 2 options syntax please?

@joshwiens
Copy link
Member

This will need to be updated to 2.x syntax before it's reviewed. With the defaults updates requiring major versions, this would have to be compatible / focused on Webpack > 2.0

@jsf-clabot
Copy link

jsf-clabot commented Mar 18, 2017

CLA assistant check
All committers have signed the CLA.

@bebraw
Copy link
Contributor

bebraw commented Mar 18, 2017

Can you sign the CLA and document the feature at readme?

@bbtfr
Copy link
Contributor Author

bbtfr commented Mar 18, 2017

The code has been rebased, updated to 2.x syntax
The alias resolving functionality has been moved to createResolver.js, so it would be clearer
And the document is also been updated

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbtfr Thx

@michael-ciniawsky michael-ciniawsky merged commit c8db489 into webpack-contrib:master Mar 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants