Last active
August 29, 2015 14:11
-
-
Save Thorium/0868e4afda7717187e2a to your computer and use it in GitHub Desktop.
JavaScript minifier for FunScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FunScript http://funscript.info/ generates quite large un-compressed js-file. | |
So this is a JavaScript minifier for FunScript | |
1) Install node.js: http://nodejs.org/download/ | |
2) That is just used for npm https://www.npmjs.com/ to get Gulp: http://gulpjs.com/ | |
3) Create gulpfile.js | |
- To the FunScript-output folder (default: bin/Debug). | |
- There is example below. | |
4) Either run "gulp" from the shell or modify your FunScript deployment to use these f-sharp codes. | |
4) Then just execute and generate fs-scripts with FunScript as usual. | |
- Now, minified .min.js and JavaScript source-maps (.min.js.map)-files are also generated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Put this file to your FunScript output folder. | |
var gulp = require('gulp'), | |
concat = require('gulp-concat'), | |
uglify = require('gulp-uglify'), | |
sourcemaps = require('gulp-sourcemaps'); | |
var jsfile = { | |
targetPath: '', | |
//This is your FunScript-generated .js-file: | |
sources: ['generated.js'] | |
}; | |
function minifyJs() { | |
return gulp.src(jsfile.sources) | |
.pipe(sourcemaps.init()) | |
.pipe(concat('/generated.min.js')) | |
.pipe(uglify()) | |
.pipe(sourcemaps.write('/.')) | |
.pipe(gulp.dest(jsfile.targetPath)); | |
} | |
// If you call this from f-sharp-script, use this task | |
gulp.task('minifyJs', minifyJs); | |
// Or... | |
// npm install --save-dev gulp gulp-concat gulp-uglify gulp-sourcemaps | |
// If you just run "gulp" from command-line: | |
// Gulp monitors modifications of this generated.js -file (defined in jsfile.sources) and minifies it on the fly | |
gulp.task('default', function () { | |
gulp.watch(jsfile.sources, ['minifyJs']); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is just optional helper if you would like to run Gulp from the FunScript. | |
let private dir file = Path.Combine(System.Environment.CurrentDirectory, file) | |
let private execute (cmd,parameter) = System.Diagnostics.Process.Start(cmd, parameter).WaitForExit() | |
let writeTempFile code = | |
let generatedTemp = dir "generated.js" | |
if File.Exists generatedTemp then | |
File.Delete generatedTemp | |
File.WriteAllText(generatedTemp, code) | |
generatedTemp | |
let installGulpComponents path = | |
let nodePath = @"c:\Program Files\nodejs\npm.cmd" | |
let install = nodePath, "install --save-dev gulp gulp-concat gulp-uglify gulp-sourcemaps" | |
execute install | |
let minify file = | |
let gulpPath = dir @"node_modules\.bin\gulp.cmd" | |
if not <| File.Exists(gulpPath) then | |
installGulpComponents gulpPath | |
let minifiedTemp = dir "generated.min.js" | |
if File.Exists minifiedTemp then | |
File.Delete minifiedTemp | |
let gulpTask = "minifyJs"; | |
execute (gulpPath,gulpTask) | |
let result = minifiedTemp |> File.ReadAllText | |
result | |
let minified = | |
let temp = writeTempFile code | |
minify temp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment