-
-
Notifications
You must be signed in to change notification settings - Fork 200
copyFiles doesn't works for files required in js #490
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
Hi there! Yea, there is some inconsistency internally. When you reference an image in css, we move that for you always into images. Then there is this completely separate functionality that copies files - and the destination is wherever you want. So, if you reference an image from css and also copy that file, it will end up in 2 destinations. We could potentially unify this somehow, maybe, but I’m not sure. |
Okay so that's normal for now, but it's kinda weird, imo. I don't know if it's possible, but is it possible to detect if the And if it's used then use the |
Hi @etshy,
I don't think that would be a good idea at all. Let's say you have the following config: Encore.copyFiles({
from: './assets',
to: 'assets/[path][name].[hash:8].[ext]',
pattern: /\.(png|csv)$/
}); What should Encore do:
I mean... we could decide what should be the result of each one of these cases but if that isn't obvious for us right now it won't be obvious for the end-user either. And this is probably the easiest thing to deal with because then we would, for instance, have to handle multiple calls to In my opinion |
I see your point there. I tried to have Is there a way, currently, to have the same "behaviour" ? Here is what I tried, if I have the following
while my images from If it's not possible, Maybe make a way to create custom variable to use in the path like the following.
It will recreate the path inside It would allow to have the files in same folder. Just a quick idea I just had though. |
Hmm... you may be right, the context is not the same in I don't think introducing a custom placeholder would be a good thing since the other ones are kinda standards (defined by the file-loader: https://github.com/webpack-contrib/file-loader#placeholders). It may still be possible to get a config in which files override each others but with some trade-offs (such as not using Something we may be able to do however is to allow people to set the the It could look like that: Encore
.configureFilenames({ images: 'img/[path][name].[hash:8].[ext]' })
.copyFiles({
context: './',
from: './any/directory',
to: 'img/[path][name].[hash:8].[ext]'
pattern: /.png$/
})
; Or another solution, simply add a flag to use the same context than the one used in other loaders: Encore
.configureFilenames({ images: 'img/[path][name].[hash:8].[ext]' })
.copyFiles({
useDefaultContext: true,
from: './any/directory',
to: 'img/[path][name].[hash:8].[ext]'
pattern: /.png$/
})
; |
Adding a context could be good, but the And so, the whole path will be copied into the The best thing would be to choose the root folder for the context too, I think, but I guess it's not really possible with the webpack placeholder ? |
You can actually already specify the context for images/fonts... but that's not something obvious at all :) By default the However, there is an alternative to that loader: the And the thing is: the Encore.configureUrlLoader({
images: {
limit: 1, // Will use the file-loader if over a byte
context: '...'
}
}); Now if you choose to change the context I recommend you to read the following comment before to make sure you understand what the resulting paths will be (especially if you import things from These "ugly paths" were the reason we choose to not include the |
Thanks I'll read more about it. But, from my quick view of the github issues, and urlLoader github page I didn't see any I'll make some test when I can. Edit : After few tests |
@etshy The I did a quick test and it seems to work on my side. Given this project structure (the
And the following // webpack.config.js
const Encore = require('@symfony/webpack-encore');
Encore
.setOutputPath('build/')
.setPublicPath('/')
.cleanupOutputBeforeBuild()
.enableSingleRuntimeChunk()
.addEntry('main', './src/index.js')
.configureFilenames({
images: './images/[path][name].[hash:8].[ext]'
})
;
module.exports = Encore.getWebpackConfig(); I get this
Now, if I add this code before Encore.configureUrlLoader({
images: {
limit: 1,
context: './assets/images'
}
}); The
|
It worked yeah, thanks a lot But for the images/fonts in my CSS framework it generated a weaird path. I have this structure
And I get this build
for the following webpack config
the Thanks again. |
That's what I was talking about at the end of one of my previous comment and why I recommended you to read #103 (comment). Underscores are used in |
Yep I missed that part in your comment. Well, the build is working anyway so that's fine, but still, I think this is weird to have this kind of generation. Thanks for all your help and advices. |
…erryan) This PR was merged into the master branch. Discussion ---------- Allow to set a custom context in copyFiles The current behavior of `copyFiles()` is to use the value of the `from` option as a context when copying files. This means that when doing the following: ```js Encore.copyFiles({ from: './assets/images', to: '[path][name].[ext]', includeSubdirectories: false, }); ``` Will end-up putting all the files from `./assets/images` directly at the root of the output directory. Sometimes this is not the desired behavior (see #490 (comment)) which is why this PRs adds a `context` option to `copyFiles()` entries (closes #490). For instance: ```js Encore.copyFiles({ from: './assets/images', to: '[path][name].[ext]', includeSubdirectories: false, context: './', }); ``` Will put all the copied files inside of an `./assets/images` folder in the output directory. Commits ------- 73b8be5 a bit more docs 487d6ef Allow to set a custom context in copyFiles
@Lyrkan How would you configure that in the current version of encore? I'm stuck with the same issue and For
I tried this config:
but this results in copied files in Sadly there is no |
I got a weird behaviour with copyFiles.
I know in the docs, the copyFiles is used fore images in templates, but, in my case, and I guess in many cases, I have images in CSS and in templates.
For example with this webpack config
In this case, the images are copied into 2 folders.
The images from templates follow the
copyFiles
rules and end up inpublic/build/img/[path]
The images from CSS/JS are copied into
public/build/images/*.jpg|png|etc.
and if I have the same images used in template and in CSS/JS, the images will be duplicated, one on each build sub folder.
It could be good if all images followed the same rules, no ?
Or I missed something in the docs ?
Edit : Sorry I misinterpreted something.
It seems copyFiles copy all files, not only those used in templates.
But for some reasons I also have images copied into an
images
folder and I don't understand what is causing this.The images copied into the
images
folder are only images used in CSS (used in my CSS "framework",fomantic-ui
).The text was updated successfully, but these errors were encountered: