Undefined index when using copy/copyDirectory and {{ mix() }}
Create 2 folders in resources
/css/afolder/afile.css
/css/another/anotherfile.css
Copy the folders with the following:
mix.copy('resources/assets/css/', 'public/css', false);
or
mix.copyDirectory('resources/assets/css/', 'public/css');
The files are copied fine, but when using
{{ mix('css/afolder/afile.css') }}
or
{{ mix('css/anotherfolder/anotherfile.css') }}
It returns back
Undefined index: css/afolder/afile.css
Undefined index: css/anotherfolder/anotherfile.css
The folders exists:
public/css/afolder/afile.css
public/css/anotherfolder/anotherfile.css
Mix manifest just shows the following
{
"/js/app.js": "/js/app.js?id=0eaf1649511b8f1c3fd9",
"/css/app.css": "/css/app.css?id=a86d86d0b7edd1152cc6"
}
Full webpackmix file
let mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/assets/js/app.js', 'public/js');
mix.copy('resources/assets/js/', 'public/js', false);
mix.copy('resources/assets/css/', 'public/css', false);
mix.sass('resources/assets/sass/app.scss', 'public/css');
mix.version();
Reproduced.
This must have been fixed in a recent release. I can't reproduce it.
Sorry @JeffreyWay but we still have the same issues with images. Using latest 2.0.0.
mix.
.copyDirectory('resources/assets/images', 'public/images')
if (mix.inProduction()) {
mix.version()
}
We then use mix() as following:
<link rel="icon" sizes="16x16" href="{{ mix('images/favicons/favicon-16x16.png') }}"/>
The mix manifest just shows:
{
"/js/app.js": "/js/app.js?id=4d4adb1ecd45c9e6af16",
"/css/app.css": "/css/app.css?id=39a14b6a464d27ce2a27",
"/js/app.js.map": "/js/app.js.map?id=38cbd20b0967c37610cc",
"/css/app.css.map": "/css/app.css.map?id=36e0e21066d820711b49",
"/js/vendor.js": "/js/vendor.js?id=ce086365ece891130e34",
"/js/vendor.js.map": "/js/vendor.js.map?id=7e23c32966c385d7a6bc",
"/js/manifest.js": "/js/manifest.js?id=a8218688e07c2d564723",
"/js/manifest.js.map": "/js/manifest.js.map?id=6a2c4d42cbcdcf3ef0de"
}
According to the documentation, you have to specify these 'extra' files or folders you may want versioned.
Versioning Extra Files
The mix.version() will automatically version any compiled JavaScript, Sass/Less, or combined files. However, if you'd also like to version extra files as part of your build, simply pass a path, or array of paths, to the method, like so:
mix.version(['public/js/random.js']);
Hey, first of all, thanks for your work on this Jeffrey, Laravel Mix is great.
I'm having the same issue. After a bit of debugging, I can see that the main problem is the helper function mix() which doesn't handle a file not being set in mix-manifest.json which results to ErrorException (E_ERROR) Undefined index: ....
I have tried several ways to make this work using mix but I was not successful but I personally think that Laravel's mix() helper function should handle undefined index.
But this issue seems to be related to both parts. So to summarise:
mix() should handle undefined index in a better way. I will create an issue regarding this.Please correct me if I'm wrong. Thanks!
Most helpful comment
Reproduced.