Комментарии:
why u added <script src="/assets/main.js"></script>
??? wont web pack add this on its own ?
Thank you for this content!
I also got the error for "contentBase" and the way how it was fixed was by adding this line instead of contentBase:
Instead of:
devServer: {
port: 1234,
contentBase: path.join(__dirname, "dist")
},
I did this and it worked perfectly:
devServer: {
port: 1234,
static: './dist',
},
if your terminal is throwing error for "contentBase" unknown property. Just replace it with "static"
ОтветитьCopied this word for word. Didn't work! 'Could not find webpack-dev-server.js in node_modules', even though I checked and it's definitely there. very strange.
ОтветитьApparently with the latest version of webpack-cli (4.2.0) running dev is a little bit different:
change "dev" "webpack serve" in package.json:
"scripts": {
"dev": "webpack serve",
"build": "rm -rf build && webpack"
}
optionally add the open section in webpack.config.js to automagically load the webpage:
devServer: {
port: 1234,
contentBase: path.join(__dirname, 'dist'),
open: {
app: ['Chrome', '--incognito']
}
}
The above works for:
"path": "^0.12.7",
"webpack": "^5.8.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"
Enjoy,
Maarten
quick question : Where is /assets/ folder
Ответитьthis is so cool !!!
ОтветитьI'm implementing webpack for my company and am over my head. Is the dev server good to use for a medium company?
I am currently using the proxy server to send ajax to the backend. But I suspect that this won't work on the production server due to differing ports and such. How do you handle this on a larger scale.