[英]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.