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

Loaders: worth discussing "-loader" suffix? #54

Open
snoopdouglas opened this issue Jan 27, 2016 · 3 comments
Open

Loaders: worth discussing "-loader" suffix? #54

snoopdouglas opened this issue Jan 27, 2016 · 3 comments

Comments

@snoopdouglas
Copy link

I'm new to Webpack and have found this howto an invaluable resource. I have a problem (that might end up just being a question) about the module.loaders section of our webpack.config.js though:

module: {
  loaders: [
    { test: /\.less$/, loader: 'style-loader!css-loader!less-loader' }, // use ! to chain loaders
    { test: /\.css$/, loader: 'style-loader!css-loader' },
    { test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' } // inline base64 URLs for <=8k images, direct URLs for the rest
  ]
}

I'm not sure whether this is specific to the loaders used here, but in Webpack's documentation I'm seeing the -loader omitted - so we could instead use this:

module: {
  loaders: [
    { test: /\.less$/, loader: 'style!css!less' }, // use ! to chain loaders
    { test: /\.css$/, loader: 'style!css' },
    { test: /\.(png|jpg)$/, loader: 'url?limit=8192' } // inline base64 URLs for <=8k images, direct URLs for the rest
  ]
}

Is there any difference? Would it be worth adding a note mentioning that they're optional?

@kripod
Copy link

kripod commented Feb 28, 2016

There is really no difference between the two. You could even use the following code, which is - in my opinion - the best approach, and produces the same output as the aforementioned snippets.

module: {
  loaders: [
    { test: /\.less$/, loaders: ['style', 'css', 'less'] },
    { test: /\.css$/, loaders: ['style', 'css'] },
    { test: /\.(png|jpg)$/, loaders: ['url?limit=8192'] } // inline base64 URLs for <=8k images, direct URLs for the rest
  ]
}

@snoopdouglas
Copy link
Author

Agreed, using an array to specify loaders is far neater.

@mrchief
Copy link

mrchief commented Dec 22, 2016

Makes it easy to find usages I guess. Searching in files in your project for 'file-loader' and 'url-loader' is going to turn up much accurate results than searching for 'file' or 'url'.

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

3 participants