我已经去了stylelint网站,github并通过npm在本地下载。 stylelint网站建议我创建自己的插件,我应该使用这种格式:
var myPluginRule = stylelint.createPlugin(ruleName, function(primaryOption, secondaryOptionObject) {
return function(postcssRoot, postcssResult) {
var validOptions = stylelint.utils.validateOptions(postcssResult, ruleName, { .. })
if (!validOptions) { return }
// ... some logic ...
stylelint.utils.report({ .. })
}
})
当我在stylelint的npm文件夹中执行'find'时,我找不到任何使用此格式的示例。任何人都可以建议一个关于创建自己的插件的非常好的教程吗?
感谢
答案 0 :(得分:2)
1)先决条件:
import { Config } from 'ionic-angular';
@NgModule({})
class AppModule {
constructor(private config: Config) {
this.config.setTransition('fade-transition', FadeTransition);
}
}
2)在./scss/myfile.scss
创建一些scss文件体{背景:红色;}
3)创建./gulpfile.js
$ npm init
$ npm install gulp stylelint gulp-style-lint --save-dev
4)创建./stylelintCustom/index.js
var gulp = require('gulp');
var gulpStylelint = require('gulp-stylelint');
gulp.task('stylelint',function(){
return gulp
.src('./scss/*.scss')
.pipe(
gulpStylelint({
reporters: [
{formatter: 'string', console: true}
]
})
);
})
确定命名ruleName:“plugins / plugin”。即steves / steverule1等。
5)一定要创建stylelintCustom / package.json
var stylelint = require("stylelint");
var ruleName = "steves/steve1";
var messages = stylelint.utils.ruleMessages(ruleName, {
rejected: 'steve rejects this',
});
module.exports = stylelint.createPlugin(ruleName, function(max, options) {
return function(root, result) {
// to access the variable for the whole of this file scss =
console.log(root.source.input);
// apply rules now...
// run reporter to output
}
});
module.exports.ruleName = ruleName;
module.exports.messages = messages;
6)创建:stylelint.rc
{
"name": "stylelint-steves-steve1",
"version": "0.0.1",
"main": "index.js",
"devDependencies": {
"stylelint": "~2.6.0"
},
"engines": {
"node": ">=0.10.0"
}
}
7)运行gulp
{
"plugins": [
"./stylelintCustom/index.js"
],
"rules": {
"steves/steve1": true
}
}
将输出scss,因此你可以运行你需要的任何js,正则表达式。
答案 1 :(得分:1)
有关现有规则如何在stylelint中工作的参考,您可以访问:
yourproject / node_modules / stylelint / DIST /规则/ *