rollup-plugin-variables

0.1.1 • Public • Published

Rollup Plugin Variables

Rollup plugin for parse variables

npm version License: MIT Build Status

Install

npm install rollup-plugin-variables

or

yarn add rollup-plugin-variables

Usage

env.js

module.exports = () => {
  return {
    URL: 'http://www.example.com'
  };
};

rollup.config.js

import variables from 'rollup-plugin-variables';
 
export default {
  plugins: [variables()]
};

How will the result be?

before in Link.jsx

import React from 'react';
 
const LinkComponent = () => <a href="[[URL]]">Link</a>;
 
export default LinkComponent;

after in Link.jsx

import React from 'react';
 
const LinkComponent = () => <a href="http://www.example.com">Link</a>;
 
export default LinkComponent;

Options

fileName

Type String|Function Default: env.js

rollup.config.js

String

export default {
  plugins: [variables({ fileName: 'environments.js' })]
};

Function

export default {
  plugins: [
    variables({
      fileName: () => {
        if (process.env.NODE_ENV === 'development') {
          return 'environments.test.js';
        }
 
        return 'environments.js';
      }
    })
  ]
};

format

Type String<js,json,txt>|Function<js,json,env> Default: js

rollup.config.js

String

export default {
  plugins: [variables({ format: 'js' })]
};

Function

export default {
  plugins: [
    variables({
      format: () => {
        if (process.env.NODE_ENV === 'development') {
          return 'json';
        }
 
        return 'js';
      }
    })
  ]
};

marker

Type String|Function|Array Default: [[]]

rollup.config.js

String

export default {
  plugins: [variables({ marker: '{{}}' })]
};

Function

export default {
  plugins: [
    variables({
      marker: () => {
        if (process.env.NODE_ENV === 'development') {
          return '{{}}';
        }
 
        return '[[]]';
      }
    })
  ]
};

NPM Statistics

Download stats for this NPM package

NPM

License

Rollup Plugin Variables is open source software licensed as MIT.

Readme

Keywords

Package Sidebar

Install

npm i rollup-plugin-variables

Weekly Downloads

13

Version

0.1.1

License

MIT

Unpacked Size

7.84 kB

Total Files

9

Last publish

Collaborators

  • andrelmlins