webpack.mix laravel-mix-purgecss свой отдельный css для каждого лендинга

У каждого лендинга должны быть чистые css фалы без неиспользуемых стилей, оптимизированных и тп

Как сделать что бы purgeCss брал свой отедельный index.html для своего кааталога/лендинга стилей ?

├── storage
│   └── app
│      └── landings
│            ├── landingName1
|            |  ├── css
|            |  |   ├── style.css
|            |  |   ├── other.css
|            |  ├── js
|            |  |   ├── app.js
|            |  └── index.html
│            ├── landingName2
|            |  ├── css
|            |  |   ├── style.css
|            |  |   ├── other.css
|            |  ├── js
|            |  |   ├── app.js
|            |  └── index.html
│            ├── landingName3
|            |  ├── css
|            |  |   ├── style.css
|            |  |   ├── other.css
|            |  ├── js
|            |  |   ├── app.js
|            |  └── index.html
├── public
│   └── modules
│      └── landingpage
│            ├── landingName1
|            |  ├── css
|            |  |   ├── style.css
|            |  |   ├── other.css
|            |  ├── js
|            |  |   ├── app.js
│            ├── landingName2
|            |  ├── css
|            |  |   ├── style.css
|            |  |   ├── other.css
|            |  ├── js
|            |  |   ├── app.js
│            ├── landingName3
|            |  ├── css
|            |  |   ├── style.css
|            |  |   ├── other.css
|            |  ├── js
|            |  |   ├── app.js
const mix = require('laravel-mix');
const glob = require('glob-all');
require('laravel-mix-purgecss');

const { argv } = require('yargs');
const yargs = require('yargs/yargs');
const fs = require("fs");


console.log(argv);


function mix_scss_files() {
    var landings_relative_path = "storage/app/landings/";
    var landing_paths = fs.readdirSync(landings_relative_path);

    for (var i_folder = 0; i_folder < landing_paths.length; i_folder++) {

        var landing_code = landing_paths[i_folder];
        var folder = landings_relative_path + landing_paths[i_folder];
        console.log("folder = " + folder);

        const defaultConfig = {
            content: [
                folder + '/index.html'
            ],
            defaultExtractor: (content) => content.match(/[\w-/.:]+(?<!:)/g) || [],
            safelist: { standard: [/-active$/, /-enter$/, /-leave-to$/, /show$/] },
        }

        mix.js(folder +"/js/*.js", "public/modules/landingpage/"+ landing_code +"/js");

        var relative_path = folder + '/css/';

        var paths = fs.readdirSync(relative_path);

        for (var i = 0; i < paths.length; i++) {
            if (paths[i].indexOf('.css') > 0 && paths[i].charAt(0) != '_') {
                var file_path = relative_path + paths[i];
                console.log(file_path);
                var path = [];
                mix.css(file_path, 'public/modules/landingpage/' + landing_code + '/css/')
                    .purgeCss({
                        content: [folder + '/index.html'],
                    });
            }
        }
    }
}

mix_scss_files();


if (mix.inProduction()) {
    mix.version();
}

Ответы (1 шт):

Автор решения: Марат Ардисламов

Смог это сделать

const mix = require('laravel-mix');
const purgecss = require('@fullhuman/postcss-purgecss')

const { argv } = require('yargs');
const yargs = require('yargs/yargs');
const fs = require("fs");

console.log(argv);

mix.webpackConfig({
    plugins: [
        // ...
    ],
    resolve: {
        // ...
    },
    stats: {
        children: true
    }
});



function mix_scss_files() {
    var landings_relative_path = "storage/app/landings/";
    var landing_paths = fs.readdirSync(landings_relative_path);

    for (var i_folder = 0; i_folder < landing_paths.length; i_folder++) {

        var landing_code = landing_paths[i_folder];
        var folder = landings_relative_path + landing_paths[i_folder];
        console.log("folder = " + folder);

        var relative_path = folder + '/css/';
        var paths = fs.readdirSync(relative_path);

        mix.js(folder +"/js/*.js", "public/modules/landingpage/"+ landing_code +"/js");

        for (var i = 0; i < paths.length; i++) {
            if (paths[i].indexOf('.css') > 0 && paths[i].charAt(0) != '_') {
                var file_path = relative_path + paths[i];
                console.log(file_path);
                var path = [];


                mix.postCss(file_path, 'public/modules/landingpage/' + landing_code + '/css',[
                    purgecss({
                        content: [folder + '/index.html']
                    })
                ]);

            }
        }
    }
}

mix_scss_files();

if (mix.inProduction()) {
    mix.version();
}
→ Ссылка