我在 Symfony 專案上作業,但是當我想要實作 Tailwind 時,當我想要渲染影像時遇到問題,它回傳 404 .. 我瀏覽了整個互聯網并沒有找到答案,請幫助我
順便提一句。通過 url 渲染影像也不起作用
webpack.config.js
const path = require('path');
// Manually configure the runtime environment if not already configured yet by the "encore" command.
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
Encore
.setOutputPath('public/build/')
.setPublicPath(Encore.isProduction() ? '/build' : '/test/public/build')
.copyFiles([
{
from: './assets/images',
to: 'images/[path][name].[ext]',
}
])
.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;
})
.enableSassLoader()
.enablePostCssLoader((options) => {
options.postcssOptions = {
// the directory where the postcss.config.js file is stored
config: './postcss.config.js',
};
})
.splitEntryChunks()
.setPublicPath('/build')
;
module.exports = Encore.getWebpackConfig();
tailwind.config.js
purge: [
'./templates/**/*.html.twig',
'./assets/**/*.css',
'./assets/**/*.js',
'./assets/**/*.vue',
],
media: false,
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
assets/app.js
// any CSS you import will output into a single css file (app.css in this case)
import './styles/app.css';
// start the Stimulus application
import './bootstrap';
twig usage
<div class="flex justify-center mr-16">
<img class="h-12 align-middle rounded-full" src="{{ asset('images/avatar.png') }}" alt="Symfony Webpack 不作業服務器在 CSS/JS 中回傳 404">
</div>
uj5u.com熱心網友回復:
好的,我修復了它,我不知道為什么,但我發現了這個https://github.com/EresDev/HandwerkerFullstack/commit/3a1d9baf2caacf8e4b27404b111d47da1bd67a68
剛剛改變
.setPublicPath(Encore.isProduction() ? '/build' : '/test/public/build')
到
.setPublicPath('/build')
也許它會有所幫助
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/400854.html
