Webpack 4 Tutorial 13: Webpack dev server

Webpack 4 Tutorial 13: Webpack dev server

Mehul - Codedamn

5 лет назад

11,775 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Yash Chauhan
Yash Chauhan - 02.06.2023 13:03

why u added <script src="/assets/main.js"></script>
??? wont web pack add this on its own ?

Ответить
Coding Successfully
Coding Successfully - 19.02.2023 15:56

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',
},

Ответить
mohit mohlia
mohit mohlia - 28.07.2022 11:18

if your terminal is throwing error for "contentBase" unknown property. Just replace it with "static"

Ответить
Richard Cross
Richard Cross - 11.12.2020 13:40

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.

Ответить
Soft As In Software
Soft As In Software - 28.11.2020 19:54

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

Ответить
Jay Sinha
Jay Sinha - 17.08.2020 00:24

quick question : Where is /assets/ folder

Ответить
Cesar Castro Aroche
Cesar Castro Aroche - 03.03.2020 15:29

this is so cool !!!

Ответить
Sage Bias
Sage Bias - 17.11.2019 23:09

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.

Ответить