rollup-plugin-define
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

npm size libera manifesto

rollup-plugin-define

Replace AST nodes while bundling

Install

Using npm:

npm install rollup-plugin-define --save-dev

Usage

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 change
  • npm start test.coverage: creates a coverage report at coverage/lcov-report/index.html

npm run format

Formats all sources using prettier.

Create a release

  1. Update changelog
  2. npm run format
  3. npm test
  4. git commit -a -m "chore: prepare release`
  5. npm version [<newversion> | 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 directories
  • src/**/*.{spec,test}.{js,jsx,ts,tsx}: matches *.test.js and *.spec.js files; some for the other extensions

Meta

LICENSE (MIT)

Package Sidebar

Install

npm i rollup-plugin-define

Weekly Downloads

2,578

Version

1.0.1

License

MIT

Unpacked Size

14.6 kB

Total Files

11

Last publish

Collaborators

  • sastan