does exist a method to "fake" the output path in mix-manifest.json in production environment only?
i run my laravel in a subfolder and i would need an option to add some kind of prefix to my path.
... is there a way to add automatically "/subdir_name" ?
mix-manifest.json :
{
"/js/backend.js": "/subdir_name/js/backend.a16e8ecf54a937233140.js",
"/js/frontend.js": "/subdir_name/js/frontend.799232976985f885392c.js",
"/css/frontend.css": "/subdir_name/css/frontend.9bc78ae80cab9ecc1d240d27ce816801.css",
"/css/backend.css": "/subdir_name/css/backend.759d9d3b9e343547408e62525fcaca48.css"
}
thanks
editing
\node_modules\laravel-mix\src\Manifest.js
in refresh method you can add:
manifest[key] = "/sub_dir" + val;
obviously this is a _super dirty hack_ ... an option in webpack.mix.js would be very useful 馃憤
You can't do it right now, but we can an option to change that in the next release if needed.
any news? 馃槂
Hello all,
Do you have any fix for change directory as my setup is in folder /var/www/laravel/taxilot.mu and I want to generate the mix-manifest.json into /var/www/html/taxilot.mu folder. Any fixes may work for now till you provide any option. I dont want to change the domain pointing a lot of setup already running.
@JeffreyWay , definitely needed.
I added this _Closure Command_ to routes/console.php
so I can execute php artisan fix-mix-manifest after every npm run prod
Artisan::command('fix-mix-manifest', function () {
if (App::environment('production')) {
$subdir = '/your-awesome-subdirectory';
$manifest = json_decode(File::get(public_path('mix-manifest.json')));
if (is_null($manifest)) {
return $this->comment('File is empty!');
}
foreach($manifest as $key => $value) {
if (str_contains($value, ['/js', '/css'])) {
$manifest->$key = str_start($value, $subdir);
}
}
$manifest = json_encode($manifest, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
File::put(public_path('mix-manifest.json'), $manifest);
$this->comment('New mix-manifest is:'.PHP_EOL.$manifest);
}
else {
$this->comment('This command works only in production!');
}
})->describe("Fix mix-manifest.json for subdir");
A client of mine run has their department running on one server & their products are placed in folders in the root directory.
E.g. https://main-server.intranet/product-1/ (product-1, product-2, ...etc) where a product-1 could be a laravel application. (no public path because it's a virtual directory)
Issues arise when the app tries to load assets via mix() in Blade templates.
A function like mix.emulatePublicPath('product-1') would great.
I was able to accomplish this in the webpack.mix.js file:
mix.js(jsFiles, 'public/js/app.js').version().sass(sassFiles, 'public/css').version().then(() => {
var fs = require('fs');
var mix_manifest_file = path.resolve(__dirname) + '/public/mix-manifest.json';
var mix_manifest = require(mix_manifest_file);
for(var key in mix_manifest) {
mix_manifest[key] = '/starter-app' + mix_manifest[key];
}
fs.writeFile(mix_manifest_file, JSON.stringify(mix_manifest));
});
Most helpful comment
@JeffreyWay , definitely needed.