5

I am new at Laravel-mix and webpack. After some practice I was able to combining css and js files into 1 single file respectively. However, after the combine the other files are still there, which are of no use to the application.

For example:

resources
|-- scss
  |-- font-awesome.scss
  |-- template.scss

public
|-- css
  |-- font-awesome.css
  |-- template.css

After combining:

public
|-- css
  |-- font-awesome.css
  |-- template.css
  |-- combined.min.css (font-awesome.css + template.css = combined.min.css)

Webpack

mix
    .sass('resources/sass/font-awesome.scss', 'public/css/font-awesome.css')
    .sass('resources/sass/template.scss', 'public/css/template.css');

// combining css files
mix.combine([
    'public/css/font-awesome.css',
    'public/css/template.css'
], 'public/css/combined.min.css');

As the font-awesome.css & template.css files are combined into combined.min.css, there is no need for them anymore, same goes for the javascript files.

How to remove these useless files, is this possible..?

1

1 Answer 1

4

Here is the link where I found the solution https://stackoverflow.com/questions/53779090/delete-temp-files-in-laravel-mix

webpack.mix.js:

...
const del = require('del');
const env = process.env.NODE_ENV || 'dev';

mix
    .sass('resources/sass/font-awesome.scss', 'public/css/font-awesome.css')
    .sass('resources/sass/template.scss', 'public/css/template.css');

// combining css files
mix.combine([
    'public/css/font-awesome.css',
    'public/css/template.css'
], 'public/css/combined.min.css').then(() => {
    if (env === 'production') {
        del('public/css/font-awesome.css');
        del('public/css/template.css');
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.