WPGulp icon indicating copy to clipboard operation
WPGulp copied to clipboard

Compile multiple CSS files into different directories

Open cdils opened this issue 6 years ago • 8 comments

I'm in the process of adding editor-specific and gutenberg-specific styles to a project. While this is possible with the existing WPGulp styles task, I'd like to suggest a more elegant implementation.

Current output

In my project config.js file under Style Options, I have:

// Style options.
styleSRC: './develop/scss/*.scss', // Path to main .scss file.
styleDestination: './', // Path to place the compiled CSS file. Default set to root folder.

styleSRC points to three Sass files I have created:

editor-styles.scss // editor styles gutenberg.scss Gutenberg-specific styles styles.scss // main style sheet

Running these through the styles task produces these files in my project root:

|- editor-styles.css
|- editor-styles.min.css
|- editor-styles.css.map
|- gutenberg.css
|- gutenberg.min.css
|- gutenberg.css.map
|- styles.css
|- styles.min.css 
|- styles.css.map

Proposed output

That's a lot of clutter. I'd prefer to see something like this:

|- css/ 
|    |- editor-styles.css
|    |- editor-styles.min.css
|    |- gutenberg.css
|    |- gutenberg.min.css
|- styles.css
|- styles.min.css 
|- styles.css.map

It's debatable whether or not a CSS map for editor and Gutenberg styles is that useful, since those are presumably quite small files and easy to troubleshoot. It's also debatable whether you'd want to keep the three main style sheet variations in the root or move everything off to a css folder, save for styles.min.css.

Possible solution

There are multiple approaches to this. One is to add a couple of variables to config.js such as styleSRCHelpers and styleDestinationHelpers and use that as the basis for a new gulp task that mimics the current styles task, but skips sourcemap creation and routes "helper" css files (for editor and gutenberg) to a different location (i.e. css/ folder).

Forgive me, my brain isn't creative enough for better thoughts on names at the moment!

Feedback wanted

Ultimately, I'd like feedback on:

  1. Whether there's a use-case to even justify adding something like this to WPGulp versus me just implementing a one-off solution in my project. My gut is that with Gutenberg coming, there's a good use-case for generating Gutenberg-specific stylesheets and wanting to store those somewhere other than the project root. Gutenberg aside, I think there's also a use-case for needing to compile specific Sass files to specific folders. For example, if I needed to create custom styles to extend Easy Digital Downloads, I'd need to compile those Sass files into an EDD-specific folder. For reference, here's how compiling multiple CSS files was done in wp-gulp-toolkit.

  2. Thoughts on implementation. The solution I mentioned above is just one idea. Whatever solution is involved would need to also consider how/if generating corresponding rtl files is necessary.

If this is something that would be worthwhile for WP Gulp, I'm happy to investigate further, but would appreciate some input.

cdils avatar May 09 '18 20:05 cdils

Apologies, I've been away due to a family emergency. Will respond soon. Nice ideas.

ahmadawais avatar May 23 '18 05:05 ahmadawais

No worries @ahmadawais

cdils avatar May 23 '18 12:05 cdils

@cdils now that v2 has been released how do you propose we can handle this?

ahmadawais avatar Sep 14 '18 14:09 ahmadawais

I also want this feature. When will it be adopted in the official version?

Suzakura avatar Apr 23 '19 08:04 Suzakura

I see an approved PR for this in #125 - how can we get it merged?

isvictorious avatar May 22 '19 16:05 isvictorious

Pinging this! I just duplicated style-RTL to generate basically the same files as @cdils although not very elegantly. Are there any roadblocks on this merge, I'd love to try it out!

jamieschmid avatar Nov 12 '19 02:11 jamieschmid

None beyond time. If you can test this and review the PR it will help.

ahmadawais avatar Nov 12 '19 04:11 ahmadawais

I've tested this PR and for me is it working like a charm! Thanks @mintbird for your work!

AndreaBarghigiani avatar Nov 20 '19 11:11 AndreaBarghigiani