Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add new rules to loaders while using VUE CLI 3.x

Tags:

In the last couple of days I have tried to refer a HTML page inside Vue-router, but no matter what I have tried, the only thing I got back is the following error:

Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.

I have already attempt many different stack responses to fix it, but most of them actually requires to add an extra rule inside webpack.config.js.

{
  test: /\.(html)$/,
  use: {
    loader: "html-loader",
    options: {
      attrs: [":data-src"]
}

However in the latest version of Vue CLI, it looks like this file is not available anymore.

The HTML page is placed in the public/static directory, so it is running fine when I access it from localhost:8080/static/home.html, but my goal is to access it as my home page (using localhost:8080/ only) .

So far I have already installed both html-loader and vue-loader and yet no sign of success.

P.S. I have tried to convert this HTML file and its complementary files (css, fonts and js) into a component, but I had no success as well.

like image 415
Joao Marco Oliveira Barros Avatar asked Jan 29 '20 03:01

Joao Marco Oliveira Barros


People also ask

Which vue command inspect and modify the config?

You can also use the vue config command to inspect or modify the global CLI config.

Does vue CLI service use webpack?

It is the standard tooling baseline for using Vue JS which provides you with the Vue CLI service which is a runtime dependency, built on Webpack with 0 configs. It has a very extensive collection of plugins you can add to your project with a line of command.

How do I add a proxy to vue?

All you need to run the API and the app on different terminals. Here is the App running on the port 8080 and all the API calls are proxying to the port 3080. If you change the port in the proxy value in the vue. config.


1 Answers

Vue CLI uses webpack-chain internally for maintaining the Webpack config, and so to configure it you need to add a vue.config.js file to your project (in place of this webpack.config.js).

And to configure the loaders you will need the following (inside the vue.config.js), of course with the html-loader package also installed:

module.exports = {

  chainWebpack: config => {
    config.module
      .rule('html')
      .test(/\.html$/)
      .use('html-loader')
      .loader('html-loader')
  }

}
like image 198
Yom T. Avatar answered Oct 01 '22 15:10

Yom T.