Symfony 4和Encore自动刷新无法正常工作,我总是必须手动重新加载浏览器

时间:2018-09-29 16:31:24

标签: css symfony webpack-dev-server symfony4 webpack-encore

当我运行此命令时,从一个新的Symfony 4项目开始:

./node_modules/.bin/encore dev-server --hot

enter image description here

然后我修改一个scss文件(通过示例更改body标签的background-color),外壳会做出反应

enter image description here

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

谢谢!

=>我在不同的浏览器上进行了测试 =>如果我修改了自定义的javascript文件,浏览器将自动刷新!相反,当我更改scss文件时

=>我的资产目录结构:

enter image description here

=>我的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();

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

enter image description here

1 个答案:

答案 0 :(得分:0)

考虑文档here时,热模块替换(HMR)并非对所有功能都有效。它应该适用于Vue.js,仅此而已。 有关更多信息,您可以检查documentation for HMR

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

祝你好运