Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postcss-animation插件发布 #8

Open
zhouwenbin opened this issue Nov 26, 2015 · 6 comments
Open

postcss-animation插件发布 #8

zhouwenbin opened this issue Nov 26, 2015 · 6 comments

Comments

@zhouwenbin
Copy link
Owner

简介

postcss-animation用来帮我们添加动画的关键帧,数据来自animate.css,会按需要生成相应的关键帧,不用导入一大坨样式。

用法

npm install postcss-animation --save-dev

配置

postcss

新建一个postcss.js文件,代码如下

// Dependencies
var fs = require('fs');
var postcss = require('postcss');
var animation = require('postcss-animation');

// CSS to be processed
var css = fs.readFileSync('input.css', 'utf8');

var output = postcss()
  .use(animation())
  .process(css)
  .css

console.log('\n===>Output CSS:\n', output);

在命令行输入node postcss.js执行

grunt

在根目录新建gruntfile.js,代码如下

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    postcss: {
      options: {
        processors: [
          require('postcss-animation')(),
          require('autoprefixer-core')({ browsers: ['> 0%'] }).postcss
        ]
      },
      dist: {
        src: ['src/*.css'],
        dest: 'build/grunt.css'
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-postcss');

  grunt.registerTask('default', ['postcss']);
}

在命令行输入grunt postcss

gulp

在根目录新建gulpfile.js,代码如下

var gulp = require('gulp');
var postcss = require('gulp-postcss');
var animation = require('postcss-animation')
var autoprefixer = require('autoprefixer-core')

gulp.task('default', function () {
    var processors = [
        animation(),
        autoprefixer({ browsers: ['> 0%'] })

    ];
    gulp.src('src/*.css')
        .pipe(postcss(processors))
        .pipe(gulp.dest('build'))
});
gulp.watch('src/*.css', ['default']);

在命令行输入gulp

实例

/*input.css*/
.foo {
  animation-name: bounce;
}
/*output.css*/
.foo {
  animation-name: bounce;
}
@keyframes bounce {
  from, 20%, 53%, 80%, to {
    animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
    transform: translate3d(0,0,0);
  }
  40%, 43% {
    animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
    transform: translate3d(0, -30px, 0);
  }
  70% {
    animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
    transform: translate3d(0, -15px, 0);
  }
  90% {
    transform: translate3d(0,-4px,0);
  }
}

测试用例

test里面是所有的测试用例

$ git clone https://github.com/zhouenbin/postcss-animation.git
$ cd postcss-animation
$ npm install
$ npm test
@yisibl
Copy link

yisibl commented Nov 26, 2015

我觉得不应该单独把 animate.css 内容放到 JS 文件中,应该直接读取这个 CSS。

@zhouwenbin
Copy link
Owner Author

@yisibl 直接读css也可以,第一次写插件,api还不熟悉

@yisibl
Copy link

yisibl commented Nov 26, 2015

直接读取,方便修改及维护。

还是很赞的,你去官方仓库提交一个 PR,加入到插件列表中。

@zhouwenbin
Copy link
Owner Author

@yisibl 已经提交了,参考了很多插件,照猫画虎弄了一个,还是要多练练手。

@shikelong
Copy link

请问atom的cssnext的插件为什么删除了啊。 谢谢。

@zhouwenbin
Copy link
Owner Author

@shikelong 编译出了问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants