为什么我的环境中的React.js暴露在脚本chunk.js中

huangapple go评论51阅读模式
英文:

Why my env reactjs exposed on script chunk.js

问题

以下是代码部分的翻译:

我有一个使用react-app-rewire的reactjs应用,但在构建/运行后,我发现env在main.chunk.js中被暴露出来,我期望env将被加密或混淆,而不会明确地显示为一个对象。

package.json中的脚本如下:

"scripts": {
    "start": "react-app-rewired start",
    "build": "GENERATE_SOURCEMAP='false' INLINE_RUNTIME_CHUNK='false' react-app-rewired build",
    "test": "react-app-rewired test",
    "analyze": "source-map-explorer 'build/static/js/*.js'",
    "eject": "react-scripts eject",
    "prod": "yarn run build && serve build",
    "lint": "eslint \"./**/*.{js,jsx}\"",
    "lint:fix": "npm run lint -- --fix",
    "format": "prettier --write \"**/*.+(js|jsx|json|css|md)\"",
    "prepare": "husky install",
    "doc": "jsdoc -c jsdoc.json"
  }

如何修复这个问题?

英文:

I have reactjs app using react-app-rewire but after im build / running i saw that env was exposed on main.chunk.js, im expected that env will be encrypted or obfuscated not clearly saw as an object

this script on package.json

"scripts": {
    "start": "react-app-rewired start",
    "build": "GENERATE_SOURCEMAP='false' INLINE_RUNTIME_CHUNK='false' react-app-rewired build",
    "test": "react-app-rewired test",
    "analyze": "source-map-explorer 'build/static/js/*.js'",
    "eject": "react-scripts eject",
    "prod": "yarn run build && serve build",
    "lint": "eslint \"./**/*.{js,jsx}\"",
    "lint:fix": "npm run lint -- --fix",
    "format": "prettier --write \"**/*.+(js|jsx|json|css|md)\"",
    "prepare": "husky install",
    "doc": "jsdoc -c jsdoc.json"
  },

为什么我的环境中的React.js暴露在脚本chunk.js中

How to fix this ?

答案1

得分: 2

环境变量始终在 DOM 中可用。React 应用程序是单页面的,所有内容都最终在用户的浏览器中加载。文档建议不要在 React 应用程序中存储机密信息。

https://create-react-app.dev/docs/adding-custom-environment-variables/

英文:

The environment variables are always going to be available in the DOM. React applications are single page and everything ends up in the users browser. The docs say not to store secrets in a react app.

https://create-react-app.dev/docs/adding-custom-environment-variables/

huangapple
  • 本文由 发表于 2023年4月10日 23:11:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75978286.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定