Skip to content
This repository was archived by the owner on Jan 16, 2018. It is now read-only.
This repository was archived by the owner on Jan 16, 2018. It is now read-only.

Loader query function, regex, and object, support #13

@colelawrence

Description

@colelawrence

Currently, the loader query only supports strings, and when you pass it an actual object, it applies stringify to it, and prevents the ability to pass a function, which may be desirable if you wish to pass a custom minification function, or a regex to your loader.

Query to json string in /lib/LoadersList.js#L52-L61

function getLoadersFromObject(element) {
    if(element.query) {
        if(!element.loader || element.loader.indexOf("!") >= 0) throw new Error("Cannot define 'query' and multiple loaders in loaders list");
        if(typeof element.query === "string") return [element.loader + "?" + element.query];
        return [element.loader + "?" + JSON.stringify(element.query)];
    }
    if(element.loader) return element.loader.split("!");
    if(element.loaders) return element.loaders;
    throw new Error("Element from loaders list should have one of the fields 'loader' or 'loaders'");
}

jade-locals interpretting query: webpack/jade-loader/index.js#L9-L20

module.exports = function(source) {
    this.cacheable && this.cacheable();
    var jade = require("jade");

    var utils = require("jade/lib/utils");
    var nodes = require("jade/lib/nodes");
    var filters = require("jade/lib/filters");

    var req = loaderUtils.getRemainingRequest(this).replace(/^!/, "");

    var query = loaderUtils.parseQuery(this.query);

It is especially relevant for my current project where we need to pass in a localization function (convert keys to text) into the jade-loader locals object.

I feel this can be addressed by allowing element.query to be either an object or a string.

Maybe there is a way to work around this by allowing the list of loaders to be objects of the modules themselves, as described in webpack/How to register a custom loader in webpack.config #903 or where is apply-loader to use with jade-loader #940

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions