簡體   English   中英

將 font-awesome 作為組件添加到 Vue.js 后,熱重載非常慢

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

我最近在 Vue.js 中開始了有趣的項目,因為這個框架看起來很有趣。 我決定添加https://github.com/FortAwesome/vue-fontawesome組件。 不幸的是,在我的一個 Vue 組件中使用它之后:

<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 似乎構建項目很慢。 DONE Compiled successfully in 54369ms10:04:26 AM不僅僅是在添加<font-awesome-icon fa:icon="faCheck"/>之后,而是在任何更改之后。 我試圖在 Vue 之外彈出 webpack 但似乎沒有任何效果。 也許我不應該使用 font-awesoma 作為組件? 也許我應該通過插入 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>/

編輯類似解決方案的解決方案:

以前我在 docker 容器內運行yarn serve 它會導致很長的熱重載。 當我直接在 Windows 內運行它時,它會在 500毫秒內編譯。 我把它作為未解決的問題,因為我仍然不知道為什么它在 Docker 上這么慢。

剛剛在這個問題上做了幾天的噩夢,我想我可能已經找到了解決辦法。

首先,對我來說,不是在通過 yarn/npm 添加任何特定的 package 之后。 此外,我必須使用 Windows 作為帶有 Linux 容器的主機操作系統。

我用 vue-cli 開始了一個新項目,一切正常,在將其 docker 化后,HMR 速度慢得無法使用。

這里似乎有兩個主要方面在起作用,正在使用的端口以及node_modules/構建時間。

修復其中一個對我沒有太大幫助,但修復兩個都讓 HMR 非常接近再次原生運行。

所以這些是我添加修復的東西:

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,
        },
    },
};

我希望這對某人有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM