一覧へ戻る
anireact/rollup-plugin-override(新しいタブで開きます)
主要言語: TypeScript
Robust compile-time expression substitution.
- star 数
- 1
- watcher 数
- 2
- fork 数
- 0
- issue 数
- 0
- 最終更新
- 2023/10/12
主要言語: TypeScript
Robust compile-time expression substitution.
Compile-time expression substitution. Similar to
@rollup/plugin-replace, but robust and safe.
yarn add -D @anireact/rollup-plugin-override
npm install --save-dev @anireact/rollup-plugin-override
import override from '@anireact/rollup-plugin-override'; export default { plugins: [ override({ mappings: { 'process.env.NODE_ENV': `'production'`, 'OPT_LEVEL': `3`, 'BUILD_ID': JSON.stringify(uuid()), }, }), ], };
include, exclude — filter patterns to limit files the plugin processes.ignoreScope (default: false) — force enable replacement processing even
in scopes that have bindings, shadowing the expression to be rewritten.mappings — a record of key-value mappings; values must be strings
containing valid JavaScript expressions.Unlike the official @rollup/plugin-replace, this plugin is more robust in edge
cases:
Doesn’t care of the exact code formatting:
assert(process.env.NODE_ENV === 'production'); assert(process.env['NODE_ENV'] === 'production'); assert(process['env'][`NODE_ENV`] === 'production'); assert( process .env .NODE_ENV === 'production' );
Doesn’t rewrite binding names, assignment LHS expressions, etc.:
process.env.NODE_ENV = 'production'; // ↑ writing the real env variable import { BUILD_ID } from '#constants'; const { BUILD_ID } = whatever; const f = BUILD_ID => g(); class App { BUILD_ID; OPT_LEVEL() {} }
Respects the scope:
const f = BUILD_ID => g(BUILD_ID); // ↑ “global” `BUILD_ID` is shadowed // by the function parameter, // so it will not be rewritten import process from 'node:process'; console.log(process.env.NODE_ENV); // ↑ reading the real env variable
Because it has an easy to use all-in-one API.
If you have any issues, feel free to fork this plugin, or contact me on Telegram https://t.me/miyaokamarina.
MIT © 2023 Yuri Zemskov