Gathering detailed insights and metrics for params-replace-loader
Gathering detailed insights and metrics for params-replace-loader
Gathering detailed insights and metrics for params-replace-loader
Gathering detailed insights and metrics for params-replace-loader
npm install params-replace-loader
Typescript
Module System
Node Version
NPM Version
69.1
Supply Chain
98.7
Quality
75.7
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
18 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Mar 24, 2023
Latest Version
1.1.8
Package Id
params-replace-loader@1.1.8
Unpacked Size
10.59 kB
Size
4.13 kB
File Count
13
NPM Version
8.3.1
Node Version
17.4.0
Published on
Mar 24, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
1
用于项目环境变量批量自动替换的webpack-loader。
根据当前的webpack执行环境(或者也称 当前node 命令执行环境), 自动将项目源代码中的指定变量替换对应的项目参数值。 其中源代码包括js、css、vue、html等文件,当然也可以自行设置需要替换的项目源文件, 注意事项:需要提前设置源代码中需要替换的参数值
1$ npm install --save-dev params-replace-loader
或者:
1$ yarn add params-replace-loader --dev
1$ node ./test/demo.js --env=test
注:以上命令通过--env告知params-replace-loader,当前的执行环境是 test.
1 "scripts": { 2 "test": "node ./test/demo.js --env=online" 3 }
注:以上命令通过--env告知params-replace-loader,当前的执行环境是 online.
1 envParams: { // 项目系统环境变量 2 common: { // 通用参数 3 '#version#': '20191121.1', 4 ... 5 }, 6 local: { // 本地开发环境 7 '#dataApiBase#': 'http://localhost', 8 '#assetsPublicPath#': 'http://localhost', 9 '#routeBasePath#': '/', 10 ... 11 }, 12 test: { // 线上测试环境配置参数 13 '#dataApiBase#': '//goodtool666.cn/', 14 '#assetsPublicPath#': '//goodtool666.cn/_test/_spa/sportNews', // 静态资源引用路径 15 '#routeBasePath#': '/_test/_spa/sportNews/', // 路由根地址 16 ... 17 }, 18 online: { // 线上正式环境配置参数 19 '#dataApiBase#': '//goodtool666.cn/', 20 '#assetsPublicPath#': '//goodtool666.cn/_spa/sportNews', 21 '#routeBasePath#': '/_spa/sportNews/', 22 ... 23 }, 24 ... 25 }
注:以上envParams放在projectConfig中。
注:如果只是将params-replace-loader当webpack-loader使用,无需自己引用(安装后即可直接使用)
1 // 导入params-replace-loader 2 const paramsReplaceAction = require('params-replace-loader'); 3 4 // 导入params-replace-loader的主功能模块,不以webpack-loader的方式使用 5 const paramsReplaceAction = require('params-replace-loader/lib/mainAction'); 6 7 // params-replace-loader提供的方法:获取当前执行环境的所有配置数据 8 const currentConfig = paramsReplaceAction.getCurrentEnvParams(projectConfig.envParams); 9 10 // params-replace-loader提供的方法:获取当前执行环境 11 const currentConfig = paramsReplaceAction.getCurrentEnv(); 12
配置 你的webpack.config.js
:
1module.exports = { 2 // ... 3 module: { 4 rules: [ 5 { 6 test: /\.(js|vue|css|html)$/, 7 loader: 'params-replace-loader', 8 options: projectConfig.envParams 9 } 10 ] 11 } 12}
或者:
1module.exports = { 2 // ... 3 module: { 4 rules: [ 5 { 6 test: /\.(js|vue|css|html)$/, 7 loader: 'params-replace-loader', 8 options: { 9 common: { 10 '#version#': '20191121.1', 11 }, 12 local: { 13 '#assetsPublicPath#': 'http://localhost', 14 '#routeBasePath#': '/', 15 ... 16 }, 17 online: { 18 '#assetsPublicPath#': '//goodtool666.cn/_spa/sportNews', 19 '#routeBasePath#': '/_spa/sportNews/', 20 }, 21 ... 22 } 23 } 24 ] 25 } 26}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 0/18 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More