mirror of
https://github.com/remy/inliner.git
synced 2024-08-16 11:50:32 +03:00
parent
ef5433ccc7
commit
83edb2bf54
@ -16,6 +16,7 @@ function options(args) {
|
|||||||
'videos',
|
'videos',
|
||||||
'inlinemin',
|
'inlinemin',
|
||||||
'preserve-comments',
|
'preserve-comments',
|
||||||
|
'iesafe',
|
||||||
],
|
],
|
||||||
string: [ // options
|
string: [ // options
|
||||||
'encoding',
|
'encoding',
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
-n, --nocompress don't compress CSS or HTML - useful for debugging
|
-n, --nocompress don't compress CSS or HTML - useful for debugging
|
||||||
-i, --noimages don't encode images - keeps files size small, but more requests
|
-i, --noimages don't encode images - keeps files size small, but more requests
|
||||||
-m, --inlinemin inline minified files
|
-m, --inlinemin inline minified files
|
||||||
|
--iesafe safe JS compression for older IE 6/7/8
|
||||||
--videos encode videos (and their poster image) - disabled by default
|
--videos encode videos (and their poster image) - disabled by default
|
||||||
--nosvg don't compress SVG (through SVGO)
|
--nosvg don't compress SVG (through SVGO)
|
||||||
--skip-absolute-urls don't inline links with absolute URLs
|
--skip-absolute-urls don't inline links with absolute URLs
|
||||||
|
@ -7,5 +7,6 @@ module.exports = function () {
|
|||||||
nosvg: false, // by default, DO compress SVG with SVGO
|
nosvg: false, // by default, DO compress SVG with SVGO
|
||||||
skipAbsoluteUrls: false,
|
skipAbsoluteUrls: false,
|
||||||
preserveComments: false,
|
preserveComments: false,
|
||||||
|
iesafe: false,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,8 @@ var debug = require('debug')('inliner');
|
|||||||
var UglifyJS = require('uglify-js');
|
var UglifyJS = require('uglify-js');
|
||||||
|
|
||||||
function uglify(source) {
|
function uglify(source) {
|
||||||
|
var notIESafe = !this.options.iesafe;
|
||||||
|
|
||||||
this.emit('progress', 'compressing javascript');
|
this.emit('progress', 'compressing javascript');
|
||||||
|
|
||||||
source = source.trim();
|
source = source.trim();
|
||||||
@ -20,6 +22,13 @@ function uglify(source) {
|
|||||||
try {
|
try {
|
||||||
result = UglifyJS.minify(source, {
|
result = UglifyJS.minify(source, {
|
||||||
fromString: true,
|
fromString: true,
|
||||||
|
// must set screw_ie8 for each option group
|
||||||
|
// https://github.com/mishoo/UglifyJS2/issues/1204#issuecomment-234714094
|
||||||
|
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||||
|
compress: { screw_ie8: notIESafe },
|
||||||
|
mangle: { screw_ie8: notIESafe },
|
||||||
|
output: { screw_ie8: notIESafe },
|
||||||
|
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||||
}).code;
|
}).code;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// failed to uglify, just return it plain
|
// failed to uglify, just return it plain
|
||||||
|
5
test/fixtures/script-ie.js
vendored
Normal file
5
test/fixtures/script-ie.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function doit() {
|
||||||
|
var foo = {default:'bar'};
|
||||||
|
// default is a reserved word which breaks parsing in IE<=8
|
||||||
|
return foo.default;
|
||||||
|
}
|
3
test/fixtures/script-iesafe.opts.json
vendored
Normal file
3
test/fixtures/script-iesafe.opts.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"iesafe": true
|
||||||
|
}
|
1
test/fixtures/script-iesafe.result.html
vendored
Normal file
1
test/fixtures/script-iesafe.result.html
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>iesafe</title> </head> <body> <script>function doit(){return{"default":"bar"}["default"]}</script> </body> </html>
|
10
test/fixtures/script-iesafe.src.html
vendored
Normal file
10
test/fixtures/script-iesafe.src.html
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>iesafe</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script src="script-ie.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
1
test/fixtures/script-ieunsafe.result.html
vendored
Normal file
1
test/fixtures/script-ieunsafe.result.html
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>ieunsafe</title> </head> <body> <script>function doit(){return{default:"bar"}.default}</script> </body> </html>
|
10
test/fixtures/script-ieunsafe.src.html
vendored
Normal file
10
test/fixtures/script-ieunsafe.src.html
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>ieunsafe</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script src="script-ie.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user