简体   繁体   中英

Very slow hot reloading after font-awesome has been added to Vue.js as a component

I recently have started project for fun in Vue.js because this framework seems to be fun to work with. I have decided to add https://github.com/FortAwesome/vue-fontawesome component. Unfortunately after use it in one of my Vue components:

<template>
  <div class="success-box-wrapper">
    <div class="box">
      <div class="box-header">
        <span class="close">x</span>
      </div>
      <div class="box-body">

      </div>
      <div class="box-footer">
        <div class="checkmark-circle">
          <div class="background"></div>
          <font-awesome-icon fa :icon="faCheck"/>
          <div></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { faCheck } from '@fortawesome/free-solid-svg-icons';

export default {
  name: 'SuccessBox',
  data() {
    return {
      isOpen: false,
      faCheck,
    };
  },
};
</script>

<style>
</style>

Webpack seem to build project very slow. DONE Compiled successfully in 54369ms10:04:26 AM Not just after adding <font-awesome-icon fa:icon="faCheck"/> but after any change. I tried to eject webpack outside Vue but nothing seem to work well. Maybe i shouldn't use font-awesoma as a component? maybe i should use in a "old" way by inserting CDN href?

node_1  |  WAIT  Compiling...10:03:32 AM
node_1  |
node_1  | <s> [webpack.Progress] 0% compiling
node_1  | <s> [webpack.Progress] 10% building 0/0 modules 0 active
node_1  | <s> [webpack.Progress] 10% building 0/0 modules 0 active
node_1  | <s> [webpack.Progress] 40% building 0/0 modules 0 active
node_1  | <s> [webpack.Progress] 40% building 0/1 modules 1 active /usr/src/app/node_modules/cache-loader/dist/cjs.js??ref--0-0!/usr/src/app/node_modules/vue-loader/lib/index.js??vue-loader-options!/usr/src/app/node_modules/eslint-loader/index.js??ref--13-0!/usr/sr
c/app/src/components/SuccessBox.vue
node_1  | <s> [webpack.Progress] 70% building 1/1 modules 0 active
node_1  | <s> [webpack.Progress] 40% building 1/2 modules 1 active /usr/src/app/node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"593dd390-vue-loader-template"}!/usr/src/app/node_modules/vue-loader/lib/loade
rs/templateLoader.js??vue-loader-options!/usr/src/app/node_modules/cache-loader/dist/cjs.js??ref--0-0!/usr/src/app/node_modules/vue-loader/lib/index.js??vue-loader-options!/usr/src/app/src/components/SuccessBox.vue?vue&type=template&id=6d8cce10&scoped=true&
node_1  | <s> [webpack.Progress] 40% building 1/3 modules 2 active /usr/src/app/node_modules/cache-loader/dist/cjs.js??ref--12-0!/usr/src/app/node_modules/babel-loader/lib/index.js!/usr/src/app/node_modules/cache-loader/dist/cjs.js??ref--0-0!/usr/src/app/node_modul
es/vue-loader/lib/index.js??vue-loader-options!/usr/src/app/src/components/SuccessBox.vue?vue&type=script&lang=js&
node_1  | <s> [webpack.Progress] 40% building 1/4 modules 3 active /usr/src/app/node_modules/css-loader/index.js??ref--8-oneOf-1-1!/usr/src/app/node_modules/vue-loader/lib/loaders/stylePostLoader.js!/usr/src/app/node_modules/postcss-loader/src/index.js??ref--8-oneO
f-1-2!/usr/src/app/node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-1-3!/usr/src/app/node_modules/cache-loader/dist/cjs.js??ref--0-0!/usr/src/app/node_modules/vue-loader/lib/index.js??vue-loader-options!/usr/src/app/src/components/SuccessBox.vue?vue&type=style&in
dex=0&id=6d8cce10&lang=scss&scoped=true&
node_1  | <s> [webpack.Progress] 40% building 2/4 modules 2 active /usr/src/app/node_modules/css-loader/index.js??ref--8-oneOf-1-1!/usr/src/app/node_modules/vue-loader/lib/loaders/stylePostLoader.js!/usr/src/app/node_modules/postcss-loader/src/index.js??ref--8-oneO
f-1-2!/usr/src/app/node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-1-3!/usr/src/app/node_modules/cache-loader/dist/cjs.js??ref--0-0!/usr/src/app/node_modules/vue-loader/lib/index.js??vue-loader-options!/usr/src/app/src/components/SuccessBox.vue?vue&type=style&in
dex=0&id=6d8cce10&lang=scss&scoped=true&
node_1  | <s> [webpack.Progress] 54% building 3/4 modules 1 active /usr/src/app/node_modules/css-loader/index.js??ref--8-oneOf-1-1!/usr/src/app/node_modules/vue-loader/lib/loaders/stylePostLoader.js!/usr/src/app/node_modules/postcss-loader/src/index.js??ref--8-oneO
f-1-2!/usr/src/app/node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-1-3!/usr/src/app/node_modules/cache-loader/dist/cjs.js??ref--0-0!/usr/src/app/node_modules/vue-loader/lib/index.js??vue-loader-options!/usr/src/app/src/components/SuccessBox.vue?vue&type=style&in
dex=0&id=6d8cce10&lang=scss&scoped=true&
node_1  | <s> [webpack.Progress] 70% building 4/4 modules 0 active
node_1  | <s> [webpack.Progress] 70% building 4/4 modules 0 active
node_1  | <s> [webpack.Progress] 70% finish module graph
node_1  | <s> [webpack.Progress] 70% finish module graph FlagDependencyExportsPlugin
node_1  | <s> [webpack.Progress] 70% sealing
node_1  | <s> [webpack.Progress] 70% sealing WarnCaseSensitiveModulesPlugin
node_1  | <s> [webpack.Progress] 72% basic dependencies optimization
node_1  | <s> [webpack.Progress] 72% dependencies optimization
node_1  | <s> [webpack.Progress] 73% advanced dependencies optimization
node_1  | <s> [webpack.Progress] 73% after dependencies optimization
node_1  | <s> [webpack.Progress] 71% chunk graph
node_1  | <s> [webpack.Progress] 71% after chunk graph
node_1  | <s> [webpack.Progress] 71% after chunk graph WebAssemblyModulesPlugin
node_1  | <s> [webpack.Progress] 74% optimizing
node_1  | <s> [webpack.Progress] 74% basic module optimization
node_1  | <s> [webpack.Progress] 75% module optimization
node_1  | <s> [webpack.Progress] 75% advanced module optimization
node_1  | <s> [webpack.Progress] 76% after module optimization
node_1  | <s> [webpack.Progress] 76% basic chunk optimization
node_1  | <s> [webpack.Progress] 76% basic chunk optimization EnsureChunkConditionsPlugin
node_1  | <s> [webpack.Progress] 76% basic chunk optimization RemoveEmptyChunksPlugin
node_1  | <s> [webpack.Progress] 76% basic chunk optimization MergeDuplicateChunksPlugin
node_1  | <s> [webpack.Progress] 77% chunk optimization
node_1  | <s> [webpack.Progress] 77% advanced chunk optimization
node_1  | <s> [webpack.Progress] 77% advanced chunk optimization SplitChunksPlugin
node_1  | <s> [webpack.Progress] 77% advanced chunk optimization RemoveEmptyChunksPlugin
node_1  | <s> [webpack.Progress] 77% after chunk optimization
node_1  | <s> [webpack.Progress] 78% module and chunk tree optimization
node_1  | <s> [webpack.Progress] 78% after module and chunk tree optimization
node_1  | <s> [webpack.Progress] 79% basic chunk modules optimization
node_1  | <s> [webpack.Progress] 80% chunk modules optimization
node_1  | <s> [webpack.Progress] 80% advanced chunk modules optimization
node_1  | <s> [webpack.Progress] 81% after chunk modules optimization
node_1  | <s> [webpack.Progress] 81% module reviving
node_1  | <s> [webpack.Progress] 81% module reviving RecordIdsPlugin
node_1  | <s> [webpack.Progress] 82% module order optimization
node_1  | <s> [webpack.Progress] 82% advanced module order optimization
node_1  | <s> [webpack.Progress] 83% before module ids
node_1  | <s> [webpack.Progress] 83% before module ids NamedModulesPlugin
node_1  | <s> [webpack.Progress] 83% module ids
node_1  | <s> [webpack.Progress] 84% module id optimization
node_1  | <s> [webpack.Progress] 84% module id optimization
node_1  | <s> [webpack.Progress] 85% chunk reviving
node_1  | <s> [webpack.Progress] 85% chunk reviving RecordIdsPlugin
node_1  | <s> [webpack.Progress] 85% chunk order optimization
node_1  | <s> [webpack.Progress] 85% chunk order optimization OccurrenceOrderChunkIdsPlugin
node_1  | <s> [webpack.Progress] 86% before chunk ids
node_1  | <s> [webpack.Progress] 86% before chunk ids NamedChunksPlugin
node_1  | <s> [webpack.Progress] 86% chunk id optimization
node_1  | <s> [webpack.Progress] 87% after chunk id optimization
node_1  | <s> [webpack.Progress] 87% record modules
node_1  | <s> [webpack.Progress] 87% record modules RecordIdsPlugin
node_1  | <s> [webpack.Progress] 87% record chunks
node_1  | <s> [webpack.Progress] 87% record chunks RecordIdsPlugin
node_1  | <s> [webpack.Progress] 88% hashing
node_1  | <s> [webpack.Progress] 88% after hashing
node_1  | <s> [webpack.Progress] 88% after hashing HotModuleReplacementPlugin
node_1  | <s> [webpack.Progress] 89% record hash
node_1  | <s> [webpack.Progress] 89% module assets processing
node_1  | <s> [webpack.Progress] 90% chunk assets processing
node_1  | <s> [webpack.Progress] 90% additional chunk assets processing
node_1  | <s> [webpack.Progress] 90% additional chunk assets processing HotModuleReplacementPlugin
node_1  | <s> [webpack.Progress] 91% recording
node_1  | <s> [webpack.Progress] 91% recording HotModuleReplacementPlugin
node_1  | <s> [webpack.Progress] 92% additional asset processing
node_1  | <s> [webpack.Progress] 92% chunk asset optimization
node_1  | <s> [webpack.Progress] 93% after chunk asset optimization
node_1  | <s> [webpack.Progress] 93% asset optimization
node_1  | <s> [webpack.Progress] 94% after asset optimization
node_1  | <s> [webpack.Progress] 94% after seal
node_1  | <s> [webpack.Progress] 95% emitting
node_1  | <s> [webpack.Progress] 95% emitting HtmlWebpackPlugin
node_1  | <s> [webpack.Progress] 95% emitting CopyPlugin
node_1  | <s> [webpack.Progress] 98% after emitting
node_1  | <s> [webpack.Progress] 98% after emitting CopyPlugin
node_1  |  DONE  Compiled successfully in 54369ms10:04:26 AM
node_1  |
node_1  | <s> [webpack.Progress] 100%
node_1  |
node_1  |
node_1  |   App running at:
node_1  |   - Local:   http://localhost:8080/
node_1  |
node_1  |   It seems you are running Vue CLI inside a container.
node_1  |   Access the dev server via http://localhost:<your container's external mapped port>/

EDIT WORKAROUND-LIKE SOLUTION:

Previously i ran yarn serve inside docker container. It cause very long hot reload. When i run it directly inside Windows it compiles in 500 ms . I leave it as unresolved question because i still don't know why it is so slow on Docker.

Having just had a nightmare couple of days with this issue, I think I may have found a fix for it.

Firstly, for me, it wasn't after adding any particular package via yarn/npm. Also, I'm having to use Windows as a host OS with Linux containers.

I started a new project with vue-cli, everything was working fine, after dockerizing it, the HMR was just unusably slow.

There seems to be 2 main aspects at play here, the port being used and also the node_modules/ build time.

Fixing either one didn't help me very much but fixing both have HMR very close to running natively again.

So these were the things I added to fix:

docker-compose.yml

version: '3.7'

services:

  front-end:
    container_name: my-front-end
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - '.:/app'
      - '/app/node_modules' # <---- this enables a much faster start/reload
    ports:
      # default port does work but slow without mounting node_modules (above)
      # - '8080:8080'
      # for some reason HMR breaks completely when not using the same port as the container.
      # - '8007:8080'
      # - '8006:8007'
      # port 8007 set up in vue.config
      - '8007:8007'
    #   this is now also done in the vue.config
    # environment: 
      # - CHOKIDAR_USEPOLLING=true

vue.config.js

module.exports = {
    devServer: {
        public: "localhost:8007",
        port: 8007,
        disableHostCheck: true,
        watchOptions: {
            ignored: /node_modules/,
            aggregateTimeout: 300,
            poll: 300,
        },
    },
};

I hope this helps somebody.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM