0.1.1 • Published 4 years ago

rollup-plugin-variables v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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.

0.1.1

4 years ago

0.1.0

4 years ago