From 299828c4e12025d2491e867ba057617229048c62 Mon Sep 17 00:00:00 2001 From: munrocket Date: Wed, 25 Sep 2019 15:26:36 +0400 Subject: [PATCH] replacement feature --- README.md | 12 +++++++++--- index.js | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4cf0ddd..52f455c 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,17 @@ rollup({ entry: "main.js", plugins: [ string({ - // Required to be specified + // target files include: "**/*.html", - // Undefined by default - exclude: ["**/index.html"] + // [optional] excluded files + exclude: ["**/index.html"], + + // [optional] replace pattern (regexp|substr) + replacePattern: '/n', + + // [optional] replacement (newSubstr|function) + replacement: '' }) ] }); diff --git a/index.js b/index.js index e67387f..5cddcc1 100644 --- a/index.js +++ b/index.js @@ -12,8 +12,12 @@ function string(opts = {}) { transform(code, id) { if (filter(id)) { + code = JSON.stringify(code); + if (opts.replacePattern && opts.replacement) { + code = code.replace(opts.replacePattern, opts.replacement); + } return { - code: `export default ${JSON.stringify(code)};`, + code: `export default ${code};`, map: { mappings: "" } }; }