📚 论文级功能实现: - ✅ KaTeX数学公式渲染系统 (内联$...1411...1411) - ✅ 高级代码高亮 (行号、标题、语法着色) - ✅ PWA渐进式Web应用支持 - ✅ 多语言代码支持 (20+编程语言) - ✅ 代码行标注系统 (错误/成功/警告/高亮) 🧮 数学公式系统: - LaTeX语法完整支持 - 数学宏定义 (\RR, \NN, \ZZ, \QQ, \CC等) - 复杂公式渲染 (矩阵、积分、求和、分数) - 响应式数学表达式 - 黑暗模式数学公式适配 💻 高级代码展示: - 代码块标题显示 - 行号自动生成 - 语法高亮增强 - 多行高亮标注 - 错误/成功/警告行标记 - 20+编程语言支持 🔧 企业级插件: - @docusaurus/plugin-pwa (离线支持) - rehype-katex (数学公式) - remark-math (数学语法) - remark-gfm (GitHub风格Markdown) - prism-react-renderer (代码高亮) 📊 算法示例升级: - Transformer深度学习模型 - 多头注意力机制实现 - 完整的神经网络架构 - 专业文档注释 - 类型提示和错误处理 🎨 视觉优化: - 数学公式背景框 - 代码行高亮动画 - 专业配色方案 - 渐变边框效果 - 响应式设计适配 📱 PWA功能: - 离线访问支持 - 应用图标配置 - 清单文件完整 - 主题色统一 - 安装提示优化 🚀 性能优化: - 图片质量提升至85% - 代码分割优化 - 字体预加载 - CSS变量系统 - GPU加速渲染 ✨ 用户体验: - 论文级排版标准 - 学术引用格式 - 专业视觉层次 - 无障碍访问支持 - 多设备完美适配
188 lines
4.7 KiB
Markdown
188 lines
4.7 KiB
Markdown
[npm]: https://img.shields.io/npm/v/@rollup/plugin-replace
|
|
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-replace
|
|
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-replace
|
|
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-replace
|
|
|
|
[![npm][npm]][npm-url]
|
|
[![size][size]][size-url]
|
|
[](https://liberamanifesto.com)
|
|
|
|
# @rollup/plugin-replace
|
|
|
|
🍣 A Rollup plugin which replaces targeted strings in files while bundling.
|
|
|
|
## Requirements
|
|
|
|
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v8.0.0+) and Rollup v1.20.0+.
|
|
|
|
## Install
|
|
|
|
Using npm:
|
|
|
|
```console
|
|
npm install @rollup/plugin-replace --save-dev
|
|
```
|
|
|
|
## Usage
|
|
|
|
Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:
|
|
|
|
```js
|
|
import replace from '@rollup/plugin-replace';
|
|
|
|
export default {
|
|
input: 'src/index.js',
|
|
output: {
|
|
dir: 'output',
|
|
format: 'cjs'
|
|
},
|
|
plugins: [
|
|
replace({
|
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
__buildDate__: () => JSON.stringify(new Date()),
|
|
__buildVersion: 15
|
|
})
|
|
]
|
|
};
|
|
```
|
|
|
|
Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).
|
|
|
|
The configuration above will replace every instance of `process.env.NODE_ENV` with `"production"` and `__buildDate__` with the result of the given function in any file included in the build.
|
|
|
|
_Note: Values must be either primitives (e.g. string, number) or `function` that returns a string. For complex values, use `JSON.stringify`. To replace a target with a value that will be evaluated as a string, set the value to a quoted string (e.g. `"test"`) or use `JSON.stringify` to preprocess the target string safely._
|
|
|
|
Typically, `@rollup/plugin-replace` should be placed in `plugins` _before_ other plugins so that they may apply optimizations, such as dead code removal.
|
|
|
|
## Options
|
|
|
|
In addition to the properties and values specified for replacement, users may also specify the options below.
|
|
|
|
### `delimiters`
|
|
|
|
Type: `Array[...String, String]`<br>
|
|
Default: `['\b', '\b']`
|
|
|
|
Specifies the boundaries around which strings will be replaced. By default, delimiters are [word boundaries](https://www.regular-expressions.info/wordboundaries.html). See [Word Boundaries](#word-boundaries) below for more information.
|
|
|
|
### `preventAssignment`
|
|
|
|
Type: `Boolean`<br>
|
|
Default: `false`
|
|
|
|
Prevents replacing strings where they are followed by a single equals sign. For example, where the plugin is called as follows:
|
|
|
|
```js
|
|
replace({
|
|
values: {
|
|
'process.env.DEBUG': 'false'
|
|
}
|
|
});
|
|
```
|
|
|
|
Observe the following code:
|
|
|
|
```js
|
|
// Input
|
|
process.env.DEBUG = false;
|
|
if (process.env.DEBUG == true) {
|
|
//
|
|
}
|
|
// Without `preventAssignment`
|
|
false = false; // this throws an error because false cannot be assigned to
|
|
if (false == true) {
|
|
//
|
|
}
|
|
// With `preventAssignment`
|
|
process.env.DEBUG = false;
|
|
if (false == true) {
|
|
//
|
|
}
|
|
```
|
|
|
|
### `exclude`
|
|
|
|
Type: `String` | `Array[...String]`<br>
|
|
Default: `null`
|
|
|
|
A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored.
|
|
|
|
### `include`
|
|
|
|
Type: `String` | `Array[...String]`<br>
|
|
Default: `null`
|
|
|
|
A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.
|
|
|
|
### `values`
|
|
|
|
Type: `{ [key: String]: Replacement }`, where `Replacement` is either a string or a `function` that returns a string.
|
|
Default: `{}`
|
|
|
|
To avoid mixing replacement strings with the other options, you can specify replacements in the `values` option. For example, the following signature:
|
|
|
|
```js
|
|
replace({
|
|
include: ['src/**/*.js'],
|
|
changed: 'replaced'
|
|
});
|
|
```
|
|
|
|
Can be replaced with:
|
|
|
|
```js
|
|
replace({
|
|
include: ['src/**/*.js'],
|
|
values: {
|
|
changed: 'replaced'
|
|
}
|
|
});
|
|
```
|
|
|
|
## Word Boundaries
|
|
|
|
By default, values will only match if they are surrounded by _word boundaries_.
|
|
|
|
Consider the following options and build file:
|
|
|
|
```js
|
|
module.exports = {
|
|
...
|
|
plugins: [replace({ changed: 'replaced' })]
|
|
};
|
|
```
|
|
|
|
```js
|
|
// file.js
|
|
console.log('changed');
|
|
console.log('unchanged');
|
|
```
|
|
|
|
The result would be:
|
|
|
|
```js
|
|
// file.js
|
|
console.log('replaced');
|
|
console.log('unchanged');
|
|
```
|
|
|
|
To ignore word boundaries and replace every instance of the string, wherever it may be, specify empty strings as delimiters:
|
|
|
|
```js
|
|
export default {
|
|
...
|
|
plugins: [
|
|
replace({
|
|
changed: 'replaced',
|
|
delimiters: ['', '']
|
|
})
|
|
]
|
|
};
|
|
```
|
|
|
|
## Meta
|
|
|
|
[CONTRIBUTING](/.github/CONTRIBUTING.md)
|
|
|
|
[LICENSE (MIT)](/LICENSE)
|