1
- var assign = require ( 'object-assign-deep' ) ;
2
- var autoprefixer = require ( 'autoprefixer' ) ;
3
- var bemLinter = require ( 'postcss-bem-linter' ) ;
4
- var cssnano = require ( 'cssnano' ) ;
5
- var difference = require ( 'lodash.difference' ) ;
6
- var encapsulationPlugins = require ( './encapsulation' ) ;
7
- var isEmpty = require ( 'lodash.isempty' ) ;
8
- var postcss = require ( 'postcss' ) ;
9
- var postcssEasyImport = require ( 'postcss-easy-import' ) ;
10
- var reporter = require ( 'postcss-reporter' ) ;
11
- var stylelint = require ( 'stylelint' ) ;
12
- var stylelintConfigSuit = require ( 'stylelint-config-suitcss' ) ;
1
+ 'use strict' ;
2
+
3
+ const assign = require ( 'object-assign-deep' ) ;
4
+ const autoprefixer = require ( 'autoprefixer' ) ;
5
+ const bemLinter = require ( 'postcss-bem-linter' ) ;
6
+ const cssnano = require ( 'cssnano' ) ;
7
+ const difference = require ( 'lodash.difference' ) ;
8
+ const encapsulationPlugins = require ( './encapsulation' ) ;
9
+ const isEmpty = require ( 'lodash.isempty' ) ;
10
+ const postcssEasyImport = require ( 'postcss-easy-import' ) ;
11
+ const reporter = require ( 'postcss-reporter' ) ;
12
+ const stylelint = require ( 'stylelint' ) ;
13
+ const stylelintConfigSuit = require ( 'stylelint-config-suitcss' ) ;
14
+ let postcss = require ( 'postcss' ) ; // eslint-disable-line prefer-const
13
15
14
16
module . exports = preprocessor ;
15
17
@@ -18,7 +20,7 @@ module.exports = preprocessor;
18
20
* and options to PostCSS plugins
19
21
*/
20
22
21
- var defaults = {
23
+ const defaults = {
22
24
debug : identity ,
23
25
lint : true ,
24
26
minify : false ,
@@ -31,8 +33,8 @@ var defaults = {
31
33
'postcss-apply'
32
34
] ,
33
35
autoprefixer : {
34
- browsers : ' > 1%, last 2 versions, safari > 6, ie > 9, ' +
35
- ' ios > 6, android > 4.3, samsung > 3, chromeandroid > 50'
36
+ browsers : ` > 1%, last 2 versions, safari > 6, ie > 9,
37
+ ios > 6, android > 4.3, samsung > 3, chromeandroid > 50`
36
38
} ,
37
39
'postcss-easy-import' : {
38
40
transform : identity ,
@@ -62,14 +64,14 @@ var defaults = {
62
64
function preprocessor ( css , options , filename ) {
63
65
options = mergeOptions ( options ) ;
64
66
65
- var plugins = [
67
+ let plugins = [
66
68
postcssEasyImport ( options [ 'postcss-easy-import' ] )
67
69
] ;
68
70
69
71
plugins = plugins . concat (
70
- options . use . map ( function ( p ) {
71
- var plugin = require ( p ) ;
72
- var settings = options [ p ] ;
72
+ options . use . map ( p => {
73
+ const plugin = require ( p ) ;
74
+ const settings = options [ p ] ;
73
75
return settings ? plugin ( settings ) : plugin ;
74
76
} )
75
77
) ;
@@ -88,15 +90,14 @@ function preprocessor(css, options, filename) {
88
90
reporter ( options [ 'postcss-reporter' ] )
89
91
] ) ;
90
92
91
- var processor = postcss ( options . debug ( plugins ) ) ;
93
+ const processor = postcss ( options . debug ( plugins ) ) ;
92
94
93
95
if ( options . minify ) {
94
96
processor . use ( cssnano ( options . cssnano ) ) ;
95
97
}
96
98
97
- return lintFile ( css , options , filename ) . then ( function ( result ) {
98
- return processor . process ( result . css , options . postcss ) ;
99
- } ) ;
99
+ return lintFile ( css , options , filename )
100
+ . then ( result => processor . process ( result . css , options . postcss ) ) ;
100
101
}
101
102
102
103
/**
@@ -108,33 +109,31 @@ function preprocessor(css, options, filename) {
108
109
109
110
function mergeOptions ( options ) {
110
111
options = options || { } ;
111
- var mergedOpts = assign ( { } , defaults , options ) ;
112
- var easyImportOpts = mergedOpts [ 'postcss-easy-import' ] ;
113
- var origTransform = easyImportOpts . transform ;
114
- var origOnImport = easyImportOpts . onImport ;
112
+ const mergedOpts = assign ( { } , defaults , options ) ;
113
+ const easyImportOpts = mergedOpts [ 'postcss-easy-import' ] ;
114
+ const origTransform = easyImportOpts . transform ;
115
+ const origOnImport = easyImportOpts . onImport ;
115
116
116
117
if ( mergedOpts . root ) {
117
118
easyImportOpts . root = mergedOpts . root ;
118
119
}
119
120
120
- easyImportOpts . transform = function ( css , filename ) {
121
- var transformedCss = origTransform ( css ) ;
122
- return lintFile ( transformedCss , mergedOpts , filename ) . then ( function ( result ) {
123
- return result . css ;
124
- } ) ;
121
+ easyImportOpts . transform = ( css , filename ) => {
122
+ const transformedCss = origTransform ( css ) ;
123
+ return lintFile ( transformedCss , mergedOpts , filename ) . then ( result => result . css ) ;
125
124
} ;
126
125
127
- easyImportOpts . onImport = function ( importedFiles ) {
126
+ easyImportOpts . onImport = importedFiles => {
128
127
updateWatchTaskFiles ( importedFiles ) ;
129
128
origOnImport ( importedFiles ) ;
130
129
} ;
131
130
132
131
// Allow additional plugins to be merged with the defaults
133
132
// but remove any duplicates so that it respects the new order
134
133
if ( ! isEmpty ( options . use ) ) {
135
- var plugins = difference ( mergedOpts . use , options . use ) ;
134
+ const plugins = difference ( mergedOpts . use , options . use ) ;
136
135
// Remove core plugins. Can't reorder them
137
- var userPlugins = difference ( options . use , [
136
+ const userPlugins = difference ( options . use , [
138
137
'postcss-easy-import' ,
139
138
'autoprefixer' ,
140
139
'postcss-reporter'
@@ -153,7 +152,7 @@ function mergeOptions(options) {
153
152
* @returns {Promise } Used by postcss-import transform
154
153
*/
155
154
function lintFile ( css , options , filename ) {
156
- var processor = postcss ( ) ;
155
+ const processor = postcss ( ) ;
157
156
158
157
if ( options . lint ) {
159
158
processor
@@ -170,9 +169,7 @@ function lintFile(css, options, filename) {
170
169
. use ( reporter ( options [ 'postcss-reporter' ] ) ) ;
171
170
172
171
if ( isPromise ( css ) ) {
173
- return css . then ( function ( css ) { // eslint-disable-line no-shadow
174
- return processor . process ( css , options . postcss ) ;
175
- } ) ;
172
+ return css . then ( css => processor . process ( css , options . postcss ) ) ; // eslint-disable-line no-shadow
176
173
}
177
174
178
175
return processor . process ( css , options . postcss ) ;
0 commit comments