rollup-plugin-define v1.0.1
rollup-plugin-define
Replace AST nodes while bundling
Install
Using npm:
npm install rollup-plugin-define --save-devUsage
Create 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.
Options
In addition to the properties and values specified for replacement, users may also specify the options below.
exclude
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.
include
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.
Available Scripts
npm test
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 atcoverage/lcov-report/index.html
npm run format
Formats all sources using prettier.
Create a release
- Update changelog
npm run formatnpm test- git commit -a -m "chore: prepare release`
- npm version [\ | major | minor | patch] -m "chore: release"
Folder Structure
src/
Put 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.jsand*.spec.jsfiles; some for the other extensions