How to pass .env file variables to webpack config?

You can use dotenv package for this purpose. npm install dotenv –save After installing the package, add this in the top of your config: const webpack = require(‘webpack’); // only add this if you don’t have yet // replace accordingly ‘./.env’ with the path of your .env file require(‘dotenv’).config({ path: ‘./.env’ }); then in plugins … Read more

Getting “Error: `output.path` needs to be an absolute path or `/`”

As the error message says, you need to use absolute path. To get an absolute path for current directory, You can use __dirname to get the current directory and then append dist/js. So it would be something like, output: { path: __dirname + “/dist/js”, // or path: path.join(__dirname, “dist/js”), filename: “bundle.js” } Both will work … Read more

Webpack-dev-server compiles files but does not refresh or make compiled javascript available to browser

Two things were causing my problems here: module.exports = { entry: ‘./src/index.js’, output: { // For some reason, the `__dirname` was not evaluating and `/public` was // trying to write files to a `public` folder at the root of my HD. path: __dirname + ‘/public’, // Public path refers to the location from the _browser’s_ … Read more

How to make the webpack dev server run on port 80 and on 0.0.0.0 to make it publicly accessible?

Something like this worked for me. I am guessing this should work for you. Run webpack-dev using this webpack-dev-server –host 0.0.0.0 –port 80 And set this in webpack.config.js entry: [ ‘webpack-dev-server/client?http://0.0.0.0:80’, config.paths.demo ] Note If you are using hot loading, you will have to do this. Run webpack-dev using this webpack-dev-server –host 0.0.0.0 –port 80 … Read more

CORS error on request to localhost dev server from remote site

Original Answer I finally found the answer, in this RFC about CORS-RFC1918 from a Chrome-team member. To sum it up, Chrome has implemented CORS-RFC1918, which prevents public network resources from requesting private-network resources – unless the public-network resource is secure (HTTPS) and the private-network resource provides appropriate (yet-undefined) CORS headers. There’s also a Chrome flag … Read more