gulp-polymin2
raw JSON → 1.0.2 verified Fri May 01 auth: no javascript deprecated
A Gulp plugin to optimize Polymer 2 components by minifying HTML, JavaScript, and CSS. It uses Babel for JS transpilation (with presets like 'babili' or 'es2015'), cssclean for CSS minification, and integrates uglify-js for JS minification. Current stable version is 1.0.2. Release cadence is low; last update was around 2017. Useful for legacy Polymer 2 builds but no longer actively maintained.
Common errors
error Error: Cannot find module 'cssclean' ↓
cause cssclean is not included as a dependency of gulp-polymin2.
fix
Install cssclean separately: npm install --save-dev cssclean.
error TypeError: polymin is not a function ↓
cause Using default import syntax (ESM) with CommonJS module.
fix
Use require: var polymin = require('gulp-polymin2');
error gulp-polymin2: option 'babelPressets' not recognized ↓
cause Misspelled option name; actual is 'babelPresets'.
fix
Use babelPresets instead of babelPressets.
Warnings
deprecated Package is deprecated; no longer maintained. Use modern tools like polymer-build or webpack. ↓
fix Migrate to polymer-cli or @polymer/build.
gotcha Option name 'babelPressets' is misspelled (should be 'babelPresets'). Using 'babelPressets' will be ignored. ↓
fix Use correct option: { babelPresets: 'es2015' }.
gotcha If jsOptions is null, uglify-js is not applied. Some expect minification by default. ↓
fix Explicitly set jsOptions to {} to enable uglify with defaults.
breaking Requires Babel 6; incompatible with Babel 7+. ↓
fix Use babel-core@^6.0.0 or switch to a modern tool.
Install
npm install gulp-polymin2 yarn add gulp-polymin2 pnpm add gulp-polymin2 Imports
- polymin wrong
import polymin from 'gulp-polymin2';correctvar polymin = require('gulp-polymin2'); - polymin (default) wrong
const { polimin } = require('gulp-polymin2');correctconst polymin = require('gulp-polymin2'); - gulp.pipe wrong
.pipe(new polymin(options))correct.pipe(polymin(options))
Quickstart
var gulp = require('gulp');
var polymin = require('gulp-polymin2');
gulp.task('compress', function() {
return gulp.src('src/*.html')
.pipe(polymin({
babelPressets: 'es2015',
cssOptions: {},
jsOptions: null
}))
.pipe(gulp.dest('dist'));
});