Skip to content

Conversation

@SkReD
Copy link

@SkReD SkReD commented Jan 5, 2017

No description provided.

@jsf-clabot
Copy link

jsf-clabot commented Jan 5, 2017

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@jhnns
Copy link
Member

jhnns commented Mar 7, 2017

Thank you for your pull-request. I think, importLoaders are not necessary anymore since with webpack 2 you can specify different loader pipelines depending on the issuer. Does this solve your use-case?

@SkReD
Copy link
Author

SkReD commented Mar 9, 2017

Don't quite understand how issuer is should be used. And how nested rules should be configured and how they applied. Could you provide some examples here on in webpack docs?

@jhnns
Copy link
Member

jhnns commented Mar 9, 2017

While trying this out, I saw that this is currently not possible. I have to adjust the less-loader (and the sass-loader) to make this possible, but I have a working copy that I will probably publish the next days.

With a workaround (by using the enforce option), however, this is already possible.

This is how the webpack.config.js would look like:

module.exports = {
    entry: [
        require.resolve("./entry.less"),
        require.resolve("./entry.js"),
    ],
    output: {
        filename: "bundle.js"
    },
    module: {
        rules: [
            {
                test: /\.js$/,

                // if the requesting module is a less file, than use this loader pipeline
                issuer: /\.less$/,

                enforce: "pre", // quick fix, enforce won't be necessary after less-loader fix
                use: [{
                    loader: require.resolve("./jsToLessLoader.js")
                }]
            },
            {
                test: /\.less$/,
                use: [{
                    loader: "css-loader"
                }, {
                    loader: "less-loader"
                }]
            }
        ]
    }
};
// entry.less
@import "./a.js"; // don't omit the extension, because less will assume .less files
// entry.js
import a from "./a";
// a.js
export default 42;

Does this solve your use-case?

Could you provide some examples here on in webpack docs?

We will probably publish some loader tips and best practices.

@SkReD
Copy link
Author

SkReD commented Mar 9, 2017

Yes. This is exactly what i need. Thank you

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.

3 participants