0.0.1 • Published 6 years ago

text-replace-loader v0.0.1

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

Text Replace Loader

Install

npm install --save-dev text-replace-loader

Usage

replacement.js

module.exports = {
  'dev': {
    'NAME' :'Hello, Kitty!',
    'FETCH_URL' :'http://localhost:8080/path/to/res',
  },
  'prod': {
    'NAME' :'Hello, World!',
    'FETCH_URL' :'http://prod.your-site/path/to/res',
  }
}

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.(js|jsx|css)$/,
        use: [
          {
            loader: 'text-replace-loader',
            options: {
              prefix: '__',
              replacement: require('./replacement')[process.env.NODE_ENV]
            }
          }
        ]
      }
    ]
  }
}

Opotions

NameTypeDefaultDescription
prefixString__The prefix identifier of the placeholder which will be matched.
replacementObject{}The matched data which should be key-value pairs, and the keys can not need to be prefixed.