3 thoughts on “Query JSON config on chained loaders

  1. {
        test: /\.css$/,
        loader: "style-loader"
        query: { a: 1 }
    },
    {
        test: /\.css$/,
        loader: "css-loader"
        query: { b: 2 }
    }

    or

    {
        test: /\.css$/,
        loaders: [
            "style?" + JSON.stringify({
                a: 1
            }),
            "css?" + JSON.stringify({
                b: 2
            })
        ]
    }

    or

    {
        test: /\.css$/,
        loaders: [
            q("style", {
                a: 1
            }),
            q("css", {
                b: 2
            })
        ]
    }
    function q(loader, query) {
        return loader + "?" + JSON.stringify(query);
    }
  2. This is not possible today:

    {
        test: /\.css$/,
        loader: "style-loader"
        query: { a: 1 }
    },
    {
        test: /\.css$/,
        loader: "css-loader"
        query: { b: 2 }
    }

    I get this error:

    Error: Cannot define 'query' and multiple loaders in loaders list
    
  3. FWIW: this structure seemed to work:

    module: {
            loaders: [{
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                loaders: [{
                    loader: "babel",
                    query: {
                        cacheDirectory: true
                    }
                }],
            }, {
                test: /\.html$/,
                loader: 'file?name=[name].[ext]'
            }, {
                test: /\.scss$/,
                loaders: [{
                    loader: 'sass-loader',
                    query: {
                        sourceMap: true,
                        includePaths: [
                            __dirname + "/app/styles"
                        ]
                    }
                }]
            }],
        },

Comments are closed.