我已經創建了具有給定命令的Symfony全Web應用程式symfony new app --webapp。它帶有配置的網客webpack-encore。我可以匯編我的資產npm run watch。但是,當我的CSS更改時,瀏覽器不會自動重新加載。我在這里webpack-dev-server嘗試過Symfony的官方檔案,但沒有作業。
webpack.config.js(我剛洗掉了評論):
const Encore = require('@symfony/webpack-encore');
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.addEntry('app', './assets/app.js')
.enableStimulusBridge('./assets/controllers.json')
.splitEntryChunks()
.enableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.configureBabel((config) => {
config.plugins.push('@babel/plugin-proposal-class-properties');
})
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage';
config.corejs = 3;
})
;
module.exports = Encore.getWebpackConfig();
package.json:
{
"devDependencies": {
"@hotwired/stimulus": "^3.0.0",
"@symfony/stimulus-bridge": "^3.0.0",
"@symfony/webpack-encore": "^1.7.0",
"core-js": "^3.0.0",
"regenerator-runtime": "^0.13.2",
"webpack-notifier": "^1.6.0"
},
"license": "UNLICENSED",
"private": true,
"scripts": {
"dev-server": "encore dev-server",
"dev": "encore dev",
"watch": "encore dev --watch",
"build": "encore production --progress"
}
}
uj5u.com熱心網友回復:
1.解決方案
以下是您如何使用WebPack-Encore和Symfony設定熱重新加載。
- 第一步:
npm i browser-sync-webpack-plugin dotenv --save-dev
- 編輯
webpack.config.js(添加線條有注釋):
const Encore = require('@symfony/webpack-encore');
require("dotenv").config(); // line to add
const BrowserSyncPlugin = require("browser-sync-webpack-plugin"); // line to add
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.addEntry('app', './assets/app.js')
.enableStimulusBridge('./assets/controllers.json')
.splitEntryChunks()
.enableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.configureBabel((config) => {
config.plugins.push('@babel/plugin-proposal-class-properties');
})
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage';
config.corejs = 3;
})
// entry to add
.addPlugin(new BrowserSyncPlugin(
{
host: "localhost",
port: 3000,
proxy: process.env.PROXY,
files: [
{
match: ["src/*.php"],
},
{
match: ["templates/*.twig"],
},
{
match: ["assets/*.js"],
},
{
match: ["assets/*.scss"],
},
],
notify: false,
},
{
reload: true,
}
))
;
module.exports = Encore.getWebpackConfig();
- 在下面添加下面的線
.env(URL應該是您制作時的URLsymfony serve):
PROXY=http://127.0.0.1:8000/
- 在專案檔案夾中打開終端,然后鍵入:
symfony serve
- 在專案檔案夾中打開第二個終端,然后鍵入:
npm run watch
2.故障排除
如果它不作業,那么你應該做的:
- 確保巫婆
port使用BrowserSyncPlugin目前3000在其他地方沒有使用,否則會隨意改變它。 - make sure the url put inside
PROXYin.envis the same as the one you get when you dosymfony serve.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/440111.html
標籤:php 交响乐 网页包 webpack-encore
