Installation
npm
npm i -D rollup-plugin-replace-amstramgram
Manually
Download the plugin in a rollup-plugin-replace-amstramgram folder located at the root of your project.
Dependencies
If you have chosen the manual way, install also fast-glob.
Usage
...
//Replace
//Here we use the es6 version of the plugin
import replace from './rollup-plugin-replace-amstramgram/esm/index.mjs'
//If the plugin has been installed from npm :
//import replace from 'rollup-plugin-replace-amstramgram'
export default = {
input: 'src/js/index.js',
output: {
file: 'dist/js/index.js',
format: ...
},
plugins: [
...
//Replace beginning and ending of tags by html entities :
// & becomes &
// < becomes <
// > becomes >
//The resulting text files are then included in final html files with htmlinclude
replace({
jobs: {
from:
[
`src/index.html`,
`src/css.html`,
`src/html/common/template.html`,
`rollup.config.mjs`,
`package.json`
],
to: `${src}html/code`,
rename: (name) => name + '.txt'
},
replace:
[
[/&/g, '&'], // & becomes &
[/</g, '<'], // < becomes <
[/>/g, '>'] // > becomes >
]
}),
....
]
}
Options
jobs
A Job or an array of Jobs.
A Job is an object whose properties are :
- from -
Either a String or an Array of Strings.
Each element should be a valid glob or a string pointing to an existing file or folder.
If the target is a folder, all relevant files at its root will be processed.
See here if you need details about glob.
- to -
A String (or an Array of Strings) pointing to folder(s) where to put the result.
- root -
A String that sets the reference for the result tree.
By default, all processed files are placed at the root of the destination folder(s) defined by the to option.
If a directory is set as root option, the files will be placed relatively to it (see below for an illustration).
(default : undefined)
- rename -
A String or a Function that defines how the resulting file(s) should be named.
The function takes the file name, its extension and its full path as arguments and should return a string.
Example :
rename: (name, ext, path) => name + '-replace' + ext
will result in :
index.html => index-replace.html
rename: (name) => name + '.txt'
will result in :
index.html => index.txt
If you process only one file, you can simply set :
rename: 'index-replace.html'
(default : undefined)
replace
A ReplaceOption or an array of ReplaceOption.
A ReplaceOption is an array whose first element must be a regular expression and the second element a string.
watch
A Boolean indicating whether folders containing files to process should be watched.
(default : false)
processHook
A String that defines the rollup hook used to process the files.
Note however that the watch option will be forced to false if you use a hook called after moduleParsed because rollup cannot call the addWatchFile function after the build has finished.
(default : "buildStart").
verbose
A Boolean that specifies whether messages and notifications should be sent to the terminal.
(default : false).
warnOnError
A Boolean that specifies whether warnings should be logged for process errors.
(default : true).