-
Notifications
You must be signed in to change notification settings - Fork 939
Expand file tree
/
Copy pathdist.js
More file actions
36 lines (31 loc) · 1.1 KB
/
dist.js
File metadata and controls
36 lines (31 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"use strict";
var fs = require( "fs" );
module.exports = function( grunt ) {
grunt.registerTask( "dist", "Process files for distribution", function() {
var files = grunt.file.expand( { filter: "isFile" }, "dist/*" );
files.forEach( function( filename ) {
var map,
text = fs.readFileSync( filename, "utf8" );
// Modify map/min so that it points to files in the same folder;
// see https://github.com/mishoo/UglifyJS2/issues/47
if ( /\.map$/.test( filename ) ) {
text = text.replace( /"dist\//g, "\"" );
fs.writeFileSync( filename, text, "utf-8" );
} else if ( /\.min\.js$/.test( filename ) ) {
// Wrap sourceMap directive in multiline comments (#13274)
text = text.replace( /\n?(\/\/@\s*sourceMappingURL=)(.*)/,
function( _, directive, path ) {
map = "\n" + directive + path.replace( /^dist\//, "" );
return "";
} );
if ( map ) {
text = text.replace( /(^\/\*[\w\W]*?)\s*\*\/|$/,
function( _, comment ) {
return ( comment || "\n/*" ) + map + "\n*/";
} );
}
fs.writeFileSync( filename, text, "utf-8" );
}
} );
} );
};