how to use webpack externals for config data in react/redux app

社会主义新天地 提交于 2020-07-22 05:49:50

问题


I'd like to use a config file in a react/redux app. In this thread

How to store Configuration file and read it using React

i found a nice solution but i receive the following error when using require in my redux action file.

Module not found: Error: Cannot resolve module 'Config'


回答1:


I managed to solve it with the following webpack config:

plugins:[
    new webpack.DefinePlugin({
        'process.env':{
            'NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
        }
    }),
],
externals: {
    'Config': JSON.stringify(process.env.NODE_ENV === 'production' ? {
        api: "http://www.vitto.mt.it/eventi/api/public/"
    } : {
        api: "/react/eventi/api/public/"
    })
},

and calling it:

var Config = require('Config');

But i still have to set manually the NODE_ENV value. How can i set it using an external file?



来源:https://stackoverflow.com/questions/40790683/how-to-use-webpack-externals-for-config-data-in-react-redux-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!