-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.js
68 lines (64 loc) · 2.53 KB
/
Gruntfile.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
module.exports = function(grunt) {
var pkg = require('./package.json'),
fs = require('fs'),
banner = '/*! '+pkg.name+' '+pkg.version+' by '+pkg.author+' license: '+pkg.license+' */\n',
umd = '(function (root, factory) {\n'
+ " if (typeof define === 'function' && define.amd) {\n"
+ " define(['MediumEditor'], factory);\n"
+ " } else if (typeof module === 'object') {\n"
+ " module.exports = factory(require('medium-editor'));\n"
+ " } else {\n"
+ " root.MEmbed = factory(root.MediumEditor);\n"
+ "}\n"
+ "}(this, function (Medium) {\n"
+ "'use strict';";
grunt.initConfig({
pkg: pkg,
requirejs: {
options: {
baseUrl: "./js",
include: ['Extension', 'Request', 'View'],
wrap: {
start: banner + umd,
end: '\n}));'
},
paths: {
MediumEditor: "//cdn.jsdelivr.net/medium-editor/5.8.2/js/medium-editor.min"
},
onBuildWrite: function(name, path, contents)
{
contents = contents.replace(/define\((.|\s)*?\{/, '');
contents = contents.replace(/}\s*\)\s*;*\s*?.*$/, '');
if ( name !== 'Extension' ) {
contents = contents.replace(/return.*[^return]*$/, '');
}
return contents;
}
},
concat: {
options: {
optimize: 'none',
out: function ( text ) {
fs.writeFileSync('./dist/js/medium-editor-m-embed.js', text);
}
}
},
dist: {
options: {
optimize: "uglify2",
out: function ( text ) {
fs.writeFileSync('./dist/js/medium-editor-m-embed.min.js', text);
}
}
}
},
jshint: {
all: ['js/Extension.js', 'js/Request.js', 'js/View.js']
}
});
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('concat', ['requirejs:concat']);
grunt.registerTask('dist', ['requirejs:dist']);
grunt.registerTask('default', ['requirejs:concat','requirejs:dist']);
};