Coder Social home page Coder Social logo

breezewish / express-minify Goto Github PK

View Code? Open in Web Editor NEW
86.0 6.0 18.0 109 KB

Automatically minify and cache your javascript and css files.

Home Page: https://npmjs.org/package/express-minify

License: MIT License

JavaScript 100.00%
express minify uglifyjs

express-minify's People

Contributors

breezewish avatar peterdavehello avatar reiz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

express-minify's Issues

Basic Usage is not working

express-minify needs a Content-Type header on the response before it does anything. Express doesn't set this by default, so one needs a custom middleware before the express-minify middleware.

So your Basic Usage example should be extended in the following way so that it works 'out of the box', to save developers some time debugging.

var mime = require('mime');
app.use(function (req, res, next) {
  res.type(mime.lookup(req.path));
  next();
});
app.use(minify());

I'm using express 4.14.0 and express-minify 0.2.0.

CSS minifying issue

When going to test.css in a public directory it throws this error:

TypeError error: TypeError: Cannot read property 'length' of undefined
    at uriToSourceMapping (/Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/reader/load-original-sources.js:39:38)
    at loadOriginalSources (/Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/reader/load-original-sources.js:20:18)
    at /Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/reader/read-sources.js:26:14
    at applySourceMaps (/Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/reader/apply-source-maps.js:34:5)
    at Object.callback (/Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/reader/read-sources.js:25:12)
    at doInlineImports (/Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/reader/read-sources.js:200:25)
    at inline (/Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/reader/read-sources.js:178:10)
    at fromStyles (/Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/reader/read-sources.js:151:5)
    at fromString (/Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/reader/read-sources.js:48:10)
    at doReadSources (/Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/reader/read-sources.js:33:12)
    at readSources (/Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/reader/read-sources.js:24:10)
    at /Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/clean.js:115:12
    at /Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/clean.js:135:34
    at minify (/Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/clean.js:114:35)
    at CleanCSS.minify (/Users/me/Desktop/Code/CDN-Template/node_modules/clean-css/lib/clean.js:77:12)
    at Minifier._minifyCss (/Users/me/Desktop/Code/CDN-Template/node_modules/express-minify/minifier.js:74:55)

Error while installing on macOS 10.14.1

I got the following error(s) when I try to install it.

`Administrators-MacBook-Pro:myproject administrator$ npm install express-minify
npm WARN deprecated [email protected]: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated [email protected]: Use uuid module instead
npm WARN deprecated [email protected]: The major version is no longer supported. Please update to 4.x or newer
npm WARN deprecated [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: This package is unmaintained. Use @sinonjs/formatio instead
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue

[email protected] install /Users/administrator/Downloads/myproject/node_modules/express-minify/node_modules/node-sass
node build.js

(node:23746) [DEP0006] DeprecationWarning: child_process: options.customFds option is deprecated. Use options.stdio instead.
CXX(target) Release/obj.target/binding/binding.o
In file included from ../binding.cpp:1:
../../nan/nan.h:79:32: warning: 'BooleanValue' is deprecated [-Wdeprecated-declarations]
|| optionsObj->Get(opt)->BooleanValue();
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2474:3: note: 'BooleanValue' has been explicitly marked deprecated here
V8_DEPRECATED("Use maybe version", bool BooleanValue() const);
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
declarator attribute((deprecated))
^
In file included from ../binding.cpp:1:
../../nan/nan.h:83:32: warning: 'BooleanValue' is deprecated [-Wdeprecated-declarations]
&& optionsObj->Get(opt)->BooleanValue();
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2474:3: note: 'BooleanValue' has been explicitly marked deprecated here
V8_DEPRECATED("Use maybe version", bool BooleanValue() const);
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
declarator attribute((deprecated))
^
In file included from ../binding.cpp:1:
../../nan/nan.h:102:31: warning: 'Uint32Value' is deprecated [-Wdeprecated-declarations]
? optionsObj->Get(opt)->Uint32Value()
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2477:3: note: 'Uint32Value' has been explicitly marked deprecated here
V8_DEPRECATED("Use maybe version", uint32_t Uint32Value() const);
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
declarator attribute((deprecated))
^
In file included from ../binding.cpp:1:
../../nan/nan.h:189:68: error: too many arguments to function call, expected at most 2, have 4
return v8::Signature::New(v8::Isolate::GetCurrent(), receiver, argc, argv);
~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:6137:3: note: 'New' declared here
static Local New(
^
In file included from ../binding.cpp:1:
../../nan/nan.h:244:32: error: no member named 'CompileUnbound' in 'v8::ScriptCompiler'
return v8::ScriptCompiler::CompileUnbound(
~~~~~~~~~~~~~~~~~~~~^
../../nan/nan.h:253:32: error: no member named 'CompileUnbound' in 'v8::ScriptCompiler'
return v8::ScriptCompiler::CompileUnbound(
~~~~~~~~~~~~~~~~~~~~^
../../nan/nan.h:259:40: error: too few arguments to function call, expected 2, have 1
return v8::BooleanObject::New(value).Asv8::BooleanObject();
~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:5035:3: note: 'New' declared here
static Local New(Isolate* isolate, bool value);
^
In file included from ../binding.cpp:1:
../../nan/nan.h:259:62: error: expected '(' for function-style cast or type construction
return v8::BooleanObject::New(value).Asv8::BooleanObject();
~~~~~~~~~~~~~~~~~^
../../nan/nan.h:259:64: error: expected expression
return v8::BooleanObject::New(value).Asv8::BooleanObject();
^
../../nan/nan.h:266:30: warning: 'New' is deprecated [-Wdeprecated-declarations]
return v8::StringObject::New(value).Asv8::StringObject();
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:5052:3: note: 'New' has been explicitly marked deprecated here
V8_DEPRECATED("Use Isolate* version",
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
declarator attribute((deprecated))
^
In file included from ../binding.cpp:1:
../../nan/nan.h:271:3: error: redefinition of 'NanNew'
NanNew<v8::StringObject, v8::Handlev8::String >(
^
../../nan/nan.h:264:3: note: previous definition is here
NanNew<v8::StringObject, v8::Localv8::String >(
^
../../nan/nan.h:273:30: warning: 'New' is deprecated [-Wdeprecated-declarations]
return v8::StringObject::New(value).Asv8::StringObject();
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:5052:3: note: 'New' has been explicitly marked deprecated here
V8_DEPRECATED("Use Isolate* version",
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
declarator attribute((deprecated))
^
In file included from ../binding.cpp:1:
../../nan/nan.h:285:24: warning: 'New' is deprecated [-Wdeprecated-declarations]
return v8::RegExp::New(pattern, flags);
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:5109:10: note: 'New' has been explicitly marked deprecated here
static V8_DEPRECATED("Use maybe version",
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
declarator attribute((deprecated))
^
In file included from ../binding.cpp:1:
../../nan/nan.h:289:36: error: redefinition of 'NanNew'
NAN_INLINE v8::Localv8::RegExp NanNew(
^
../../nan/nan.h:283:36: note: previous definition is here
NAN_INLINE v8::Localv8::RegExp NanNew(
^
../../nan/nan.h:291:24: warning: 'New' is deprecated [-Wdeprecated-declarations]
return v8::RegExp::New(pattern, flags);
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:5109:10: note: 'New' has been explicitly marked deprecated here
static V8_DEPRECATED("Use maybe version",
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
declarator attribute((deprecated))
^
In file included from ../binding.cpp:1:
../../nan/nan.h:297:24: warning: 'New' is deprecated [-Wdeprecated-declarations]
return v8::RegExp::New(pattern, flags);
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:5109:10: note: 'New' has been explicitly marked deprecated here
static V8_DEPRECATED("Use maybe version",
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
declarator attribute((deprecated))
^
In file included from ../binding.cpp:1:
../../nan/nan.h:301:36: error: redefinition of 'NanNew'
NAN_INLINE v8::Localv8::RegExp NanNew(
^
../../nan/nan.h:295:36: note: previous definition is here
NAN_INLINE v8::Localv8::RegExp NanNew(
^
../../nan/nan.h:303:24: warning: 'New' is deprecated [-Wdeprecated-declarations]
return v8::RegExp::New(pattern, flags);
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:5109:10: note: 'New' has been explicitly marked deprecated here
static V8_DEPRECATED("Use maybe version",
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
declarator attribute((deprecated))
^
In file included from ../binding.cpp:1:
../../nan/nan.h:309:51: error: too few arguments to function call, single argument 'context' was not specified
v8::Isolate::GetCurrent(), val)->ToUint32();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2435:3: note: 'ToUint32' declared here
V8_WARN_UNUSED_RESULT MaybeLocal ToUint32(
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8config.h:416:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT attribute((warn_unused_result))
^
In file included from ../binding.cpp:1:
../../nan/nan.h:315:51: error: too few arguments to function call, single argument 'context' was not specified
v8::Isolate::GetCurrent(), val)->ToUint32();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2435:3: note: 'ToUint32' declared here
V8_WARN_UNUSED_RESULT MaybeLocal ToUint32(
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8config.h:416:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT attribute((warn_unused_result))
^
In file included from ../binding.cpp:1:
../../nan/nan.h:320:60: error: no matching member function for call to 'ToInt32'
return v8::Int32::New(v8::Isolate::GetCurrent(), val)->ToInt32();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2437:43: note: candidate function not viable: requires single argument 'context', but no arguments were provided
V8_WARN_UNUSED_RESULT MaybeLocal ToInt32(Local context) const;
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2450:30: note: candidate function not viable: requires single argument 'isolate', but no arguments were provided
Local ToInt32(Isolate* isolate) const);
^
In file included from ../binding.cpp:1:
../../nan/nan.h:325:60: error: no matching member function for call to 'ToInt32'
return v8::Int32::New(v8::Isolate::GetCurrent(), val)->ToInt32();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2437:43: note: candidate function not viable: requires single argument 'context', but no arguments were provided
V8_WARN_UNUSED_RESULT MaybeLocal ToInt32(Local context) const;
^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2450:30: note: candidate function not viable: requires single argument 'isolate', but no arguments were provided
Local ToInt32(Isolate* isolate) const);
^
In file included from ../binding.cpp:1:
../../nan/nan.h:368:9: error: cannot initialize a parameter of type 'v8::NewStringType' with an rvalue of type 'v8::String::NewStringType'
, v8::String::kNormalString
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2803:64: note: passing argument to parameter 'type' here
Isolate* isolate, const uint8_t* data, v8::NewStringType type,
^
In file included from ../binding.cpp:1:
../../nan/nan.h:379:9: error: cannot initialize a parameter of type 'v8::NewStringType' with an rvalue of type 'v8::String::NewStringType'
, v8::String::kNormalString
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2803:64: note: passing argument to parameter 'type' here
Isolate* isolate, const uint8_t* data, v8::NewStringType type,
^
In file included from ../binding.cpp:1:
../../nan/nan.h:385:69: error: too few arguments to function call, expected at least 3, have 2
return v8::String::NewFromOneByte(v8::Isolate::GetCurrent(), arg);
~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2802:3: note: 'NewFromOneByte' declared here
static V8_WARN_UNUSED_RESULT MaybeLocal NewFromOneByte(
^
In file included from ../binding.cpp:1:
../../nan/nan.h:391:69: error: too few arguments to function call, expected at least 3, have 2
return v8::String::NewFromOneByte(v8::Isolate::GetCurrent(), arg);
~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2802:3: note: 'NewFromOneByte' declared here
static V8_WARN_UNUSED_RESULT MaybeLocal NewFromOneByte(
^
In file included from ../binding.cpp:1:
../../nan/nan.h:477:63: error: cannot initialize a parameter of type 'v8::String::ExternalOneByteStringResource *' with an lvalue of type 'v8::String::ExternalStringResource '
return v8::String::NewExternal(v8::Isolate::GetCurrent(), resource);
^~~~~~~~
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2862:64: note: passing argument to parameter 'resource' here
ExternalOneByteStringResource
resource));
^
In file included from ../binding.cpp:1:
../../nan/nan.h:481:19: error: no type named 'ExternalAsciiStringResource' in 'v8::String'; did you mean 'ExternalStringResource'?
v8::String::ExternalAsciiStringResource *resource) {
~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
ExternalStringResource
/Users/administrator/.node-gyp/10.14.1/include/node/v8.h:2710:19: note: 'ExternalStringResource' declared here
class V8_EXPORT ExternalStringResource
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
9 warnings and 20 errors generated.
make: *** [Release/obj.target/binding/binding.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/administrator/Downloads/myproject/node_modules/express-minify/node_modules/node-sass
gyp ERR! node -v v10.14.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed
npm WARN [email protected] requires a peer of [email protected] but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No repository field.
npm WARN [email protected] license should be a valid SPDX license expression

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node build.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/administrator/.npm/_logs/2018-12-09T14_26_40_983Z-debug.log`

JSON cannot be minified by uglify-js

Because JSON is not quite valid Javascript. For example:

{ "success" : "true" }

is valid JSON but not valid JS! In JS that is considered to be a code block, not an object literal. To be valid JS it would need to be:

({ "success" : "true" })

The result is that a request with Accept: application/json fails to minify:

2013/08/26 20:35:45 [log] (express-minify/minify.js:39:10|minifyIt) Minifying some content of type '1' content={
  "retStatus": "success"
}
WARN: ERROR: Unexpected token: punc (:) [?:2,13]

node_modules/express-minify/node_modules/uglify-js/lib/parse.js:199
    throw new JS_Parse_Error(message, line, col, pos);
          ^
Error
    at new JS_Parse_Error (node_modules/express-minify/node_modules/uglify-js/lib/parse.js:185:18)
    at js_error (node_modules/express-minify/node_modules/uglify-js/lib/parse.js:199:11)
    at croak (node_modules/express-minify/node_modules/uglify-js/lib/parse.js:630:9)
    at token_error (node_modules/express-minify/node_modules/uglify-js/lib/parse.js:638:9)
    at unexpected (node_modules/express-minify/node_modules/uglify-js/lib/parse.js:644:9)
...

My suggestion is that JSON should not be marked for minifying. Alternatively, if you want to minify JSON, wrap it in (...) before passng to Uglify, and remove the parentheses afterwards.

node-sass's postinstall-script error on windows

npm i express-minify shows errors on node-sass's postinstall-script (failing on windows, node 0.12.0, npm 2.5.1), while npm i node-sass works just fine!?

15299 verbose about to build C:\f\node_modules\express-minify\node_modules\node-sass
15300 info build C:\f\node_modules\express-minify\node_modules\node-sass
15301 verbose linkStuff [ false,
15301 verbose linkStuff   false,
15301 verbose linkStuff   false,
15301 verbose linkStuff   'C:\\f\\node_modules\\express-minify\\node_modules' ]
15302 info linkStuff [email protected]
15303 verbose linkBins [email protected]
15304 verbose link bins [ { 'node-sass': 'bin/node-sass' },
15304 verbose link bins   'C:\\f\\node_modules\\express-minify\\node_modules\\.bin',
15304 verbose link bins   false ]
15305 verbose linkMans [email protected]
15306 verbose rebuildBundles [email protected]
15307 verbose rebuildBundles [ '.bin',
15307 verbose rebuildBundles   'chalk',
15307 verbose rebuildBundles   'cross-spawn',
15307 verbose rebuildBundles   'gaze',
15307 verbose rebuildBundles   'get-stdin',
15307 verbose rebuildBundles   'meow',
15307 verbose rebuildBundles   'mkdirp',
15307 verbose rebuildBundles   'mocha',
15307 verbose rebuildBundles   'nan',
15307 verbose rebuildBundles   'object-assign',
15307 verbose rebuildBundles   'replace-ext',
15307 verbose rebuildBundles   'request',
15307 verbose rebuildBundles   'shelljs' ]
15308 info install [email protected]
15309 verbose unsafe-perm in lifecycle true
15310 info [email protected] Failed to exec install script
15311 verbose unlock done using C:\Users\OB\AppData\Roaming\npm-cache\_locks\node-sass-700920b75f4b299a.lock for C:\f\node_modules\express-minify\node_modules\node-sass
15312 verbose about to build C:\f\node_modules\express-minify
15313 verbose unlock done using C:\Users\OB\AppData\Roaming\npm-cache\_locks\express-minify-7c761142970a8628.lock for C:\f\node_modules\express-minify
15314 verbose stack Error: [email protected] install: `node scripts/install.js`
15314 verbose stack Exit status 1
15314 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:213:16)
15314 verbose stack     at EventEmitter.emit (events.js:110:17)
15314 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:14:12)
15314 verbose stack     at ChildProcess.emit (events.js:110:17)
15314 verbose stack     at maybeClose (child_process.js:1008:16)
15314 verbose stack     at Process.ChildProcess._handle.onexit (child_process.js:1080:5)
15315 verbose pkgid [email protected]
15316 verbose cwd C:\f
15317 error Windows_NT 6.1.7601
15318 error argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "express-minify" "-d"
15319 error node v0.12.0
15320 error npm  v2.5.1
15321 error code ELIFECYCLE
15322 error [email protected] install: `node scripts/install.js`
15322 error Exit status 1
15323 error Failed at the [email protected] install script 'node scripts/install.js'.
15323 error This is most likely a problem with the node-sass package,
15323 error not with npm itself.
15323 error Tell the author that this fails on your system:
15323 error     node scripts/install.js
15323 error You can get their info via:
15323 error     npm owner ls node-sass
15323 error There is likely additional logging output above.
15324 verbose exit [ 1, true ]
15325 verbose unbuild node_modules\express-minify\node_modules\node-sass
15326 info preuninstall [email protected]
15327 info uninstall [email protected]
15328 verbose unbuild rmStuff [email protected] from C:\f\node_modules
15329 verbose unbuild rmStuff in C:\f\node_modules\express-minify\node_modules
15330 verbose gentlyRm verifying that C:\f is managed by npm
15331 silly isManaged C:\f is not inside C:\f\node_modules
15332 silly isManaged C:\f is not inside C:\f\node_modules
15333 silly isManaged C:\f\node_modules\.bin is inside C:\f
15334 silly gentlyRm C:\f is managed by npm
15335 silly gentlyRm C:\f\node_modules\express-minify\node_modules\.bin\node-sass.cmd is under C:\f
15336 verbose gentlyRm vacuuming C:\f\node_modules\express-minify\node_modules\.bin\node-sass.cmd up to C:\f
15337 silly gentlyRm removing C:\f\node_modules\express-minify\node_modules\.bin\node-sass.cmd
15338 silly gentlyRm quitting because other entries in C:\f\node_modules\express-minify\node_modules\.bin
15339 verbose gentlyRm verifying that C:\f is managed by npm
15340 silly isManaged C:\f is not inside C:\f\node_modules
15341 silly isManaged C:\f is not inside C:\f\node_modules
15342 silly isManaged C:\f is not inside C:\f\node_modules\.bin
15343 silly isManaged C:\f is inside C:\f
15344 silly gentlyRm C:\f is managed by npm
15345 silly gentlyRm C:\f\node_modules\express-minify\node_modules\.bin\node-sass is under C:\f
15346 verbose gentlyRm vacuuming C:\f\node_modules\express-minify\node_modules\.bin\node-sass up to C:\f
15347 silly gentlyRm removing C:\f\node_modules\express-minify\node_modules\.bin\node-sass
15348 silly gentlyRm quitting because other entries in C:\f\node_modules\express-minify\node_modules\.bin
15349 info postuninstall [email protected]
15350 verbose gentlyRm vacuuming C:\f\node_modules\express-minify\node_modules\node-sass
15351 silly gentlyRm purging C:\f\node_modules\express-minify\node_modules\node-sass
15352 silly gentlyRm quitting because other entries in C:\f\node_modules\express-minify\node_modules
15353 verbose unbuild node_modules\express-minify
15354 info preuninstall [email protected]
15355 info uninstall [email protected]
15356 verbose unbuild rmStuff [email protected] from C:\f\node_modules
15357 info postuninstall [email protected]
15358 verbose gentlyRm vacuuming C:\f\node_modules\express-minify
15359 silly gentlyRm purging C:\f\node_modules\express-minify
15360 silly gentlyRm quitting because other entries in C:\f\node_modules

(Low priority) Skip minification of already minified files

Some of the files served in our project are third party libraries which are already minified.

Although it only happens once, re-minifying these can be very slow. (I guess that's an issue with uglify.) To reproduce, try minifying http://d3js.org/d3.v3.min.js

I would like to tell express-minify to skip minification for all files matching .min.js$ or .min.css$, and I recommend that behaviour as a default.

Alternatively, this could be addressed by whitelisting or blacklisting specific folders for minification.

(In our project, we are serving all our pre-minified and to-be-minified files from one express.static() route.)

Does not work well with the compression module

Hey there. I keep getting ERR_CONTENT_DECODING_FAILED messages from chrome while using this one and the compression module together.

When I use cURL to look at the output, it looks perfectly right; but requesting this with the browser results in the above error.

Here is a snapshot of using CURL to get the file. Its a static asset generated by a different tool.

[email protected] ~/Work/BIRD3 $ curl -v -4 --header "Accept-encoding: gzip" http://localhost:8080/cdn/assets/f9f74164/c_ce8e14622a9666575efec15f9f44009c.css > test.gz
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /cdn/assets/f9f74164/c_ce8e14622a9666575efec15f9f44009c.css HTTP/1.1
> User-Agent: curl/7.38.0
> Host: localhost:8080
> Accept: */*
> Accept-encoding: gzip
>
< HTTP/1.1 200 OK
< Content-Type: text/css
< Cache-Control: max-age=0, must-revalidate
< ETag: 5/bNP6Ea/OG8UdvgX7sNWTIklPY=
< Content-Encoding: gzip
< Vary: Accept-Encoding
< X-Response-Time: 0.163ms
< Date: Thu, 15 Jan 2015 21:15:46 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
<
{ [data not shown]
100 87193    0 87193    0     0  28.7M      0 --:--:-- --:--:-- --:--:-- 83.1M
* Connection #0 to host localhost left intact
[email protected] ~/Work/BIRD3 $ hexdump -C -n 16 test.gz
00000000  1f ef bf bd 08 00 00 00  00 00 00 03 ef bf bd ef  |................|
00000010

uglifyJS option and uglifyJS-X compatibility

I gave it a try with uglify-es

app.use(minify({uglifyJS: require('uglify-es')})); //uglifyJS with ES6 support

but it does not work. There are uglifyJS2 and uglifyJS3 out there, which are stated to be mutually incompatible either.

What options do we really have with uglifyJS option? Can we document it?

Update node-sass for node v0.12 support

Hello,

Depending on node-sass@^1.2.3 causes issues with node v0.12 (and probably io.js as well); you can't install express-minify because the installation script for node-sass fails. If I clone express-minify locally and change the dependency in package.json to ^2.0.1 then everything installs correctly. The error has to do with the fact that node-sass has a C++ binding that needs to be rebuilt correctly for v0.12.

I can't speak for whether that causes breaking changes (my application doesn't use sass, and I don't see a changelog in the node-sass repo), but it'd be nice if express-minify could have that dependency updated so I don't have to fork it just to get it working on v0.12.

test cache

cache functionality is not tested yet

Cleanup of stale cache entries

Just a placeholder to discuss this feature. :)

A metric I used in the past to order cache entries for cleanup was:

timeSinceLastHit / (numberOfTimesHit + 1)

So entries which are hit twice as often will take twice as long to expire. (The +1 just avoids division by zero, if we don't record the creation of the cache entry as a "hit".)

Although for this project, a fixed timeout like "1 month old" for the disk-cache might be simpler, and avoid having to record hit statistics. "1 month unused" might be better, but we would need to record the last hit time.

CoffeeScript compile not congruent with coffeescript.org compiler

Sometimes codes which are compiled correctly at coffeescript.org, fail with your module... Not sure if it's the coffee-script dependency or the minification afterwards.. please check for this.

Example

#perfectly compiled at coffeescript.org
$ovl
    .on "click", ".close", -> F.obs.f "mod_ovl_close"
    .on "click", ".prev", -> move -1
    .on "click", ".next", -> move 1
    .click ( e ) -> e.stopPropagation()

Workaround

#I need to write this with express-minify
$ovl
    .on( "click", ".close", -> F.obs.f "mod_ovl_close" )
    .on( "click", ".prev", -> ( move -1 ) )
    .on( "click", ".next", -> ( move 1 ) )
    .click ( e ) -> e.stopPropagation()

If the issue lays in the coffee-script dependency, please forward this issue, thx !!

*Do* minify this response but *do not* cache it! (blacklist or res._option?)

The section in the readme titled "Do not minify this response!" assumes that we don't want to minify dynamic responses.

However, if the minifier runs fast enough, it may still be desirable to minify dynamic documents before sending them to the client. In that case, we just don't want to cache dynamic data, because as you say, it will create a lot of cache entries which will likely not be hit again.

Something like res._no_cache_minified = true; would provide that feature, although perhaps a (list of) cache blacklist regexp(s) may be preferable because it is more declarative. (The regexps would be redundant, but would keep the behaviour all in one place. Perhaps both methods might be made available.)

(The same argument for a white/blacklist could be applied to the existing res._no_minify feature. Aren't routes usually dynamic? Therefore wouldn't res._do_minify make more sense, for those few routes which serve a static response, or a small range of responses?)

An alternative, is to cache all minified responses, but cleanup cache entries which have not been hit for a long time. (This should probably happen quite soon for the memory cache, less urgently for a file cache.) This might be the preferred solution for e.g. a news site which updates its front page just once a day, serving each day's document many times, but then never serving that document again.

Question about file cache option

Not actually an issue but I want to ask about the cache directory option. What's the purpose of storing files in the cache folder on the server? As far as i know, express static files support ETag, so what's the difference here? Your package is working fine for me by the way.

'Error: Module version mismatch. Expected 11, got 1' when trying to deploy application with nodejitsu

Hi,

I am using express-minify for minifying my js files on the fly. The module is working fine in development environment i.e with localhost but when I try to deploy application with nodejitsu, I get following error:

module.js:356
    Module._extensions[extension](this, filename);

  Error: Module version mismatch. Expected 11, got 1.
       at Module.load (module.js:356:32)
       at Function.Module._load (module.js:312:12)
       at Module.require (module.js:364:17)
       at require (module.js:380:17)
       at Object.<anonymous> (/opt/run/snapshot/package/node_modules/express-minify/node_modules/node-sass/sass.js:11:13)
       at Module._compile (module.js:456:26)
       at Object.Module._extensions..js (module.js:474:10)
       at Module.load (module.js:356:32)
       at Function.Module._load (module.js:312:12)
       at Module.require (module.js:364:17)

Middleware not hooked?

I can't seem to get minified output using the default express-minify options and setup as in README.
Should I call minify before or after body-parser?

Any knows conflicts with these modules?
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]

Keep comments?

Over at our project we could really use the keep comments option in this package from uglify-js but still minify everything else (in select JavaScript code)... any chance of that here?

TIA.

js_match.test is not a function

Hello,

I've just configured express-minify an i get the following error:

Express server listening on port 3001
/foo/node_modules/express-minify/index.js:66
      } else if (js_match.test(contentType)) {
                          ^

TypeError: js_match.test is not a function

My conf is:


var minify = require('express-minify');
var myUglifyJS = require('uglify-js');
var myCssmin = require('cssmin');

app.use(cookieParser());
app.use(compress());
app.use(minify({
    uglifyJS: myUglifyJS,
    cssmin: myCssmin,
    js_match: config.root + '/public/js/',
    css_match: config.root + '/public/css/',
  }));

I believe to be a bug with express-minify, but i'm also new to js, so i might not be right.

Thanks!

`express-minify` +`terser` ?

I got an overall idea about what is going on. I understood that terser the module to uglify modern JS. But, I tried to use it using the uglifyJsModule. It looks like it is not compatible with express-minify.

Code:

const _express_minify = require('express-minify');
const _terser = require('terser');
app.use(_express_minify({
    cache: false,
    jsMatch: /javascript|js/g,
    errorHandler: error => {
        console.error(error);
    },
    uglifyJsModule: _terser
}));

Output:

_http_outgoing.js:696
    throw new ERR_INVALID_ARG_TYPE('first argument',
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer or Uint8Array. Received undefined
    at write_ (_http_outgoing.js:696:11)
    at ServerResponse.write (_http_outgoing.js:661:15)
    at C:\Projects\openstore\node_modules\express-minify\index.js:151:23
    at MemoryCache.put (C:\Projects\openstore\node_modules\express-minify\cache.js:46:3)
    at C:\Projects\openstore\node_modules\express-minify\index.js:150:27
    at C:\Projects\openstore\node_modules\express-minify\minifier.js:173:5
    at Minifier._minifyJavaScript (C:\Projects\openstore\node_modules\express-minify\minifier.js:63:3)
    at Minifier._compileAndMinify (C:\Projects\openstore\node_modules\express-minify\minifier.js:155:15)
    at Minifier.compileAndMinify (C:\Projects\openstore\node_modules\express-minify\minifier.js:164:8)
    at C:\Projects\openstore\node_modules\express-minify\index.js:144:20 {
  code: 'ERR_INVALID_ARG_TYPE'
}

It's not working for me.

this is my code
app.use(minifying({ js_match : /\.js$/, css_match : /\.css$/ })) right before express static middleware.

  1. no js or css file is being minified.
  2. not getting any response to data APIs

I tried using compression, that works just fine. But minification , with or without compression is not working.

stylus not required when not loaded yet

VERSIONS nodeJS: 4.0.0, expressJS: 4.13.3

I just updated to the latest nodeJS and expressJS versions and express-minify didn't compile my text/stylus responses anymore.

Reading your code I found out that the variable stylus is false BUT require( "stylus" ) never happens.

WORKAROUND I preinstalled the latest stylus now and everything fine again.

THOUGHTS Not invested that much time but maybe your minifyIt() is only called when caching activated?

old stylus dependency

HI!!
I'm using express-minify to compile stylus. However when I @import "nib" some features fail because your stylus dependency is 0.32.1, which is old and doesn't support e.g. linear-gradients from the nib framework. Please update your dependency... THX

0-length cache file; writing files to cache; and Last-Modified header.

This seems like a pretty rare bug, but when I was using version 0.0.4, somehow I got a 0 length file in my cache. I'm afraid I couldn't reproduce it, but I did wonder if fs.writeFile might be to blame...

Unfortunately in many apps, writing directly to files is often not the correct thing to do. Because there is a small chance that during that moment the process will be killed, or there will be a power cut, and the file will be left only partially written to the disk. When the app is started again, it has no way of knowing that the file is invalid, and just assumes it is valid.

Instead of using lockfiles, a common solution to this is to write to a temporary file (e.g. filename.working) and then after the data is saved, move the working file into its final location. This is good practice, because on most filesystems, a file move/overwrite is atomic: it either works or it doesn't. (You can see apps doing this sort of thing when saving their config files, to avoid the risk of losing the user's config.)

So ... you could consider that approach when writing your cachefiles.


The second related issue was that I had some difficulty getting this 0 length file out of my browser's cache! If I changed the original file a little, the browser would get a new freshly-minified version, but then when I changed it back, it hit the 0-length copy from its cache again!

If I recall correctly, the browser was using Last-Modified, perhaps based on the minfied file's timestamp, rather than the original? If that is the case, you might reconsider that policy. Although I guess this is a non-problem, assuming we never see invalid cachefiles again.


Anyway, thanks for this nice little package. It's great to be able to just drop it in. I hope my bug reports don't drive you too crazy! :)

Some more suggestions for the future: how about minification for HTML/SVG/XML/XSLT/SGML files, and cleanup of old cache files?

Crash

I am sometimes getting the following js stack when it crashes:

--
==== JS stack trace =========================================

Security context: 0x1eebfa29cca1
1: indexOf(this=0x8003cb8acb9 <Very long string[120432959]>)
2: cssmin [/home/1/www/node_modules/cssmin/cssmin.js:~28] [pc=0x30c7f5977e84](this=0x3443744b0189 ,css=0x2bd8de31baa9 <Very long string[20809655]>,linebreakpos=0x1eebfa282241 )
3: arguments adaptor frame: 1->2
5: /* anonymous */ [/home/1/www/node_modules/express-minify/minifier....

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

--

any idea how to fix it?

I am using express-minify 0.2.0. I see there were new versions - is this issue known/fixed?

thanks

CSS are minified, JS not

Hi,

As the title explained, CSS are well minified, but the JS files are not :(

const minify = require("express-minify");
const uglifyEs = require("uglify-es");

this.app.use(BodyParser.json({limit: "2mb"}));
this.app.use(BodyParser.urlencoded({ extended: false }));
this.app.use(ENDPOINT_UI, express.static(__dirname + "/../../../ui"));

if (this.enableCompression) {
    this.app.use(compression({filter: (req, res) => {
        if (req.headers["x-no-compression"]) {
            // don't compress responses with this request header
            return false;
        }

        // fallback to standard filter function
        return compression.filter(req, res);
    }}));
}

// Minify
this.app.use(minify({
  cache: false,
  uglifyJsModule: uglifyEs,
  errorHandler: (errorInfo, callback) => {
      Logger.err(errorInfo);
  },
  jsMatch: /javascript/,
  cssMatch: /css/,
  jsonMatch: false
}));

My js files are set under ui/js/ and in the browser I can see that http://localhost:8100/js/bootstrap.js sent the good mime type

Any clue ?

NFR: Experimental branch for *UglifyJS2*

Heyo again... still pondering on that last NFR but keep getting yanked in different directions... anyhow...

I was hoping to see if you could add a specific branch to express-minify that has:

"uglify-js": "git://github.com/mishoo/UglifyJS2#harmony"

... in that branches ./package.json to replace this line in order to let everyone test out mishoo/UglifyJS#448 .

I've established a testing method on OpenUserJS and would like to easily switch between your primary release (npm of course) and a test branch on this GitHub repo.

Would this one liner with a branch creation be something you would be willing to do when you have a moment?

Thanks so much and have a good holiday if you are doing that sort of thing. :)
OUJS Admin

Refs:

How to skip minification for already minified assets?

Some devs have pre-minified files to serve, like self-hosted jquery.min.js, or bootstrap-min.css. What's a good rule to apply to save some CPU cycles and not re-minify these file patterns?

... Could this rule be applied to express-minify by default?

Minification of static files

If I understand correctly, express-minify always reads the entire contents of a document that is about to be served, then calculates a SHA1 sum from the data, so it can check the cache to see if it has already been minified.

However, if the file being served is a static file on the disk, the process of reading and hashing the file contents every time is an unnecessary overhead. (When using file cache, we would end up reading both the unminified and minified files, to serve one request.) Instead, we could check in the cache for an entry matching the (hashed) filename + filesize + last-modified date of the unminified file on the disk, and potentially serve the minified file directly, without having to read the unminified file at all. (We would need to stat it of course.)

This might need to be implemented as something like a replacement for express.static(). express-minifier would need to be told where the /static folder(s) are, and therefore it seems redundant to use express.static() at all. But this extra complexity might be worthwhile to halve the number of files read.

Apologies if I have misunderstood the current workings. Perhaps you already have a plan like this in motion. If you don't get around to implementing this, I may be able to provide a pull request in future... :)

Support for `@import` ?

Hello again. This is going to be a bit tricky to explain but I will give it a go in a reduced test case form...

someSnippet.js

var express = require('express');
var minify  = require('express-minify');

var app = express();

/*
 * Bunch of other express specific intialization and then...
 */
express.static.mime.define({
  'text/less': ['less']
});

/*
 * Use minify
 */
app.use(minify());

someSnippet.html

<link rel="stylesheet/less" type="text/css" href="/source1.less">

source1.less

@import 'source2.less';

body {
  background-color: @my-color;
}

source2.less

@my-color: #ABC123;

Produces the following output at our http://localhost:8080/source1.less:

{"type":"File","filename":"input","index":0,"line":1,"callLine":null,"column":0,"extract":[null,"@import 'source2.less';",""],"message":"'source2.less' wasn't found. Tried - source2.less,source2.less"}

... instead of the expected ...

body{background-color:#abc123}
  1. Did I do something incorrectly with express-minify initialization?
  2. Do you support the @import statement? Currently we are using the less-middleware package to achieve support.
  3. If you do support the @import statement we are going to need some exposure to the paths option in less too probably similar to #15 e.g. we currently pick through a series of .less files at different paths in our project tree and import them into our own .less from a different path.

As long as we don't use the @import statement and keep all variables and mixins in the same file express-minify works with less parsing and compiling... however splitting them out doesn't seem to.

Any help would be greatly appreciated.

NFR: `catch` callbacks, emitters, or equivalent options

In order to easily provide some data back to UglifyJS2 the current code "ignores" any errors.

It would be very helpful to them to have us be able to provide this data to them and we could attach our own handler to the error to track down which user script request (code in general) is causing an error being thrown.

I can of course hack in a stderr message in a fork but thought something more elegant might be available.

Applies to mishoo/UglifyJS#448

Thanks so much.

Typescript

Would be very nice if you also support Typescript compiling

Don't minify but do everything else?

We were wondering if you would consider adding the feature of disabling minification but still parse and compile available types (e.g. add a separate option in to negate the "Notice that this would also disabling CoffeeScript/SCSS/LESS/Stylus parsing for this response." for response._no_minify)

Currently our project has two development modes detected... dev and dbg (develompent and debug). When we are in debug mode we would like to be able to disable minification for extreme debugging purposes but still enable parsing and compiling. Currently there is nothing like response._no_minification = true;, or similar, to prevent result = cssmin(content) calls from happening similar to response._no_cache. e.g. perhaps something like result = identifier._no_minification ? content : cssmin(content)?

We can use another package in a very small group (in their unusual way) for our debug environment but it would be awesome to see this feature here as your package appears to be handling this according to the specs and is very clean in comparison.

Thanks so much for the consideration and this is definitely one of my more favorite packages. :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.