I can't understand why vue cli is injecting js and css files twice. One time inside head with rel="preload" and one time inside body without the rel attribute.

I tried to find what option I need to add to vue.config.js in order to solve this issue, but couldn't find any.

My package.json:

{
  "name": "somename",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "@babel/polyfill": "^7.4.3",
    "axios": "^0.18.0",
    "axios-rest-client": "^0.1.11",
    "simplebar-vue": "^1.0.0-alpha.6",
    "vue": "^2.6.10",
    "vue-js-modal": "^1.3.28",
    "vue-meta": "^1.6.0",
    "vue-router": "^3.0.6",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.6.0",
    "@vue/cli-plugin-eslint": "^3.6.0",
    "@vue/cli-service": "^3.6.0",
    "babel-eslint": "^10.0.1",
    "eslint": "^5.16.0",
    "eslint-plugin-vue": "^5.0.0",
    "sass": "^1.18.0",
    "sass-loader": "^7.1.0",
    "svg-to-vue-component": "^0.3.8",
    "vue-template-compiler": "^2.6.10"
  }
}

My vue.config.js:

module.exports = {
  assetsDir: "./static/",
  productionSourceMap: false,
  chainWebpack: config => {
    // Only convert .svg files that are imported by these files as Vue component
    const FILE_RE = /\.(vue|js|ts|svg)$/;

    // Use vue-cli's default rule for svg in non .vue .js .ts files
    config.module.rule("svg").issuer(file => !FILE_RE.test(file));

    // Use our loader to handle svg imported by other files
    config.module
      .rule("svg-component")
      .test(/\.svg$/)
      .issuer(file => FILE_RE.test(file))
      .use("vue")
      .loader("vue-loader")
      .end()
      .use("svg-to-vue-component")
      .loader("svg-to-vue-component/loader");
  },
};

Rendered HTML after npm run build:

<!DOCTYPE html>
<html lang=en>

<head>
    ...
    ...
    ...
    ...
    <link href=/static/css/app.0236e035.css rel=preload as=style>
    <link href=/static/css/chunk-vendors.a1440aaa.css rel=preload as=style>
    <link href=/static/js/app.e0f054b2.js rel=preload as=script>
    <link href=/static/js/chunk-vendors.85520ed9.js rel=preload as=script>
    <link href=/static/css/chunk-vendors.a1440aaa.css rel=stylesheet>
    <link href=/static/css/app.0236e035.css rel=stylesheet>
</head>

<body>
    <noscript><strong>We're sorry but somename doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript>
    <div id=app></div>
    <script src=/static/js/chunk-vendors.85520ed9.js></script>
    <script src=/static/js/app.e0f054b2.js></script>
</body>

</html>

I would like to know how to fix it to be injected only once, or maybe it is like this because of the preload?

0 Answers