I've finally got the he dev server running and I get something on screen. I've setup a "start" script for NPM like this:
"start": "webpack-dev-server --content-base app"
I get an error:
http://localhost:8080/bundle.js Failed to load resource: the server responded with a status of 404 (Not Found)
My folders are set as follows:
appDir
->app
->node_modules
webpack.config.js
package.json
My webpack.config.js:
module.exports = {
context: __dirname + '/app',
entry: './index.js',
output: {
path: __dirname + '/app',
filename: './bundle.js'
}
}
Can you tell what's wrong?
You can bundle your JavaScript using the CLI command by providing an entry file and output path. Webpack will automatically resolve all dependencies from import and require and bundle them into a single output together with your app's script.
Webpack is an aggressive and powerful module bundler for JavaScript applications. It packages all the modules in your application into one or more bundles (often, just one) and serves it to the browser.
Out of the box, webpack won't require you to use a configuration file. However, it will assume the entry point of your project is src/index.js and will output the result in dist/main.js minified and optimized for production.
js in the console! This means Webpack has successfully bundled both our logic from src/index. js and HTML from src/index. html into the dist directory, even automatically linking them together for us.
bundle.js is located inside your /app
directory. That path
option in output specifies the absolute path that the file goes.
Also you don't need the ./
in filename. It will get resolved relatively to output.path
but it is confusing and may have contributed to your problem.
The problem mostly with pointing bundle js in index.html. The reason webpack bundle.js is not found because you need to specify absolute path in index.html. Say suppose your bundle.js and index.html is generated under dist folder, then it should be something like below.
<script src="/bundle.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With