Use with webpack.DefinePlugin
See original GitHub issueI’m trying to inject some constants into my app at build time under a global object called config
, but no matter where I put my plugin, when I run the app I get 'config' is not defined
. What am I doing wrong? Here’s my craco.config.js
:
const webpack = require('webpack')
const reactHotReloadPlugin = require('craco-plugin-react-hot-reload')
const appConfig = require('./config')
module.exports = {
webpack: {
plugins: [
new webpack.DefinePlugin({
config: JSON.stringify(appConfig),
})
]
},
plugins: [
{ plugin: reactHotReloadPlugin }
]
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:9 (1 by maintainers)
Top Results From Across the Web
DefinePlugin | webpack
The DefinePlugin replaces variables in your code with other values or expressions at compile time. This can be useful for allowing different behavior ......
Read more >Environment Variables : Webpack config using DefinePlugin
“The DefinePlugin allows you to create global constants which can be configured at compile time.” We can use Define plugin in webpack.config ...
Read more >How to include and use DefinePlugin in webpack config?
I Have "webpack": "^4.28.4" and define in webpack config new webpack.DefinePlugin({ PRODUCTION: JSON.stringify(true), });.
Read more >webpack.DefinePlugin JavaScript and Node.js code examples
webpack. Best JavaScript code snippets using webpack.DefinePlugin(Showing top 15 results out of 909).
Read more >The hidden potential of webpack DefinePlugin
tl;dr. If you want to pass environment variables and use it within your JavaScript, you need to: Create the environment variable ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you want it to work you have to do this:
Here is the solution in case anybody wants to use it:
and here is another example I added ant design to config, it’s good if you need mix and match webpack plugins and babel plugins!