【问题标题】:Delete Temp Files in Laravel Mix删除 Laravel Mix 中的临时文件
【发布时间】:2019-05-15 16:29:27
【问题描述】:

我想在 laravel-mix 构建期间或之后删除临时构建文件。
这是我目前拥有的一些代码,但 del 不起作用:

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

【问题讨论】:

  • 你为什么要这样做?为什么不直接创建 admin.min.css?
  • @KuebelElch15 你不能在mix.sass() 中混合css和sass文件所以这是我的解决方法。
  • 哦,我看错了//other css stylesheets 评论

标签: javascript webpack laravel-mix del


【解决方案1】:

我能够通过在mix.styles() 返回的then() 中运行del 来解决这个问题:

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
});

同样的事情也适用于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');
});

【讨论】:

  • 我不知道这些方法返回了承诺。我已经开始在我的 sass 文件中导入 css 文件,所以我不需要临时文件。非常感谢!
猜你喜欢
  • 2017-07-04
  • 1970-01-01
  • 1970-01-01
  • 2010-11-04
  • 1970-01-01
  • 2020-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多