https://github.com/feflow/replace-text-loader
A webpack loader for replacing content text.
https://github.com/feflow/replace-text-loader
Last synced: 10 months ago
JSON representation
A webpack loader for replacing content text.
- Host: GitHub
- URL: https://github.com/feflow/replace-text-loader
- Owner: feflow
- License: mit
- Created: 2017-12-19T13:22:24.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-15T04:22:33.000Z (over 8 years ago)
- Last Synced: 2025-08-21T15:57:45.578Z (10 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
replace-text-loader
Install
```bash
npm i replace-text-loader
```
Usage
**webpack.config.js**
```js
module.exports = {
module: {
rules: [
{
test: /\.index.html$/,
use: [{
loader: 'replace-text-loader',
options: {
rules: [{
// inline script, 匹配所有的 需要inline的标签
// 并且替换为 ${require('raw-loader!babel-loader!../../node_modules/@tencent/report-whitelist')} 语法
pattern: /.*?<\/script>/gmi,
replacement: (source) => {
// 找到需要 inline 的包
const result = /${require('raw-loader!babel-loader!" + pkg + "')}";
}
}, {
// inline html, 匹配语法
pattern: //gmi,
replacement: (source) => {
// 找到需要 inline 的包
const result = //gmi.exec(source);
let path = result && result[1];
if (path && path[0] === '/') {
path = '../..' + path;
}
return "${require('raw-loader!" + path +"')}";
}
}]
}
}]
}
]
}
}
```