Symfony 4 & encore 自动刷新不起作用,我总是必须手动重新加载浏览器

use*_*454 5 css symfony webpack-dev-server webpack-encore symfony4

从一个新的 Symfony 4 项目中,当我运行这个命令时:

./node_modules/.bin/encore dev-server --hot
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

然后我修改了一个 scss 文件(通过示例更改 body 标签背景颜色),shell 做出反应

在此处输入图片说明

但是我的浏览器不会自动刷新!我总是必须手动重新加载页面以查看最新的 css 更改。我可以在哪里做一个 mystake?

谢谢 !

=> 我用不同的浏览器测试过 => 如果我修改自定义 javascript 文件,浏览器会自动刷新!相反,当我更改 scss 文件时

=> 我的资产目录结构:

在此处输入图片说明

=> 我的 webpack.config.js 内容:

var Encore = require('@symfony/webpack-encore');

Encore
    // directory where compiled assets will be stored
    .setOutputPath('public/build/')
    // public path used by the web server to access the output path
    .setPublicPath('/build')
    // only needed for CDN's or sub-directory deploy
    //.setManifestKeyPrefix('build/')

    /*
     * ENTRY CONFIG
     *
     * Add 1 entry for each "page" of your app
     * (including one that's included on every page - e.g. "app")
     *
     * Each entry will result in one JavaScript file (e.g. app.js)
     * and one CSS file (e.g. app.css) if you JavaScript imports CSS.
     */
    .addEntry('app', './assets/js/app.js')
    .addEntry('article/main', './assets/js/article/main.js')
    .addStyleEntry('article/style','./assets/css/article/style.scss')
    //.addEntry('page2', './assets/js/page2.js')

    /*
     * FEATURE CONFIG
     *
     * Enable & configure other features below. For a full
     * list of features, see:
     * https://symfony.com/doc/current/frontend.html#adding-more-features
     */
    .cleanupOutputBeforeBuild()
    .enableBuildNotifications()
    .enableSourceMaps(!Encore.isProduction())
    // enables hashed filenames (e.g. app.abc123.css)
    .enableVersioning(Encore.isProduction())

    // enables Sass/SCSS support
    .enableSassLoader()

    // uncomment if you use TypeScript
    //.enableTypeScriptLoader()

    // uncomment if you're having problems with a jQuery plugin
    //.autoProvidejQuery()
;

module.exports = Encore.getWebpackConfig();
Run Code Online (Sandbox Code Playgroud)

=> 我自动生成的 public/build/manifest.json 文件:

在此处输入图片说明

Art*_*dor 2

考虑到这里的文档,热模块更换(HMR)目前并不适用于所有情况。它应该适用于 Vue.js,但仅此而已。有关更多信息,您可以查看HMR 的文档

TL:DR 在 HMR 的当前状态下,您的自定义 js 和 css 资源不应热重载。您必须手动重新加载浏览器。我不知道您是否了解 --watch 选项,但它允许您在每次文件更改时编译代码。

祝你好运