preact-cli icon indicating copy to clipboard operation
preact-cli copied to clipboard

getLoadersByName fails to resolve certain loaders

Open simonwep opened this issue 5 years ago • 0 comments

Do you want to request a feature or report a bug? A bug I guess, or if this is an intended behavior a feature.

What is the current behaviour? I'm using the sass-loader in combination with node-sass and want to modify the loader-config. Using helper.getLoadersByName(config, 'sass-loader') returns an empty array.

If the current behaviour is a bug, please provide the steps to reproduce.

$ preact create simple [name]

... install and update dependencies which at the end looks like this (snipped):

{
    "devDependencies": {
        "eslint": "^6.7.2",
        "eslint-config-synacor": "^3.0.5",
        "if-env": "^1.0.4",
        "node-sass": "^4.13.0",
        "preact-cli": "^2.2.1",
        "sass-loader": "^7.3.1"
    },
    "dependencies": {
        "preact": "^10.1.1",
        "preact-render-to-string": "^5.1.2"
    }
}

Create a preact.config.js with the following content:

export default (config, env, helpers) => {
    const sassLoader = helpers.getLoadersByName(config, 'sass-loader');
    console.log(sassLoader);
};

When I start it via npm run dev (preact watch) I'll receive an empty array: image

What is the expected behaviour? I'll get an array with the sass-loader-object inside of it.

Please mention other relevant information. I've managed to find a work-around:

const findLoaderByName = (rules, name) => {

    for (const {loaders} of rules) {
        for (const loader of loaders) {
            const loaderName = loader.loader;

            if (loaderName === 'proxy-loader') {
                if(loader.options.loader === name) {
                    return loader.options;
                }
            } else if (loaderName === name) {
                return loader;
            }
        }
    }

    return null;
};

export default (config, env, helpers) => {
    const sassLoader = findLoaderByName(helpers.getLoaders(config), 'sass-loader');
    // sassLoader is now resolved
    console.log(sassLoader);
};

Please paste the results of preact info here.

Unknown argument: info

The Preact-CLI version is 2.2.1 if you want that.

simonwep avatar Dec 17 '19 20:12 simonwep