mirror of
https://github.com/hanzoai/postcss.git
synced 2026-09-24 17:01:56 +00:00
34 lines
851 B
JavaScript
34 lines
851 B
JavaScript
import LazyResult from './lazy-result';
|
|
|
|
export default class Processor {
|
|
constructor(plugins = []) {
|
|
this.plugins = plugins.map( i => this.normalize(i) );
|
|
}
|
|
|
|
use(plugin) {
|
|
plugin = this.normalize(plugin);
|
|
if ( typeof plugin === 'object' && Array.isArray(plugin.plugins) ) {
|
|
this.plugins = this.plugins.concat(plugin.plugins);
|
|
} else {
|
|
this.plugins.push(plugin);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
process(css, opts = { }) {
|
|
return new LazyResult(this, css, opts);
|
|
}
|
|
|
|
normalize(plugin) {
|
|
let type = typeof plugin;
|
|
if ( (type === 'object' || type === 'function') && plugin.postcss ) {
|
|
return plugin.postcss;
|
|
} else {
|
|
return plugin;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
Processor.prototype.version = require('../package').version;
|