uglifyjs2

How to run UglifyJS2 without Node.JS

安稳与你 提交于 2020-02-21 13:00:08
问题 Anyway to run UglifyJS2 without node.js? Say I would like to run it in a JVM process using JavaScript script engine. How to do that? 回答1: I saw mishoo answered you https://github.com/mishoo/UglifyJS2/issues/122 Two possible ways: run uglifyjs --self to get a build of UglifyJS that you can load in a browser (or in any JS environment) and you can use the API described here. load in your environment all files in the lib/ directory (load utils.js and ast.js first, the others can come in whatever

UglifyJS throws unexpected token: keyword (const) with node_modules

北城余情 提交于 2019-12-30 00:42:34
问题 A small project I started make use a node module (installed via npm ) that declares const variables. Running and testing this project is well, but browserify fails when UglifyJS is executed. Unexpected token: keyword (const) Here is a generic Gulp file that I have successfully been using for a few other past projects without this issue (i.e. without that particular node module). gulpfile.js 'use strict'; const browserify = require('browserify'); const gulp = require('gulp'); const source =

How to minify multiple Javascript files in a folder with UglifyJS?

喜你入骨 提交于 2019-12-17 21:41:23
问题 Hello I'm using uglifyJs to minify my javascript files, it's working well with one file at a time, what I'm loking for is to minify all the javascript files present in a folder called JS into a folder called JSM, to be clear I have 2 files inside my JS folder called test1.js and test2.js and I want to run uglify against that folder and generate test1.min.js and test2.min.js inside the JSM folder, so is there a way to do this? a command like : uglifyjs -c -m JS/*.js JSM/*.min.js Or any idea

How to keep /*! comments with UglifyJS2?

↘锁芯ラ 提交于 2019-12-11 02:33:50
问题 The default behaviour looks for @license or @preserve ... But many plugins and libraries are still using /*! for licensing comment blocks... How can I use UglifyJS2 to preserve comments starting with /*! ? 回答1: See https://github.com/mishoo/UglifyJS2#usage Using the --comments argument, you can supply a regular expression. uglifyjs jquery.plugin.js --comments '/^\/*!/' -o outfile.js 回答2: In case that you use this VSCode extension JS & CSS Minifier (Minify), you can configure it easily. Just

UglifyJS2 removes wanted comments at the end of a block or file

断了今生、忘了曾经 提交于 2019-12-10 23:34:38
问题 I have a need to keep some specific comments in my uglified javascript. Is there a way to make the UglifyJS2 --comments parameter keep all wanted comments? Example foo.js: function foo() { // don't keep this /* delete this */ /* KEEPME */ for (var i=0; i < 10; i++) { alert('alert #'+i); } /* KEEPME */ } /*KEEPME*/ Using this Uglifyjs2 command line (with uglifyjs2 version 2.4.24): node uglifyjs2 --comments "/KEEPME/i" -o foo.min.js foo.js generates a foo.min.js containing: function foo(){/*

Limit line length with requirejs + uglify

旧街凉风 提交于 2019-12-10 14:54:10
问题 We're using requirejs.optimize(config) with uglify2 in our build scripts to minify our production JavaScript code. We want to limit the minified line length to about 80 chars, so that it will be easier to debug JavaScript errors even from the production code. (Most browsers only report the line number, not the column, in the onerror handler, so source maps do not help.) Uglify2 contains the max-line-len option in the beautifier options. I've tried many different combinations of the following

Lodash not TreeShaking with Webpack with Webpack 4?

别等时光非礼了梦想. 提交于 2019-12-10 04:28:55
问题 I want to tree shake lodash as well as my unused multiply function from the generated bundle from webpack I have 2 main files app.js & math.js It contains the following code - app.js import map from "lodash/map"; import { sum } from "./math"; console.log("💩"); console.log(`2 + 3 = ${sum(2, 3)}`); map([1, 2, 3], x => { console.log(x); }); math.js export const sum = (a, b) => a + b; export const multiply = (m, n) => m * n; webpack.config.js const path = require("path"); const webpack = require(

Uglify with SourceMaps while using grunt usemin and rev

我怕爱的太早我们不能终老 提交于 2019-12-08 17:36:21
问题 I want to log javascript errors to server but the stacktrace is not useful with minified JS code. So I was thinking of using either Getsentry or Rollbar which shows proper stack trace with the help of sourcemaps . But I'm struggling to create sourcemap in first place. I'm getting this error "Destination (_build/js/app.js) not written because src files were empty." Once it creates source map properly, there will be another problem i.e. rev will rename the file. I also need to leave the

UglifyJS property mangling

不羁岁月 提交于 2019-12-08 16:57:03
问题 According to the docs, UglifyJS can mangle all property names except those on a provided reserved list. Is it possible to do it the other way, so only properties on provided list will be mangled? If so, what options do I need to pass to uglify.minify(files, { ... }) ? 回答1: One (ugly) command-line approach to achieve the kind of whitelist you're looking for might be to use the regex option. You can also use a regular expression to define which property names should be mangled. For example, -

UglifyJS webpack plugin throws: Unexpected token: name (features)

落爺英雄遲暮 提交于 2019-12-06 05:11:38
问题 I used to have problems with UglifyJS for Webpack and ES6 modules: ERROR in static/js/vendor.6ccd9e38979a78765c7a.js from UglifyJs Unexpected token: name (features) [./node_modules/pica/lib/mathlib.js:19,0][static/js/vendor.6ccd9e38979a78765c7a.js:39003,6] I read that the new beta version of the Webpack plugin supports ES6: https://github.com/webpack-contrib/uglifyjs-webpack-plugin new webpack.optimize.UglifyJsPlugin({ uglifyOptions: { ie8: false, ecma: 8, // I also tried 7 and 6 parse: {},