Webpack
Replace loader forReplace everything in all plain text file...
Install:
$ npm i -D replace-daddy
Usage:
Hardcode
# projectconst assetsPath = '__debug__'==='true' ? `http://__localIP__:__localPORT__/foo` : `//cdn.site.com/assets/bar`;/* webpackChunkName: "__spaDirBuild__/Index" */ # webpackmoduleexports = // ... module: loaders: exclude: /node_modules/ test: /\.$/ loader: 'replace-daddy' query: multiple: search: '__debug__' replace: myConfigdebug || true //warning: use bool string in condition syntax search: '__localIP__' replace: search: '__localPORT__' replace: search: '__imagesDir__' replace: 'images/bar/foo' search: '__spaDirBuild__' replace:'assets/scripts' search: '__routerMode__' replace: 'router-split' regexMode:'ig'
Dynamic by local config file
# project # webpackmoduleexports = // ... module: loaders: test: /\.$/ loader: 'replace-daddy' query: multiple: file: path alias: '__daddy__' ### CONSTSjs like moduleexports = debug: 'dev'//there can be bool, number whatever prefix:'ax' router: split: true mode: 'hash' __daddy__: search: '__prefix__' replace:'prefix' regexMode: 'ig' search: '__debug__' replace:'debug' regexMode: 'ig' search: "__routerMode__" replace: "router.split==true": "router-split" "router.split==false": "router-common" regexMode: "ig" search: "__bootPath__" replace: "debug=='dev'": "config.dev.js" "debug=='pro'": "config.pro.js"
Advanced
tips
- lot of spa(vue,react,ng) projects(pro1,pro2,pro3) in a single webpack environment, you may need root and key to make your files unique to been replaced
# project # webpackmoduleexports = //... module: loaders: test: /\.$/ loader: 'replace-daddy' query: multiple: search: '__routerMode__' replace: 'whatever' regexMode: 'ig' root: 'vue' name: 'spafoldername' file: 'api/CONSTS.js' alias: '__daddy__'
Why this loader been created
fake & error code
if configroutersplitelse// you know why