gulp-wp-toolkit icon indicating copy to clipboard operation
gulp-wp-toolkit copied to clipboard

Consider adding node-sass-tilde-importer

Open seothemes opened this issue 7 years ago • 2 comments

Adding a tilde importer allows shorter URLs when importing files from node_modules. Gulp doesn't provide this by default.

Expected Behavior

@import "~normalize-css/normalize";

Current Behavior

@import "../../../node_modules/normalize-css/normalize";

Possible Solution

Add node-sass-tilde-importer - https://www.npmjs.com/package/node-sass-tilde-importer

Steps to Reproduce

  1. Require the package:
tilde = require( 'node-sass-tilde-importer'),
  1. Add the importer in the css task:
.pipe(sass.sync({
  outputStyle: outputConfig.outputStyle,
  includePaths: [].concat(normalize),
  importer: tilde
}))

Context

This makes it a lot easier to import scss or js files from node_modules. Especially in deeper nested folder structures.

Your Environment

  • Version used: Latest
  • Node version: 9.10.1
  • NPM version: 5.6.0

seothemes avatar Aug 17 '18 03:08 seothemes

Normalize 8.0.0 is already bundled with Gulp WP Toolkit.

So all you need to use is:

@import "normalize";

And it'll be included in the CSS build task automatically.

craigsimps avatar Aug 17 '18 11:08 craigsimps

The normalize.css was just an example but good to know it’s included.

I’m currently rebuilding my starter theme’s Sass and have started splitting up certain styles into node packages e.g https://www.npmjs.com/package/genesis-column-classes. I’m also importing bourbon, neat and a few other things from node_modules.

It’s definitely not essential, just cleans up Sass files a bit.

seothemes avatar Aug 17 '18 11:08 seothemes