Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to insert non-stringified replacement? #6

Closed
joebartels opened this issue May 14, 2016 · 1 comment
Closed

Possible to insert non-stringified replacement? #6

joebartels opened this issue May 14, 2016 · 1 comment

Comments

@joebartels
Copy link

e.g. I'd like

<head>
  {{testFiles}}
</head>

replaced with:

<head>
  var testFiles=['tests/foo.js, 'tests/bar.js'];
</head>

I'm able to get that with this configuration:

const testFiles = `['some/path', 'another/path']`;

const testHTML = new Replace('tests', {
  files: ['**/*.html'],
  patterns: [
    {
      match: /{{testFiles}}/,
      replacement: `<script>var testFiles=${testFiles};</script>`
    }
  ]
});

Which is OK but I have to 'pre-stringify' the array I'd like to insert.

I'm curious on your thoughts w/ supporting inserting Objects or Arrays as-is.

@outaTiME
Copy link
Owner

outaTiME commented Mar 4, 2021

Hi, sorry for the long delay, you could try it in the following way:

const testFiles = ['some/path', 'another/path'];

const testHTML = new Replace('tests', {
  files: ['**/*.html'],
  patterns: [
    {
      match: /{{testFiles}}/,
      replacement: `<script>var testFiles=${JSON.stringify(testFiles)};</script>`
    }
  ]
});

@outaTiME outaTiME closed this as completed Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants