Skip to content
Advertisement

Vuejs 3 webpack : Problem with vue-template-compiler

I am trying to integrate vuejs 3 to an existing project which uses webpack. I read about vue-loader, so I am trying to use it.

In the official documentation I have this:

Every time a new version of vue is released, a corresponding version of vue-template-compiler is released together. The compiler’s version must be in sync with the base vue package so that vue-loader produces code that is compatible with the runtime. This means every time you upgrade vue in your project, you should upgrade vue-template-compiler to match it as well.

So, when I try to compile I get this error:

JavaScript

But when I try to install vue-template-compiler@3.0.2 I get this error:

JavaScript

How can I solve this problem?

Advertisement

Answer

To make vue 3 work fine with webpack without using vite or vue cli follow these steps :

  1. init the package.json like :
JavaScript
  1. install the last version of vue :

npm i --save vue@next vue-loader@next

  1. install also the dev dependencies that includes @vue/compiler-sfc which replaces vue-template-compiler
JavaScript
  • @vue/compiler-sfc
  • css-loader
  • file-loader
  • mini-css-extract-plugin
  • url-loader
  • vue-loader
  • webpack
  • webpack-cli
  • webpack-dev-server
  1. create or edit your webpack.config.js with following content :
JavaScript
  1. Add dev script to run your app :
JavaScript
  1. Fill the index.html with following content :
JavaScript

Finally run npm run dev the visit http://localhost:8080/

for a ready to use project try to clone this REPOSITORY which built by following the steps above.

Edit webpack-vue3

Advertisement