Skip to content

Add explanation #1

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
jhnns opened this issue Apr 3, 2013 · 8 comments
Closed

Add explanation #1

jhnns opened this issue Apr 3, 2013 · 8 comments

Comments

@jhnns
Copy link
Member

jhnns commented Apr 3, 2013

Hi @sokra :)

how is the url- or file-loader supposed to work with the css-loader?

@jhnns
Copy link
Member Author

jhnns commented Apr 3, 2013

Sry I'm too dumb to get it. Tried something like this:

    background-image: url(file!../../bundle/assets/img/bg.jpg);

@sokra
Copy link
Member

sokra commented Apr 3, 2013

    background-image: url(../../bundle/assets/img/bg.jpg);

And configure it in the webpack options:

module.exports = {
  module: {
    loaders: [
      { test: /\.css$/,    loader: "style-loader!css-loader" },
      { test: /\.jpg$/,    loader: "url-loader?limit=10000&minetype=image/jpg" }
      // or: { test: /\.jpg$/,    loader: "file-loader" }
    ],
  }
};

Then:

require("./style.css");

For rar cases it also possible to overwrite it in the css:

    background-image: url(~!file!../../bundle/assets/img/bg.jpg);

Generally url(file) -> require("./file") and url(~file) -> require("file")

@sokra
Copy link
Member

sokra commented Apr 3, 2013

The url-loader generates a Data Url if file size below the limit. Elsewise it fall back to the file-loader.

The file-loader generates a file in your output.path. The basename is a md5 hash and extension is copied from original file.

@jhnns
Copy link
Member Author

jhnns commented Apr 3, 2013

Ah thx. Great! webpack is awesome 👍
I think the README should be more explicit on this point. Something like this (in case my presumption are correct 😀):

@import statements will be resolved by the css loader. The file will be included in place of the statement
url(...) statements will stay untouched unless a loader for that file-type has been specified in the webpack options.

@jhnns
Copy link
Member Author

jhnns commented Apr 3, 2013

Does the url() behaviour also apply on the less-loader? Or should it always be combined with the css-loader?

@sokra
Copy link
Member

sokra commented Apr 3, 2013

The less-loader just emits css. You have to configure it like this:

  { test: /\.less$/,   loader: "style-loader!css-loader!less-loader" },

Check this example config.

@jhnns
Copy link
Member Author

jhnns commented Apr 3, 2013

Yep, thx!

@jhnns
Copy link
Member Author

jhnns commented Apr 9, 2013

I think the line "You should define useful loaders by config." is still a bit unclear. Would be nice to include some example config that will be passed to webpack. I sought for a way to pass the url-loader a config object.

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

No branches or pull requests

2 participants