22
33[ ![ NPM Version] [ npm-img ]] [ npm-url ]
44[ ![ Build Status] [ cli-img ]] [ cli-url ]
5- [ ![ Gitter Chat] [ git-img ]] [ git-url ]
5+ [ ![ Windows Build Status] [ win-img ]] [ win-url ]
6+ [ ![ Support Chat] [ git-img ]] [ git-url ]
67
78[ PostCSS Extend Rule] lets you use the ` @extend ` at-rule and
89[ Functional Selectors] in CSS, following the speculative
910[ CSS Extend Rules Specification] .
1011
11- ``` css
12+ ``` pcss
1213%thick-border {
1314 border: thick dotted red;
1415}
@@ -68,7 +69,9 @@ npm install postcss-extend-rule --save-dev
6869Use [ PostCSS Extend Rule] to process your CSS:
6970
7071``` js
71- require (' postcss-extend-rule' ).process (YOUR_CSS /* , PostCSS Options, Options */ );
72+ import postcssExtend from ' postcss-extend-rule' ;
73+
74+ postcssExtend .process (YOUR_CSS , /* processOptions */ /* , pluginOptions */ );
7275```
7376
7477#### PostCSS
@@ -82,11 +85,48 @@ npm install postcss --save-dev
8285Use [ PostCSS Extend Rule] as a plugin:
8386
8487``` js
88+ import postcss from ' gulp-postcss' ;
89+ import postcssExtend from ' postcss-extend-rule' ;
90+
8591postcss ([
86- require ( ' postcss-extend-rule ' )( /* Options */ )
92+ postcssExtend ( /* pluginOptions */ )
8793]).process (YOUR_CSS );
8894```
8995
96+ #### Webpack
97+
98+ Add [ PostCSS Loader] to your build tool:
99+
100+ ``` bash
101+ npm install postcss-loader --save-dev
102+ ```
103+
104+ Use [ PostCSS Extend Rule] in your Webpack configuration:
105+
106+ ``` js
107+ import postcssExtend from ' postcss-extend-rule' ;
108+
109+ module .exports = {
110+ module: {
111+ rules: [
112+ {
113+ test: / \. css$ / ,
114+ use: [
115+ ' style-loader' ,
116+ { loader: ' css-loader' , options: { importLoaders: 1 } },
117+ { loader: ' postcss-loader' , options: {
118+ ident: ' postcss' ,
119+ plugins : () => [
120+ postcssExtend (/* pluginOptions */ )
121+ ]
122+ } }
123+ ]
124+ }
125+ ]
126+ }
127+ }
128+ ```
129+
90130#### Gulp
91131
92132Add [ Gulp PostCSS] to your build tool:
@@ -98,17 +138,16 @@ npm install gulp-postcss --save-dev
98138Use [ PostCSS Extend Rule] in your Gulpfile:
99139
100140``` js
101- var postcss = require (' gulp-postcss' );
102-
103- gulp .task (' css' , function () {
104- return gulp .src (' ./src/*.css' ).pipe (
105- postcss ([
106- require (' postcss-extend-rule' )(/* Options */ )
107- ])
108- ).pipe (
109- gulp .dest (' .' )
110- );
111- });
141+ import postcss from ' gulp-postcss' ;
142+ import postcssExtend from ' postcss-extend-rule' ;
143+
144+ gulp .task (' css' , () => gulp .src (' ./src/*.css' ).pipe (
145+ postcss ([
146+ postcssExtend (/* pluginOptions */ )
147+ ])
148+ ).pipe (
149+ gulp .dest (' .' )
150+ ));
112151```
113152
114153#### Grunt
@@ -122,13 +161,15 @@ npm install grunt-postcss --save-dev
122161Use [ PostCSS Extend Rule] in your Gruntfile:
123162
124163``` js
164+ import postcssExtend from ' postcss-extend-rule' ;
165+
125166grunt .loadNpmTasks (' grunt-postcss' );
126167
127168grunt .initConfig ({
128169 postcss: {
129170 options: {
130171 use: [
131- require ( ' postcss-extend-rule ' )( /* Options */ )
172+ postcssExtend ( /* pluginOptions */ )
132173 ]
133174 },
134175 dist: {
@@ -140,6 +181,18 @@ grunt.initConfig({
140181
141182## Options
142183
184+ ### name
185+
186+ The ` name ` option determines the at-rule name being used to extend selectors.
187+ By default, this name is ` extend ` , meaning ` @extend ` rules are parsed.
188+
189+ ``` js
190+ postcssExtend ({ name: ' postcss-extend' })
191+ ```
192+
193+ If the ` name ` option were changed to, say, ` postcss-extend ` , then only
194+ ` @postcss-extend ` at-rules would be parsed.
195+
143196### onFunctionalSelector
144197
145198The ` onFunctionalSelector ` option determines how functional selectors should be
@@ -150,6 +203,14 @@ handled. Its options are:
150203- ` warn ` warns the user whenever it encounters a functional selector
151204- ` throw ` throws an error if ever it encounters a functional selector
152205
206+ ``` js
207+ postcssExtend ({ onFunctionalSelector: ' remove' /* default */ })
208+ ```
209+
210+ ``` pcss
211+ %this-will-be-removed {}
212+ ```
213+
153214### onRecursiveExtend
154215
155216The ` onRecursiveExtend ` option determines how recursive extend at-rules should
@@ -160,6 +221,16 @@ be handled. Its options are:
160221- ` warn ` warns the user whenever it encounters a recursive extend at-rules
161222- ` throw ` throws an error if ever it encounters a recursive extend at-rules
162223
224+ ``` js
225+ postcssExtend ({ onRecursiveExtend: ' remove' /* default */ })
226+ ```
227+
228+ ``` pcss
229+ .this-will-not-extend-itself {
230+ @extend .this-will-not-extend-itself;
231+ }
232+ ```
233+
163234### onUnusedExtend
164235
165236The ` onUnusedExtend ` option determines how an unused extend at-rule should be
@@ -170,16 +241,29 @@ handled. Its options are:
170241- ` warn ` warns the user whenever it encounters an unused extend at-rule
171242- ` throw ` throws an error if ever it encounters an unused extend at-rule
172243
173- [ npm-url ] : https://www.npmjs.com/package/postcss-extend-rule
174- [ npm-img ] : https://img.shields.io/npm/v/postcss-extend-rule.svg
175- [ cli-url ] : https://travis-ci.org/jonathantneal/postcss-extend-rule
244+ ``` js
245+ postcssExtend ({ onUnusedExtend: ' remove' /* default */ })
246+ ```
247+
248+ ``` pcss
249+ main {
250+ @extend .this-selector-does-not-exist-and-will-be-removed;
251+ }
252+ ```
253+
176254[ cli-img ] : https://img.shields.io/travis/jonathantneal/postcss-extend-rule.svg
255+ [ cli-url ] : https://travis-ci.org/jonathantneal/postcss-extend-rule
256+ [ git-img ] : https://img.shields.io/badge/support-chat-blue.svg
177257[ git-url ] : https://gitter.im/postcss/postcss
178- [ git-img ] : https://img.shields.io/badge/chat-gitter-blue.svg
258+ [ npm-img ] : https://img.shields.io/npm/v/postcss-extend-rule.svg
259+ [ npm-url ] : https://www.npmjs.com/package/postcss-extend-rule
260+ [ win-img ] : https://img.shields.io/appveyor/ci/jonathantneal/postcss-extend-rule.svg
261+ [ win-url ] : https://ci.appveyor.com/project/jonathantneal/postcss-extend-rule
179262
180263[ CSS Extend Rules Specification ] : https://jonathantneal.github.io/specs/css-extend-rule/
181264[ Functional Selectors ] : https://jonathantneal.github.io/specs/css-extend-rule/#functional-selector
182265[ Gulp PostCSS ] : https://github.com/postcss/gulp-postcss
183266[ Grunt PostCSS ] : https://github.com/nDmitry/grunt-postcss
184267[ PostCSS ] : https://github.com/postcss/postcss
268+ [ PostCSS Loader ] : https://github.com/postcss/postcss-loader
185269[ PostCSS Extend Rule ] : https://github.com/jonathantneal/postcss-extend-rule
0 commit comments