0.2.4 • Published 4 months ago

rollup-plugin-template-replace v0.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Replace the template expressions and restore them.

It won't process nested expressions.

import replace from "rollup-plugin-template-replace";

export default {
  input: "index.js",
  output: {
    dir: "output",
    format: "esm",
  },
  plugins: [
    replace({
      /* options */
    }),
  ],
};

Example, use a CSS preprocessor to process the modified text.

replace({
  match: (tag) => tag === "css",
  callback: (input) => postcss(/* postcss plugins */).process(input).css.trim(),
  replace: (_, index) => `--__REPLACE__${index}__`,
});

before replacement

css`
  .class {
    ${"expression_0"}: ${"expression_1"};
  }
`;

after replacement

css`
  .class {
    --__REPLACE__0__: --__REPLACE__1__;
  }
`;

callback input (content between `)

.class {
  --__REPLACE__0__: --__REPLACE__1__;
}

Final output text will be restored.

0.2.1

6 months ago

0.2.0

7 months ago

0.1.1

8 months ago

0.2.3

5 months ago

0.2.2

5 months ago

0.2.4

4 months ago

0.1.0

9 months ago

0.0.0

9 months ago