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

How to minify the script? #27

Open
verlok opened this issue Aug 2, 2018 · 1 comment
Open

How to minify the script? #27

verlok opened this issue Aug 2, 2018 · 1 comment

Comments

@verlok
Copy link

verlok commented Aug 2, 2018

Hey,
how can I minify the script using uglify or other similar?

I'm currently doing:

gulp.task("default", function() {
	process.env.NODE_ENV = "release";
	return (
		gulp.
			src("./src/lazyload.js").
			pipe(sourcemaps.init()).
			// ----------- linting --------------
			pipe(eslint()).
			pipe(eslint.format()).
			pipe(eslint.failAfterError()). // --> failing if errors
			// ----------- rolling up --------------
			pipe(rollup({ plugins: [babel()] }, "umd")).
			pipe(sourcemaps.write("")).
			pipe(gulp.dest(destFolder)). // --> writing not uglified
	);
});

But if I try to add the following lines afterwards, the code I get in destFolder is ES6 code.

			pipe(uglify()).
			pipe(rename("lazyload.min.js")).
			pipe(gulp.dest(destFolder)) // --> writing uglified

What am I doing wrong?

@ekfuhrmann
Copy link

ekfuhrmann commented Nov 15, 2018

I know this has been open for awhile, but there are rollup plugins for minifying.

If you are using es5 you can use the following plugin, or if you're using es6 you can use this plugin.

Simply add the plugin to your rollup plugins option and you should be good to go.

Example:

gulp.task('scripts', () => {
  return gulp
    .src('main.js')
    .pipe(sourcemaps.init())
    .pipe(rollup({ plugins: [uglify(), babel()] }, { format: 'cjs' }))
    .pipe(sourcemaps.write(''))
    .pipe(gulp.dest('dist'));
});

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

2 participants