sastan/rollup-plugin-define(opens in a new tab)
Language: TypeScript
Replace AST nodes while bundling
- stars
- 4
- watchers
- 1
- forks
- 1
- open issues
- 1
- Last updated
- 08/25/2020
Language: TypeScript
Replace AST nodes while bundling
Replace AST nodes while bundling
Using npm:
npm install rollup-plugin-define --save-devCreate a rollup.config.js configuration file and import the plugin:
import define from 'rollup-plugin-define' export default { input: 'src/index.js', output: { dir: 'output', format: 'cjs', }, plugins: [ define({ replacements: { 'process.env.NODE_ENV': '"production"', __buildDate__: () => JSON.stringify(new Date()), }, }), ], }
Then call rollup either via the CLI or the 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 have to be valid javascript
Typically, rollup-plugin-define should be placed in plugins before other plugins so that they may apply optimizations, such as dead code removal.
In addition to the properties and values specified for replacement, users may also specify the options below.
Type: String | Array[...String]
Default: null
A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.
Type: String | Array[...String]
Default: null
A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.
Two sub scripts will came in handy from time to time:
npm start test.watch: re-run tests on changenpm start test.coverage: creates a coverage report at coverage/lcov-report/index.htmlFormats all sources using prettier.
npm run formatnpm testPut all your source code including your test files here. Test files are matched using the following regexp:
src/**/__tests__/*.{js,jsx,ts,tsx}: matches every file within a __tests__ directory but not in child directoriessrc/**/*.{spec,test}.{js,jsx,ts,tsx}: matches *.test.js and *.spec.js files; some for the other extensions