bazelbuild / rules_postcss

PostCSS rules for Bazel
Apache License 2.0
10 stars 13 forks source link

Move responsibility for defining Node.js require into postcss_plugin #17

Closed rzhw closed 4 years ago

rzhw commented 4 years ago

Currently, postcss_binary is where plugin deps and the Node.js require string for each plugin is meant to be written. Take the following example:

postcss_plugin(
    name = "list_selectors",
    srcs = [
        "list-selectors.js",
    ],
)

postcss_binary(
    name = "style_processed",
    src = "style.css",
    plugins = {
        "build_bazel_rules_postcss/examples/additional_outputs/list-selectors.js": "[{markdownDir: 'examples/additional_outputs'}]",
    },
    additional_outputs = ["selectors.md"],
    deps = [
        ":list_selectors",
    ],
)

If we wanted to reuse the :list_selectors plugin in another postcss_binary target, then we need to write out not only the ":list_selectors" dep, but also "build_bazel_rules_postcss/examples/additional_outputs/list-selectors.js" all over again.

This string is also pretty verbose.

Can we make it so we write out something like this instead?

postcss_plugin(
    name = "list_selectors",
    node_require = "build_bazel_rules_postcss/examples/additional_outputs/list-selectors.js",
    srcs = [
        "list-selectors.js",
    ],
)

postcss_binary(
    name = "style_processed",
    src = "style.css",
    plugins = {
        ":list_selectors": "[{markdownDir: 'examples/additional_outputs'}]",
    },
    additional_outputs = ["selectors.md"],
    deps = [
        ":list_selectors",
    ],
)

It'd be great if we could leave out deps too, but if we can't let's leave that out of scope for this issue.