-
-
Notifications
You must be signed in to change notification settings - Fork 199
Incorrect paths for fonts #915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Temporary working (but with warning from Encore about public path) solution: Encore
.setOutputPath('web/build/')
.setPublicPath('.')
.setManifestKeyPrefix('.')
.configureManifestPlugin((options) => {
options.publicPath = './build/';
})
// ... Doesn't work with |
Reffering to #88 (comment) we have the same case - multiple Symfony instances under sub-directories e.g:
Our current Encore config looks like this: Encore
.setOutputPath('web/assets/')
.setPublicPath('/assets') and maybe it's important .splitEntryChunks()
.configureSplitChunks((splitChunks) => {
splitChunks.chunks = 'all';
splitChunks.cacheGroups = {
css: {
test: /\.(css|sass|scss|less)$/,
name: 'styles',
chunks: 'all',
},
};
}) to aggregate all style files into single css file. Production entrypoints (with versioning) looks like this
and some examples from manifest.json
Everithing is ok so far, but in styles.css we need relative fonts/images/icons path ... because it looks like this: url(/assets/fonts/glyphicons-halflings-regular.be810be3.woff2) format("woff2") So const config = Encore.getWebpackConfig();
config.module.rules[2].options.publicPath = './';
config.module.rules[3].options.publicPath = './';
module.exports = config; was a "hack" to fix that css paths - after that we have url(fonts/glyphicons-halflings-regular.be810be3.woff2) format("woff2") And now, with |
I am not sure if this is a bug. This works fine, as long as the application is not running in a subdirectory. In this case, since the |
Yea, I understand. It's a matter of having relative paths in the final CSS files. I don't know if that's possible - it's not something I've looked into recently. Sorry I can't be more helpful! This would require some deep research. |
After hours of trial and error I have found working (but not very best I suppose) solution. But maybe someone could come up with their own solution based on that. My goals:
Point 1. can be simply done by .splitEntryChunks()
.configureSplitChunks((splitChunks) => {
splitChunks.cacheGroups = {
css: {
test: /\.(css|sass|scss|less)$/,
name: 'styles',
chunks: 'all',
},
};
}) But for the others the solution is ... "do not use Asset Modules" ... My configuration is based on: .configureFontRule(
{ type: 'javascript/auto' },
(rule) => {
rule.loader = 'file-loader';
rule.options = { outputPath: 'fonts', name: '[name].[ext]', publicPath: './fonts/' };
}
)
.configureImageRule(
{ type: 'javascript/auto' },
(rule) => {
rule.loader = 'file-loader';
rule.options = { outputPath: 'images', name: '[name].[ext]', publicPath: './images/' };
}
) After all of this every font/image is in its directory in public path and my URLs for fonts in @font-face {
font-family: "Glyphicons Halflings";
src: url(./fonts/glyphicons-halflings-regular.eot);
src: url(./fonts/glyphicons-halflings-regular.eot?#iefix) format("embedded-opentype"), url(./fonts/glyphicons-halflings-regular.woff2) format("woff2"), url(./fonts/glyphicons-halflings-regular.woff) format("woff"), url(./fonts/glyphicons-halflings-regular.ttf) format("truetype"), url(./images/glyphicons-halflings-regular.svg#glyphicons_halflingsregular) format("svg");
} Works like a charm ;) If I don't find a better solution using Assets Modules, I think I'll leave it as it is. |
After upgrading to latest web pack (was still on 0.28) I ran into #88 again. Thanks @giero for posting your solution, saved me a couple of hours. As this is an issue for every (open source) app, where the devs don't know anything about the host system, I'd propose adding some documentation for it. Edit: btw. the default config sets filenames to |
The solution from @giero appears to have stopped working. I believe this release is the cause: https://github.com/webpack-contrib/mini-css-extract-plugin/releases/tag/v2.0.0 I have managed to get relative URLs working again by using the following in my webpack.config.js: .configureMiniCssExtractPlugin((loaderConfig) => {
loaderConfig.publicPath = './';
}) |
@andyexeter you made my day! I'll describe my situation so anyone looking in google for this will know your solution works:
Problem:
With @andyexeter's solution, ie: this:
now the final path is: http://localhost:23180/repos/hello-trip/admin-panel/public/build/fonts/fa-solid-900.bdb9e232.woff2 (ie: no double /build/build but a single one) and the icons properly load. |
Thank you for this suggestion. |
1 similar comment
Thank you for this suggestion. |
Friendly reminder that this issue exists. If I don't hear anything I'll close this. |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
Uh oh!
There was an error while loading. Please reload this page.
Hi :)
I have comeback of known issue #88 in new version of Encore :)
So far I used the same solution as #88 (comment)
but this option is not valid anymore.
I tried to modify config using
but there's not much to do here
Do you have any idea how to do this correctly?
The text was updated successfully, but these errors were encountered: