CSS/JS 中的 Symfony Webpack 服务器 return 404 不工作
Symfony Webpack not working server return 404 in CSS/JS
我在 Symfony 项目上工作,但是当我想要实现 Tailwind 时,我在渲染图像时遇到了问题 return 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="">
</div>
好的,所以我修复了它,我不知道为什么,但我发现了这个 https://github.com/EresDev/HandwerkerFullstack/commit/3a1d9baf2caacf8e4b27404b111d47da1bd67a68
刚刚改变
.setPublicPath(Encore.isProduction() ? '/build' : '/test/public/build')
到
.setPublicPath('/build')
也许会有帮助
我在 Symfony 项目上工作,但是当我想要实现 Tailwind 时,我在渲染图像时遇到了问题 return 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="">
</div>
好的,所以我修复了它,我不知道为什么,但我发现了这个 https://github.com/EresDev/HandwerkerFullstack/commit/3a1d9baf2caacf8e4b27404b111d47da1bd67a68
刚刚改变
.setPublicPath(Encore.isProduction() ? '/build' : '/test/public/build')
到
.setPublicPath('/build')
也许会有帮助