npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-css-namespacing

v0.1.0

Published

[中文文档](https://github.com/Hitotsubashi/gulp-css-namespacing/blob/master/README_CN.md)

Downloads

3

Readme

gulp-css-namespacing

中文文档

A Gulp Plugin dedicated to handling CSS namespaces. It is based on css-namespacing.

This plugin has two functions:

  • This plugin is mainly used to prevent global contamination of styles caused by the introduction of third-party CSS.

  • During development, when compiling CSS code, it will automatically add namespace to the specified classname according to the options.

Getting Started

To begin, you'll need to install gulp-css-namespacing:

npm install gulp-css-namespacing --save-dev

Then add the plugin to your gulpfile.js. For example:

gulpfile.js

const { src, dest } = require('gulp');
const cssNamespacing = require('gulp-css-namespacing')

const namespace = () => src('src/style', { base: 'src/style' })
  .pipe(
    cssNamespacing([
      { namespace: 'my-', path: [/test.css/] },
    ])
  )
  .pipe(dest('dist/style',{bases:'dist/style'}));

module.exports = {
  namespace,
};

Suppose there is a CSS file as followed called test.css.

src/style/test.css

.container-fluid,
.container {
  margin-right: auto;
  margin-left: auto;
}

.container-fluid {
  padding-right: 2rem;
  padding-left: 2rem;
}

After running yarn gulp test , the compiled CSS file is as followed.

dist/style/test.css

.my-container-fluid,
.my-container {
  margin-right: auto;
  margin-left: auto;
}

.my-container-fluid {
  padding-right: 2rem;
  padding-left: 2rem;
}

In the options, you can set which classnames do not need to be prefixed, or only which classnames need to be prefixed, and the value of the namespace.

In addition, in the CSS code, you can use @namespacing flexibly set the above configuration.If you want to learn more,check here.

If you want to learn more about the result after namespacing, please check css-namespacing.

API

cssNamespacing(options)

options

Type: Array Default: undefined

element in options is an object,and it contains the following properties.

|Name|Type|Default|Necessary|Description| |----|----|-------|-----------|---------| |path|{Array<String/RegExp>}|undefined|false|An array that contains the matching path for the CSS file to add the namespace to| |value|{String}|undefined|false|the value of namespace you want to prefix| |not|{Array<RegExp>}|undefined|false|An array that contains the matching classnames that are not prefixed by specified namespace| |only|{Array<RegExp>}|undefined|false|An array that contains the matching classnames that will only be prefixed by specified namespace|

path

Type: {Array<String|RegExp>} Default: undefined

Attention: In view of the different situation of file separators caused by different operating platforms, I have done processing to unify the separator to '/'.

Here shows different situation about the difinition of options:

1.use RegExp in Array

For example:

const options=[
  { 
    value: 'bsp-', 
    path: [/node_modules\/bootstrap/],
  }
]

It will find matched files through Regexp.prototype.test like path.test(filepath)

2.use String in Array

For example:

const options=[
  { 
    value: 'bsp-', 
    path: ['./node_modules/bootstrap/dist/css/bootstrap.min.css'],
  }
]

It will find matched files through String.prototype.includes like filepath.includes(path)

3.path is not defined

For example:

const options=[
  { 
    value: 'my-' 
  }
]

At this time,it will adds a namespace to the class names of all the scanned CSS files.

value

Type: {String} Default: undefined

if value is undefined,for example:

const options=[
  { 
    path:[/bootstrap/] 
  }
]

At this time,the scanned files will not be processed.

not

Type:{Array<RegExp>} Default:undefined

For example:

const options=[
  {
    path:[/bootstrap/], 
    not:[/^box$/],
  }
]

At this time,all classnames named box will not be prefixed with namespace in the code of the CSS file being scanned.

only

For example:

const options=[
  { 
    path:[/bootstrap/],
    not:[/^box$/],
  }
]

At this time,in the code of the CSS file being scanned,only the classname named box will be prefixed with namespace

License

MIT