Skip to content

[Bug]: unable to use const path variables in gulp plugins? #2679

@SamuelMiller

Description

@SamuelMiller

I am not sure if this is a bug, or if I am doing something wrong. I am unable to use const ${variables} in gulp plugins.

I've declared various const file paths in my gulpfile.js as in the following:

const paths = {
    html: {
        src: ['./src/**/*.html', '!./src/assets/**'],
        dest: './dist/',
    },
    css: {
        src: ['./src/assets/css/*.css', '!./src/assets/css/*.min.css'],
        dest: './dist/assets/css/',
    },
    maincss: {
        bootstrap: ['src/assets/css/bootstrap.css'],
        reboot: 'src/assets/css/bootstrap-reboot.css',
        theme: 'src/assets/css/theme.css',
    },
    scripts: {
        src: ['./src/assets/js/**/*.js'],
        dest: './dist/assets/js/',
    },
};

I want to be able to use these const variables not only for input and output but also within a plugin's pipe stream. I am able to do this:

function compileStyles() {
    return src(paths.maincss.bootstrap)
        .pipe(purgecss({ content: ['./src/*.html', './src/assets/js/*.js'] }))
        .pipe(src(paths.maincss.theme))
        .pipe(concat('bootstrap.css'))
        .pipe(postcss([autoprefixer(), cssnano()]))
        .pipe(dest(paths.css.dest))
}

But not this:

function compileStyles() {
    return src(paths.maincss.bootstrap)
        .pipe(purgecss({ content: [`${paths.html.src}`,`${paths.scripts.src}`] }))
        .pipe(src(paths.maincss.theme))
        .pipe(concat('bootstrap.css'))
        .pipe(postcss([autoprefixer(), cssnano()]))
        .pipe(dest(paths.css.dest))
}

Although there are no errors in the terminal, the output file is incomplete--missing CSS selectors? It appears the purgecss file path variables are not being properly passed. Maybe an issue with the plugin itself, is that is not able to handle path variables? I've found issues with other gulp plugins as well when passing a path URL as a const variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions