简体   繁体   English

什么是webpack.DefinePlugin的create-react-app的好选择?

[英]What is a good alternative to webpack.DefinePlugin for create-react-app?

I'm working on an ejected React application that uses webpack.DefinePlugin to store globally an object defining the folder names in the application for a specific path (kind of an ls in shell but using node fs) 我正在使用webpack.DefinePlugin弹出的React应用程序上工作,以全局存储一个对象,该对象定义了应用程序中特定路径的文件夹名称(在外壳中为ls,但使用节点fs)

I'm researching how to go back to the original create-react-app without loosing this functionality as some parts of the app relies on this, but I can't find anything other than a script that writes these names into a variable in js file prior to the commands npm start or npm run build. 我正在研究如何回到原始的create-react-app而不丧失此功能,因为该应用的某些部分依赖于此,但是除了将这些名称写到js中的变量的脚本之外,我找不到其他任何东西命令npm start或npm run build之前的文件。

The project is currently using Webpack 3 and Babel 6, the idea behind going back to react-scripts is get rid of the manual maintenance and simplify the project dependencies while upgrading the project 该项目当前使用的是Webpack 3和Babel 6,返回到react-scripts背后的想法是摆脱了手动维护并简化了项目依赖性,同时升级了项目

// analysis.js
module.exports = {
  key: values from fs node package
};



// WEBPACK
    new webpack.DefinePlugin({
      "ANALYSIS": JSON.stringify(require('./analysis')),
    }),

I expect the same values to be available in the application without needing to eject react-scripts 我希望在应用程序中可以使用相同的值,而无需弹出react-scripts

Any suggestions? 有什么建议么? Thanks! 谢谢!

I finally chose to develop a script that runs before any webpack script and creates the file that I import later like any other file inside the React app 我最终选择开发一个在任何webpack脚本之前运行的脚本,并创建稍后导入的文件,就像React应用程序中的其他任何文件一样

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在 webpack.DefinePlugin 中定义的变量未定义 - variables I defined in webpack.DefinePlugin is undefined create-react-app 和 svgr 的 webpack 错误 - webpack errors with create-react-app & svgr 有没有办法在不弹出的情况下为 create-react-app 更改 webpack 的 eslint - Is there a way to change the eslint of the webpack for the create-react-app without ejecting create-react-app webpack 配置和文件在哪里? - where is create-react-app webpack config and files? 我应该使用 webpack 还是 create-react-app? - Should i use webpack or create-react-app? Webpack 错误将故事书添加到 create-react-app - Webpack error adding storybook to create-react-app 将 webpack 4 更新为 webpack 5 在现有的 create-react-app 上用 react-app-rewired 弹出 - Update webpack 4 to webpack 5 on an existing create-react-app ejected with react-app-rewired 环境变量在电子中未定义,即使它已在 webpack.DefinePlugin 中设置 - Environment variable is undefined in electron even it has been set inside webpack.DefinePlugin Vue.js:使用webpack.DefinePlugin()时出现“无效或意外令牌” - Vue.js : “Invalid or unexpected token” when using webpack.DefinePlugin() 使用 create-react-app 和 webpack dev server 将来自客户端反应应用程序的请求代理到服务器 - Proxying requests from client react app to server with create-react-app and webpack dev server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM