1

I have a file structure as below:

Project
 |
 +-- src/
 |   |
 |   +-- index.js
 |
 +-- index.html
 |
 +-- webpack.config.js

src/index.js:

document.write("Hello World.");

index.html:

 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>webpack learning</title>

    <script src="builds/bundle.js"></script>
</head>
<body>

</body>
</html>

webpack.config.js:

var path = require('path');

module.exports = {
  entry: './src',
  output: {
    path: path.join(__dirname, 'builds'),
    filename: 'bundle.js',
  }
};

When I run webpack-dev-server in the Project directory, webpack-dev-server starts normally and prints "webpack: bundle is now VALID." However, when I launch a browser and go to localhost:8080, the console complains that bundle.js is not found. Indeed, there is no such folder named "build" with bundle.js in it. But, isn't webpack-dev-server generating bundle.js in memory? Any configuration problems involved?

1 Answer 1

2

It would help to see the command you are running, however if I had to take a guess at this one I would say you may not be setting --content-base https://webpack.js.org/configuration/dev-server/#devserver-contentbase

Sign up to request clarification or add additional context in comments.

2 Comments

And it would also be useful to explicitly declare output.publicPath.
When I add output.publicPath and set it to "builds", everything works just fine. It seems that when webpack-dev-server is generating bundle.js in memory, it puts that file in the directory specified by output.publicPath and ignores what directory the "output.path" is set to. Because whatever output.path is set to, as long as output.publicPath remains "builds", no error appears in the console and the browser renders "Hello World."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.