Delete Temp Files in Laravel Mix

廉价感情. 提交于 2020-05-29 20:04:40

问题


I'd like to remove temp build files during or after my laravel-mix build.
Here's some code that I have currently, but del isn't working:

const mix = require('laravel-mix');
const del = require('del');

// compile sass into temp css file
mix.sass('resources/stylesheets/style.scss', 'public/css/temp.css');

// compile css
mix.styles([
    // other css stylesheets here...
    'public/css/temp.css' // include temp css file
], 'public/css/admin.min.css');

// delete temp css file
del('public/css/temp.css'); // not deleting the file

回答1:


I was able to solve this by running del within a then() returned by mix.styles():

const mix = require('laravel-mix');
const del = require('del');

// compile sass into temp css file
mix.sass('resources/stylesheets/style.scss', 'public/css/temp.css');

// compile css
mix.styles([
    // other css stylesheets here...
    'public/css/temp.css' // include temp css file
], 'public/css/admin.min.css').then(() => {
    del('public/css/temp.css'); // deletes the temp file
});

The same thing also works with mix.scripts():

mix.scripts([
    'public/js/app.js',
    'public/js/global.js',
], 'public/js/app.combined.js').then(() => {
    del('public/js/app.js');
    del('public/js/global.js');
});


来源:https://stackoverflow.com/questions/53779090/delete-temp-files-in-laravel-mix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!