├── .editorconfig ├── .gitattributes ├── .github ├── funding.yml ├── security.md └── workflows │ └── main.yml ├── .gitignore ├── .npmrc ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/funding.yml: -------------------------------------------------------------------------------- 1 | github: sindresorhus 2 | open_collective: sindresorhus 3 | tidelift: npm/gulp-autoprefixer 4 | custom: https://sindresorhus.com/donate 5 | -------------------------------------------------------------------------------- /.github/security.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. 4 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 20 14 | - 18 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: actions/setup-node@v4 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | - run: npm install 21 | - run: npm test 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import {Buffer} from 'node:buffer'; 2 | import applySourceMap from 'vinyl-sourcemaps-apply'; 3 | import autoprefixer from 'autoprefixer'; 4 | import postcss from 'postcss'; 5 | import {gulpPlugin} from 'gulp-plugin-extras'; 6 | 7 | export default function gulpAutoprefixer(options) { 8 | return gulpPlugin('gulp-autoprefixer', async file => { 9 | try { 10 | const result = await postcss(autoprefixer(options)).process(file.contents.toString(), { 11 | map: file.sourceMap ? {annotation: false} : false, 12 | from: file.path, 13 | to: file.path, 14 | }); 15 | 16 | file.contents = Buffer.from(result.css); 17 | 18 | if (result.map && file.sourceMap) { 19 | const map = result.map.toJSON(); 20 | map.file = file.relative; 21 | map.sources = map.sources.map(() => file.relative); 22 | applySourceMap(file, map); 23 | } 24 | 25 | const warnings = result.warnings(); 26 | if (warnings.length > 0) { 27 | console.log('gulp-autoprefixer:', '\n ' + warnings.join('\n ')); 28 | } 29 | 30 | return file; 31 | } catch (error) { 32 | if (error.name === 'CssSyntaxError') { 33 | error.message += error.showSourceCode(); 34 | error.isPresentable = true; 35 | } 36 | 37 | throw error; 38 | } 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-autoprefixer", 3 | "version": "9.0.0", 4 | "description": "Prefix CSS", 5 | "license": "MIT", 6 | "repository": "sindresorhus/gulp-autoprefixer", 7 | "funding": "https://github.com/sponsors/sindresorhus", 8 | "author": { 9 | "name": "Sindre Sorhus", 10 | "email": "sindresorhus@gmail.com", 11 | "url": "https://sindresorhus.com" 12 | }, 13 | "type": "module", 14 | "exports": "./index.js", 15 | "engines": { 16 | "node": ">=18" 17 | }, 18 | "scripts": { 19 | "test": "xo && ava" 20 | }, 21 | "files": [ 22 | "index.js" 23 | ], 24 | "keywords": [ 25 | "gulpplugin", 26 | "autoprefixer", 27 | "postcss", 28 | "css", 29 | "prefix", 30 | "prefixes", 31 | "stylesheet", 32 | "preprocess", 33 | "postcss-runner" 34 | ], 35 | "dependencies": { 36 | "autoprefixer": "^10.4.16", 37 | "gulp-plugin-extras": "^0.2.2", 38 | "postcss": "^8.4.31", 39 | "vinyl-sourcemaps-apply": "^0.2.1" 40 | }, 41 | "devDependencies": { 42 | "ava": "^5.3.1", 43 | "gulp-sourcemaps": "^3.0.0", 44 | "p-event": "^6.0.0", 45 | "vinyl": "^3.0.0", 46 | "xo": "^0.56.0" 47 | }, 48 | "peerDependencies": { 49 | "gulp": ">=4" 50 | }, 51 | "peerDependenciesMeta": { 52 | "gulp": { 53 | "optional": true 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # gulp-autoprefixer 2 | 3 | > Prefix CSS with [Autoprefixer](https://github.com/postcss/autoprefixer) 4 | 5 | *Issues with the output should be reported on the Autoprefixer [issue tracker](https://github.com/postcss/autoprefixer/issues).* 6 | 7 | ## Install 8 | 9 | ```sh 10 | npm install --save-dev gulp-autoprefixer 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```js 16 | import gulp from 'gulp'; 17 | import autoprefixer from 'gulp-autoprefixer'; 18 | 19 | export default () => ( 20 | gulp.src('src/app.css') 21 | .pipe(autoprefixer({ 22 | cascade: false 23 | })) 24 | .pipe(gulp.dest('dist')) 25 | ); 26 | ``` 27 | 28 | ## API 29 | 30 | ### autoprefixer(options?) 31 | 32 | #### options 33 | 34 | Type: `object` 35 | 36 | See the Autoprefixer [options](https://github.com/postcss/autoprefixer#options). 37 | 38 | ## Source Maps 39 | 40 | Use [gulp-sourcemaps](https://github.com/gulp-sourcemaps/gulp-sourcemaps) like this: 41 | 42 | ```js 43 | import gulp from 'gulp'; 44 | import sourcemaps from 'gulp-sourcemaps'; 45 | import concat from 'gulp-concat'; 46 | import autoprefixer from 'gulp-autoprefixer'; 47 | 48 | export default () => ( 49 | gulp.src('src/**/*.css') 50 | .pipe(sourcemaps.init()) 51 | .pipe(autoprefixer()) 52 | .pipe(concat('all.css')) 53 | .pipe(sourcemaps.write('.')) 54 | .pipe(gulp.dest('dist')) 55 | ); 56 | ``` 57 | 58 | ## Tip 59 | 60 | If you use other PostCSS based tools, like `cssnano`, you may want to run them together using [`gulp-postcss`](https://github.com/postcss/autoprefixer#gulp) instead of `gulp-autoprefixer`. It will be faster, as the CSS is parsed only once for all PostCSS based tools, including Autoprefixer. 61 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import {Buffer} from 'node:buffer'; 2 | import path from 'node:path'; 3 | import {fileURLToPath} from 'node:url'; 4 | import test from 'ava'; 5 | import Vinyl from 'vinyl'; 6 | import sourceMaps from 'gulp-sourcemaps'; 7 | import {pEvent} from 'p-event'; 8 | import autoprefixer from './index.js'; 9 | 10 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); 11 | 12 | test('autoprefix CSS', async t => { 13 | const stream = autoprefixer(); 14 | const data = pEvent(stream, 'data'); 15 | 16 | stream.end(new Vinyl({ 17 | cwd: __dirname, 18 | base: path.join(__dirname, 'fixture'), 19 | path: path.join(__dirname, 'fixture', 'fixture.css'), 20 | contents: Buffer.from('::placeholder {\n\tcolor: gray;\n}'), 21 | })); 22 | 23 | const file = await data; 24 | t.regex(file.contents.toString(), /-/); 25 | t.is(file.relative, 'fixture.css'); 26 | }); 27 | 28 | test('generate source maps', async t => { 29 | const init = sourceMaps.init(); 30 | const write = sourceMaps.write(); 31 | const data = pEvent(write, 'data'); 32 | 33 | init 34 | .pipe(autoprefixer({ 35 | overrideBrowserslist: ['Firefox ESR'], 36 | })) 37 | .pipe(write); 38 | 39 | init.end(new Vinyl({ 40 | cwd: __dirname, 41 | base: path.join(__dirname, 'fixture'), 42 | path: path.join(__dirname, 'fixture', 'fixture.css'), 43 | contents: Buffer.from('a {\n\tdisplay: flex;\n}'), 44 | sourceMap: '', 45 | })); 46 | 47 | const file = await data; 48 | t.is(file.sourceMap.mappings, 'AAAA;CACC,aAAa;AACd'); 49 | const contents = file.contents.toString(); 50 | t.regex(contents, /flex/); 51 | t.regex(contents, /sourceMappingURL=data:application\/json;charset=utf8;base64/); 52 | }); 53 | 54 | test('read upstream source maps', async t => { 55 | const stream = autoprefixer(); 56 | const finalStream = stream.pipe(sourceMaps.write()); 57 | const data = pEvent(finalStream, 'data'); 58 | 59 | const testFile = new Vinyl({ 60 | cwd: __dirname, 61 | base: path.join(__dirname, 'fixture'), 62 | path: path.join(__dirname, 'fixture', 'fixture.css'), 63 | contents: Buffer.from('a {\n\tdisplay: flex;\n}\n'), 64 | }); 65 | 66 | testFile.sourceMap = { 67 | version: 3, 68 | sources: ['imported.less'], 69 | names: [], 70 | mappings: 'AAAA;EACC,aAAA', 71 | file: 'fixture.css', 72 | sourcesContent: ['a {\n display: flex;\n}\n'], 73 | }; 74 | 75 | stream.end(testFile); 76 | 77 | const file = await data; 78 | 79 | const sourcesContent = [ 80 | 'a {\n display: flex;\n}\n', 81 | 'a {\n\tdisplay: flex;\n}\n', 82 | ]; 83 | 84 | t.is(file.sourceMap.sourcesContent[0], sourcesContent[0]); 85 | t.is(file.sourceMap.sourcesContent[1], sourcesContent[1]); 86 | }); 87 | --------------------------------------------------------------------------------