├── .editorconfig ├── .gitignore ├── .jshintrc ├── .travis.yml ├── LICENSE.md ├── README.md ├── cli.js ├── index.js ├── package.json └── test ├── fixtures ├── input.css └── output.css └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": true, 7 | "immed": true, 8 | "newcap": true, 9 | "noarg": true, 10 | "undef": true, 11 | "unused": "vars", 12 | "strict": true 13 | } 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | 4 | node_js: 5 | - 'iojs' 6 | - '0.12' 7 | - '0.11' 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 John Otander 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # postcss-remove-prefixes [![Build Status](https://secure.travis-ci.org/johnotander/postcss-remove-prefixes.png?branch=master)](https://travis-ci.org/johnotander/postcss-remove-prefixes) 2 | 3 | Remove pesky vendor prefixes from your source CSS files. This ensures that your prebuilt CSS is as terse and concise as possible. 4 | 5 | Though, please use [`autoprefixer`](https://github.com/postcss/autoprefixer) as part of your build process to ensure proper browser support. 6 | 7 | ## Installation 8 | 9 | ```bash 10 | npm install --save postcss-remove-prefixes 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```javascript 16 | var postcss = require('postcss') 17 | var removePrefixes = require('postcss-remove-prefixes') 18 | 19 | postcss([ removePrefixes() ]).process(myCss).css 20 | ``` 21 | 22 | #### Input 23 | 24 | ```css 25 | .flex { 26 | display: -webkit-flex; 27 | display: -moz-flex; 28 | display: flex; 29 | -webkit-flex: 1; 30 | flex: 1; 31 | } 32 | ``` 33 | 34 | #### Output 35 | 36 | ```css 37 | .flex { 38 | display: flex; 39 | flex: 1; 40 | } 41 | ``` 42 | 43 | Note: It is recommended that you use this plugin with [`postcss-unprefix`](https://github.com/yisibl/postcss-unprefix) in case you are missing the unprefixed declaration in your source CSS. 44 | 45 | ### CLI 46 | 47 | ```sh 48 | npm i -g postcss-remove-prefixes 49 | remove-prefixes -h 50 | remove-prefixes mycss.css 51 | remove-prefixes input.css output.css 52 | ``` 53 | 54 | ## License 55 | 56 | MIT 57 | 58 | ## Contributing 59 | 60 | 1. Fork it 61 | 2. Create your feature branch (`git checkout -b my-new-feature`) 62 | 3. Commit your changes (`git commit -am 'Add some feature'`) 63 | 4. Push to the branch (`git push origin my-new-feature`) 64 | 5. Create new Pull Request 65 | 66 | Crafted with <3 by John Otander ([@4lpine](https://twitter.com/4lpine)). 67 | 68 | *** 69 | 70 | > This package was initially generated with [yeoman](http://yeoman.io) and the [p generator](https://github.com/johnotander/generator-p.git). 71 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var fs = require('fs') 4 | var meow = require('meow') 5 | var postcss = require('postcss') 6 | var isBlank = require('is-blank') 7 | var removePrefixes = require('./') 8 | 9 | var cli = meow({ 10 | help: [ 11 | 'Usage', 12 | ' remove-prefixes []' 13 | ] 14 | }) 15 | 16 | var input = cli.input[0] 17 | var output = cli.input[1] || input 18 | 19 | if (isBlank(input)) { 20 | console.log(cli.help) 21 | } else { 22 | var inputCss = fs.readFileSync(input, 'utf8') 23 | fs.writeFileSync(output, postcss([ removePrefixes() ]).process(inputCss).css) 24 | } 25 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var postcss = require('postcss') 4 | var isVendorPrefixed = require('is-vendor-prefixed') 5 | 6 | module.exports = postcss.plugin('postcss-remove-prefixes', function (options) { 7 | if (!options) { 8 | options = { 9 | ignore: [] 10 | } 11 | } 12 | 13 | if (!Array.isArray(options.ignore)) { 14 | throw TypeError("options.ignore must be an array") 15 | } 16 | 17 | var ignore = options.ignore.map(function (value) { 18 | if (typeof value === 'string') { 19 | return new RegExp(value + '$', 'i') 20 | } else if (value instanceof RegExp) { 21 | return value 22 | } else { 23 | throw TypeError('options.ignore values can either be a string or a regular expression') 24 | } 25 | }) 26 | 27 | return function removePrefixes(root, result) { 28 | root.walkDecls(function (declaration) { 29 | if (isVendorPrefixed(declaration.prop) || isVendorPrefixed(declaration.value)) { 30 | var isIgnored = false; 31 | 32 | for (var i = 0; i < ignore.length; ++i) { 33 | var value = ignore[i]; 34 | 35 | if (value.test(declaration.prop)) { 36 | isIgnored = true; 37 | break; 38 | } 39 | } 40 | 41 | if (!isIgnored) { 42 | declaration.remove() 43 | } 44 | } 45 | }) 46 | } 47 | }) 48 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "postcss-remove-prefixes", 3 | "description": "Remove CSS vendor prefixes from your source.", 4 | "author": "John Otander", 5 | "version": "1.2.0", 6 | "main": "index.js", 7 | "bin": { 8 | "remove-prefixes": "cli.js" 9 | }, 10 | "directories": { 11 | "test": "test" 12 | }, 13 | "scripts": { 14 | "test": "mocha test" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "https://github.com/johnotander/postcss-remove-prefixes.git" 19 | }, 20 | "keywords": [ 21 | "css", 22 | "postcss", 23 | "postcss-plugin", 24 | "prefix", 25 | "vendor" 26 | ], 27 | "license": "MIT", 28 | "bugs": { 29 | "url": "https://github.com/johnotander/postcss-remove-prefixes/issues" 30 | }, 31 | "homepage": "https://github.com/johnotander/postcss-remove-prefixes", 32 | "dependencies": { 33 | "is-blank": "0.0.1", 34 | "is-vendor-prefixed": "0.0.1", 35 | "meow": "^3.3.0", 36 | "postcss": "^5.0.12" 37 | }, 38 | "devDependencies": { 39 | "mocha": "*" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/fixtures/input.css: -------------------------------------------------------------------------------- 1 | /* 2 | * display: -moz-flex; 3 | */ 4 | .flex { 5 | display: -webkit-flex; 6 | display: -moz-flex; 7 | display: flex; 8 | -webkit-flex: 1; 9 | -webkit-font-smoothing: antialiased; 10 | -webkit-transform: none; 11 | -moz-transform: none; 12 | flex: 1; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /test/fixtures/output.css: -------------------------------------------------------------------------------- 1 | /* 2 | * display: -moz-flex; 3 | */ 4 | .flex { 5 | display: flex; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-transform: none; 8 | flex: 1; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var fs = require('fs') 4 | var assert = require('assert') 5 | var postcss = require('postcss') 6 | var postcssRemovePrefixes = require('..') 7 | 8 | describe('postcss-remove-prefixes', function () { 9 | 10 | it('should remove vendor prefixes', function () { 11 | test('input.css', 'output.css') 12 | }) 13 | }) 14 | 15 | function fixture (name) { 16 | return fs.readFileSync('test/fixtures/' + name, 'utf8') 17 | } 18 | 19 | function test (input, output) { 20 | assert.deepEqual( 21 | postcss([ postcssRemovePrefixes({ ignore: [ "font-smoothing", /^-moz-transform$/i ] }) ]) 22 | .process(fixture(input)).css, 23 | fixture(output) 24 | ) 25 | } 26 | --------------------------------------------------------------------------------