@@ -13,8 +13,8 @@ const WARNING =
13
13
' Replace Autoprefixer `browsers` option to Browserslist config.\n' +
14
14
' Use `browserslist` key in `package.json` or `.browserslistrc` file.\n' +
15
15
'\n' +
16
- ' Using `browsers` option can cause errors. Browserslist config \n' +
17
- ' can be used for Babel, Autoprefixer, postcss-normalize and other tools.\n' +
16
+ ' Using `browsers` option can cause errors. Browserslist config can \n' +
17
+ ' be used for Babel, Autoprefixer, postcss-normalize and other tools.\n' +
18
18
'\n' +
19
19
' If you really need to use option, rename it to `overrideBrowserslist`.\n' +
20
20
'\n' +
@@ -48,7 +48,7 @@ function timeCapsule (result, prefixes) {
48
48
)
49
49
}
50
50
51
- module . exports = postcss . plugin ( 'autoprefixer' , ( ...reqs ) => {
51
+ module . exports = ( ...reqs ) => {
52
52
let options
53
53
if ( reqs . length === 1 && isPlainObject ( reqs [ 0 ] ) ) {
54
54
options = reqs [ 0 ]
@@ -111,33 +111,40 @@ module.exports = postcss.plugin('autoprefixer', (...reqs) => {
111
111
return cache [ key ]
112
112
}
113
113
114
- function plugin ( css , result ) {
115
- let prefixes = loadPrefixes ( {
116
- from : css . source && css . source . input . file ,
117
- env : options . env
118
- } )
119
- timeCapsule ( result , prefixes )
120
- if ( options . remove !== false ) {
121
- prefixes . processor . remove ( css , result )
122
- }
123
- if ( options . add !== false ) {
124
- prefixes . processor . add ( css , result )
125
- }
126
- }
127
-
128
- plugin . options = options
129
-
130
- plugin . browsers = reqs
114
+ return {
115
+ postcssPlugin : 'autoprefixer' ,
116
+
117
+ prepare ( result ) {
118
+ let prefixes = loadPrefixes ( {
119
+ from : result . opts . from ,
120
+ env : options . env
121
+ } )
122
+
123
+ return {
124
+ Root ( root ) {
125
+ timeCapsule ( result , prefixes )
126
+ if ( options . remove !== false ) {
127
+ prefixes . processor . remove ( root , result )
128
+ }
129
+ if ( options . add !== false ) {
130
+ prefixes . processor . add ( root , result )
131
+ }
132
+ }
133
+ }
134
+ } ,
131
135
132
- plugin . info = function ( opts ) {
133
- opts = opts || { }
134
- opts . from = opts . from || process . cwd ( )
136
+ info ( opts ) {
137
+ opts = opts || { }
138
+ opts . from = opts . from || process . cwd ( )
139
+ return info ( loadPrefixes ( opts ) )
140
+ } ,
135
141
136
- return info ( loadPrefixes ( opts ) )
142
+ options,
143
+ browsers : reqs
137
144
}
145
+ }
138
146
139
- return plugin
140
- } )
147
+ module . exports . postcss = true
141
148
142
149
/**
143
150
* Autoprefixer data
0 commit comments