手动开发一个插件
JavaScript
export default function (options) {
return {
name: 'replace-plugin',
transform (code, id) {
if (options.target && options.replacement) {
return code.replace(new RegExp(options.target, 'g'), options.replacement);
}
return null;
}
}
}
export default function (options) {
return {
name: 'replace-plugin',
transform (code, id) {
if (options.target && options.replacement) {
return code.replace(new RegExp(options.target, 'g'), options.replacement);
}
return null;
}
}
}
注意如果报错 `[!] RollupError: Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.
Original error: Cannot use import statement outside a module`
可以加package.json 里添加 "type" :"module" 就可以解决