Skip to content

Replace the context of the postcss option function by an argument #31

@MoOx

Description

@MoOx

The way it's currently handled is non intuitive https://github.com/postcss/postcss-loader/blob/a9cb6997eec444b4f90edd67ac7ec4b5d944cbb1/index.js#L28
What about replacing that .call(this) by just calling it with an argument?
Then in the configuration you can instead show a more clear code like

    postcss: function (webpack) {
        return [
            postcssImport({
                // see postcss-import docs to learn about onImport callback
                // https://github.com/postcss/postcss-import

                onImport: function (files) {
                    files.forEach(webpack.addDependency);
                }.bind(webpack)
            })
        ];
    }

Also fyi, I plan to add a addDependencyTo option to postcss-import in order to be able to write even more simpler and clean boilerplate like

    postcss: function (webpack) {
        return [
            postcssImport({
                addDependencyTo: webpack
            })
        ];
    }

What do you think?

Note: to avoid a breaking change, we might start by changing the doc + allow context and argument at the same time (via .call(this, this)), then in a later major release we replace .call(this, this) by (this).

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