DEV Community

Cover image for How to setup a vue project with webpack.

How to setup a vue project with webpack.

Temi Kara on September 28, 2020

This post gives a step by step guide to setting up vue.js using webpack. You’ll need to have node installed on your computer, you’ll also need a ba...
Collapse
 
mrcod3rir profile image
mrcod3r-ir • Edited

hi
tnx for post
I have issue even use your repo when take build version
in local no page content showing and when run xampp for local server , page content loaded but not showing logo.png as well as not nav menu routing work correctly
and when click on about link see below error in console :

http://localhost/about.a1c31bf5.js net::ERR_ABORTED 404 (Not Found)
ChunkLoadError: Loading chunk 0 failed.
(error: http://localhost/about.a1c31bf5.js)

so how fix them ?

and notice that I got problem when doing tutorial but solved !
pls remind users in tutorial when installing to use special version's together :
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"

tnx

Collapse
 
lavikara profile image
Temi Kara

Yes, i will update the article. Thanks

Collapse
 
dgloriaweb profile image
dgloriaweb

Hi Temi,

Your github repo works like charm, and I laughed so hard when I read the last 'observation' bit, because I came here, because my team told me webpack is better than cli so I should use that. Maybe that observation can also go to the top of the article. <3

Thread Thread
 
lavikara profile image
Temi Kara

Aside from helping people learn how to setup with webpack, that myth is the main reason I wrote this article. A lot of people tend to push their opinion as best practice... always find out why before accepting it.

Collapse
 
dgloriaweb profile image
dgloriaweb

I think you forgot to add install in here, but I am not sure.
npm file-loader sass sass-loader css-loader style-loader postcss postcss-loader autoprefixer clean-webpack-plugin html-webpack-plugin mini-css-extract-plugin -D

Collapse
 
lavikara profile image
Temi Kara

thanks for noting this.

Collapse
 
dgloriaweb profile image
dgloriaweb • Edited

I think the webpack config code should go under module/rules?
Update: Just saw you have a repo, maybe it would be useful to put it in top of the article? So if someone lame like me gets stuck, they can just check the repo?

Collapse
 
lavikara profile image
Temi Kara

😂😂 the idea is to have people read all the way to the end.

Collapse
 
dgloriaweb profile image
dgloriaweb

why?

Collapse
 
sergioeanx profile image
SergioEanX • Edited

Hi, thanks for the post very interesting.
I tried to reproduce your workflow but using latest packages.
I had to modify:
optimization.moduleIds:"deterministic"
And
{
test: /.s?css$/,
use: [
"style-loader",
MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [autoprefixer()]
}
},
},
"sass-loader",
],
},

But even with this changes I got 4 warnings as:

warninng

Collapse
 
lavikara profile image
Temi Kara

hmmmm, i'll have to look into this

Collapse
 
dgloriaweb profile image
dgloriaweb • Edited

Hi! Got this when running server: Error: Cannot find module 'webpack-cli/bin/config-yargs'. config:

"webpack": "^5.44.0",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2"

Repo: github.com/dgloriaweb/vue-webpack-...

Update: tried to change "serve": "webpack serve" as they recommended, but there's another error:
[webpack-cli] Failed to load 'D:\Dokumentumaim\Projects\Vue\Webpack\vue-webpack-setup\webpack.config.js' config
[webpack-cli] Error: vue-loader requires @vue/compiler-sfc to be present in the dependency tree.

Upate2: I've installed npm i @vue/compiler-sfc and server is running, but gives all sorts of weird info in the CL. And in the browser I see the folder list.

Collapse
 
lavikara profile image
Temi Kara • Edited

most of the errors you'll get (if other things are done correctly), are usually due to webpack dependencies (webpack, webpack-cli, webpack-dev-server) not being compatible with each other. you'll need to use versions that are compatible with each other. running npm install would install the latest versions and this might not be compatible with each other. You can use the exert versions on the repo to avoid this problem.

Collapse
 
nilan profile image
Nilanchal

nice post

Collapse
 
ioanstoianov profile image
Ioan Stoianov

Really good post. Thanks!

Collapse
 
leonardoks16 profile image
Leonardo Kwieciński

Nice, do you know how to use it vuetify?

Collapse
 
lavikara profile image
Temi Kara

No i don't, i've actually never used vuetify.

Collapse
 
samuellealb profile image
Samuel Leal

Great post, thank you!

I'm having a problem to compile sass, thou. It´s like sass-loader isn´t working.

Had this kind of issue already?