2.2.0 • Published 6 years ago

rollup-plugin-replace v2.2.0

Weekly downloads
101,437
License
MIT
Repository
github
Last release
6 years ago

rollup-plugin-replace

npm.io

Replace strings in files while bundling them.

Installation

npm install --save-dev rollup-plugin-replace

Usage

Generally, you need to ensure that rollup-plugin-replace goes before other things (like rollup-plugin-commonjs) in your plugins array, so that those plugins can apply any optimisations such as dead code removal.

// rollup.config.js
import replace from 'rollup-plugin-replace';

export default {
  // ...
  plugins: [
    replace({
      ENVIRONMENT: JSON.stringify('production')
    })
  ]
};

Options

{
  // a minimatch pattern, or array of patterns, of files that
  // should be processed by this plugin (if omitted, all files
  // are included by default)...
  include: 'config.js',

  // ...and those that shouldn't, if `include` is otherwise
  // too permissive
  exclude: 'node_modules/**',

  // To replace every occurrence of `<@foo@>` instead of every
  // occurrence of `foo`, supply delimiters
  delimiters: ['<@', '@>'],

  // All other options are treated as `string: replacement`
  // replacers...
  VERSION: '1.0.0',
  ENVIRONMENT: JSON.stringify('development'),

  // or `string: (id) => replacement` functions...
  __dirname: (id) => `'${path.dirname(id)}'`,

  // ...unless you want to be careful about separating
  // values from other options, in which case you can:
  values: {
    VERSION: '1.0.0',
    ENVIRONMENT: JSON.stringify('development')
  }
}

Word boundaries

By default, values will only match if they are surrounded by word boundaries — i.e. with options like this...

{
  changed: 'replaced'
}

...and code like this...

console.log('changed');
console.log('unchanged');

...the result will be this:

console.log('replaced');
console.log('unchanged');

If that's not what you want, specify empty strings as delimiters:

{
  changed: 'replaced',
  delimiters: ['', '']
}

License

MIT

vuecomponents-testpackage@admin-bro/coremarigold-buildcf-storybooktsdx-extraadmin-bro-jznotiontheory-basic-buildnew-vue-testnew-vue-test1@deity/falcon-scriptsbnc-gulp-multiple-pagesvideo-clip-ljsrikaard1kingsun-ui-expandbussr-admin-brotakla-builder-rollupfather-build-mbptestgulp-pipeline@optic-builder/bundler-cli@everything-registry/sub-chunk-2681kn-ui-submodulescherry-designmolecula-uiesm-dep-bundlerbox-testasdasdadtan_decisivesvelte-ui-componentssw-admin-brosvelte-simplebartea_proxy_pool_utilstea_serv_utilswizzi-bundlerswidget_papawodax-umi-fatherwodax-umi-librarywodax-umi-toolswl-power-pluginwoahvx0vue-hi-therewebchewrist_redesignx-test-toolx_toy_runtimewicked_pietywildlife_situationwhispering_breezewhispering_breeze_teawhispering_brookwhispering_melodieswhispering_stardustwhispering_starlightwhispering_willowwhimsical_aurorawhimsical_dreamerwhimsical_glimmerwhimsical_lullabywhimsical_moonlightwhimsical_morningwhimsical_solitudewhimsical_twilightwhimsical_wandererwhimsical_whisperwhimsical_wonderlandwheelhouse-packagerxiaoyao-dbchain-nodetechnicalindicatorslightstar-componentzstarry_nightfalltech_logic_maventech_matrix_codespine_excesssupergloosweet_momentsthrillerviz-react-boilerplatevivid_rainbowvit-svisualizer-machinesvenus-scriptsvendor-generatorvue-cli-plugin-p11nvue-cli-plugin-vpluginvibrant_sunset@doctorwork/remax-cli@co0sh/admin-bro@cocoon/cocoon@colpu/reader@conglomerate/weaver@pectin/core@positron/elixir-rollupisekaijsx-bundlejsonql-params-validatorjsonnull-scriptsjoy_utils_gopinteg-scriptskiller_samplelatte_neighborlaravel-elixir-rollup-official
2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

7 years ago

2.0.0

8 years ago

1.2.1

8 years ago

1.1.1

9 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago