uglifyjs

wepack 透视——提高工程化(实践篇)

让人想犯罪 __ 提交于 2019-12-09 13:52:28
wepack 透视——提高工程化(实践篇) webpack 是我们前端工程师必须掌握的一项技能,我们的日常开发已经离不开这个配置。关于这方面的文章已经很多,但还是想把自己的学习过程总结记录下来。 上一篇文章介绍了webpack 构建原理,这篇文章将基于这个原理之上,讲述在我们实际工程配置中可以去优化的2 个方向。 提升构建速度,也就是减少整个打包构建的时间, 优化构建输出,也就是减小我们最终构建输出的文件体积。 1. 提升构建速度 1.1 哪些阶段可以提速? 我们先回顾下整个构建过程,首先从入口文件开始递归生成所有文件的module实例,再针对所有module 实例的依赖关系进行分析优化,划分为一个或多个 chunk 去生成最终的打包文件输出。那哪些阶段我们可以去节约时间呢? module 实例的优化和处理的时间我们并不好做提速,这里往往涉及到最终输出文件的大小,我们做的优化操作越多,输出的文件体积越小,这是我们希望看到的,所以只能从生成 module 实例阶段去入手提速,在这个阶段文件会经过以下处理: resovle阶段: 获取文件所在的绝对路径以及文件要被哪些loaders编译转换 run-loader阶段:执行对应的 loaders对文件执行编译转换 parse 阶段:解析文件是否存在依赖,以及对应的依赖文件。 在这个过程中,我们可以节约时间的方向: resolve 阶段:

Webpack not minifying my bundle js

久未见 提交于 2019-12-08 17:22:32
I'm now bundling my first project with webpack, everything works as expected except webpack is not minifying my bundle.min.js code. I'm pretty sure I'm doing something wrong, but can't spot the mistake. Any help would be appreciated. Thanks in advance. Here I go w/ my webpack.config.js var webpack = require("webpack"); var ExtractTextPlugin = require("extract-text-webpack-plugin"); var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); module.exports = { context: __dirname + "/public", entry: './app.js', output: { path: __dirname + '/dist', filename: "bundle.min.js" },

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, -

ERROR in renderer.js from UglifyJs Unexpected token punc «(»

こ雲淡風輕ζ 提交于 2019-12-08 03:44:26
Version: webpack 2.3.3 Hi there I'm trying to build my first Electron app using Vuejs. Everything seems to be going great until I've come to package the app. When I run npm run dev everything works just fine. However, when I run npm build:darwin I get the following error ERROR in renderer.js from UglifyJs Unexpected token punc «(», expected punc «:» [renderer.js:26813,14] It does end up compiling however when I run the application I get the white screen of death. From what I read, this can be because Uglifyjs doesn't compile ES6 but you can overcome that by the following in your .babelrc file

Removing log statements in Create React App without ejecting

≯℡__Kan透↙ 提交于 2019-12-07 13:56:17
问题 I use lots of console.log() statements while developing Apps (and I mean LOTS ). How exactly can I remove them without "ejecting" from a Create React App What I considered but not sure how exactly to implement: In my package.json: "build": "react-scripts build && uglifyjs --compress drop_console build/static/js/main.xxxxx.js -o build/static/js/main.xxxxx.js However How exactly can I know the hash suffix on the main.js file so I can call this command and save the output js file with same

Minifying scripts using GruntJs

懵懂的女人 提交于 2019-12-07 11:58:50
问题 I have a couple js files that I can seem to get GruntJs to concat/minify properly. If I do each individually they work fine. If I combine separately then attempt to minify just the combined file it doesn't work either. Here is the error: Any ideas on how to fix this? Or maybe what is causing it? 回答1: There is currently a problem with GruntJs and the BOM I mentioned in the comment of Derick's answer. You can find the issue here: https://github.com/cowboy/grunt/issues/218#issuecomment-6329807

Grunt multi-tasks throwing EISDIR error when building

时光总嘲笑我的痴心妄想 提交于 2019-12-07 03:34:13
问题 I am trying to set up grunt to minify a number of js files in a src directory and copy them to a build directory. Following the grunt task documentation, I believe the below configuration should work. uglify: { dist: { files: [ { expand: true, // Enable dynamic expansion. cwd: 'src/js/', // Src matches are relative to this path. src: ['**/?.js'], // Actual pattern(s) to match. dest: 'build/minified/', // Destination path prefix. ext: '.min.js' // Dest filepaths will have this extension. } ] }

gulp-uglify won't preserve files order

梦想的初衷 提交于 2019-12-06 09:56:55
When I use gulp-uglify to minify the Javascript files the order gets messed up. Lets say I have this task working as expected: var gulp = require('gulp'); var rename = require('gulp-rename'); var gp_concat = require('gulp-concat'); gulp.task('js', function() { gulp.src([ './public/bower_components/jquery/dist/jquery.min.js', './public/js/functions.js', ]) .pipe(gp_concat('combined.js')) .pipe(gulp.dest(path.js + '/dist')) }); Adding the uglify line to it changes the order of the jquery and functions files and places functions.js above jquery . var gulp = require('gulp'); var rename = require(

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: {},

Aggregating and uglifying javascript in a git pre-commit hook

安稳与你 提交于 2019-12-06 02:39:36
I'm using ready.js to aggregate JS files into an all.js file (without Google's Closure Compiler), and then using uglify-js to minify and obfuscate the code. I'd like to do all of this in a pre-commit hook. However, I think I'm doing something wrong. My .git/hooks/pre-commit file looks like this: #!/bin/sh readyjs ~/Sites/backbone/js/javascripts/ ~/Sites/backbone/js/ --nojslint -o "underscore.js, backbone.js" --nocompiler uglifyjs -nm -o ~/Sites/backbone/js/all.min.js ~/Sites/backbone/js/all.js # Commit exit Should I not be using simple Bash here? Is there something else I'm doing wrong? This