diff --git a/index.js b/index.js index 1847f3b..d0ead53 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +var postcss = require("postcss") /** * 匹配自定义选择器 * :--foo @@ -8,20 +9,21 @@ var re_CUSTOM_SELECTOR = /([^,]*?)(:-{2,}[\w-]+)(.*)/g /** * 暴露插件 */ -module.exports = customSelector +module.exports = postcss.plugin("postcss-custom-selectors", function(options) { + /** + * 插件配置 + */ + options = options || {} + var extensions = options.extensions || {} + var line_break = '\n' + var map = {} + var toRemove = [] + var customSelectors = {} -/** - * 读取和替换自定义选择器 - */ -function customSelector(options) { + /** + * 读取和替换自定义选择器 + */ return function(styles) { - options = options || {} - var extensions = options.extensions || {} - var line_break = '\n' - var map = {} - var toRemove = [] - var customSelectors = {} - // 读取自定义选择器 styles.eachAtRule(function(rule) { if (rule.name !== "custom-selector") { @@ -80,4 +82,4 @@ function customSelector(options) { }) } -} +}) diff --git a/package.json b/package.json index da70c74..c909227 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "postcss", "postcss-plugins", "selector", - "custom-selector" + "custom-selector", + "custom selector" ], "author": "yisi", "license": "MIT", @@ -23,8 +24,8 @@ "index.js" ], "devDependencies": { - "postcss": "^3.0.0", - "tape": "^3.0.0" + "postcss": "^4.1.11", + "tape": "^4.0.0" }, "scripts": { "test": "tape test" diff --git a/test/index.js b/test/index.js index 1b466a0..7816c0e 100644 --- a/test/index.js +++ b/test/index.js @@ -12,11 +12,11 @@ function compareFixtures(t, name, msg, opts, postcssOpts) { postcssOpts = postcssOpts || {} //input postcssOpts.from = filename("fixtures/" + name + "/input") - console.log('postcssOpts.from', postcssOpts.from) opts = opts || {} var actual = postcss() .use(plugin(opts)) - .process(read(postcssOpts.from), postcssOpts).css + .process(read(postcssOpts.from), postcssOpts) + .css //output var output = read(filename("fixtures/" + name + "/output")) //actual