GithubHelp home page GithubHelp logo

string-replace-loader's Introduction

@miwa/string-replace-loader

一个webpack loader插件,根据配置文件直接替换常量文本,避免多次import常量文件,减少main.js的大小,方便常量统一管理以及区分环境使用不同的常量。

Params

  • changeTemp 文本配置文件
  • changeRules 匹配替换的规则

UsageDemo

把用‘<{}>’包裹起来的字段在一个类似~/constConfig.js的文件中进行匹配,替换文本中的value。

配置

npm i @miwa/string-transtion-loader --save-dev

webpack.config.js

{
  test: /\.(js|jsx)$/,
  use: [
    {
      {
        loader: '@miwa/string-loader-loader',
        options: {
          changeTemp: require('~/constConfig.js'),   // 所在的配置文件
          changeRules: /\<\{(.+?)\}\>/g        //全局匹配的正则表达式
        }
      }
    }
  ]
}

~/constConfig.js

module.exports = {
  LOGINURL: '/data/login.do',
}

使用的文件

let url = '<{LOGINURL}>'

编译后的文件

let url = '/data/login.do'

string-replace-loader's People

Contributors

minhuaf avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.