-
Notifications
You must be signed in to change notification settings - Fork 14
/
Gruntfile.js
122 lines (109 loc) · 3.32 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
module.exports = function(grunt) {
// Load grunt tasks automatically as needed ("jit")
require('jit-grunt')(grunt, {
babel: 'grunt-babel',
clean: 'grunt-contrib-clean',
cssmin: 'grunt-contrib-cssmin',
extract_sourcemap: 'grunt-extract-sourcemap',
mochaTest: 'grunt-mocha-test',
protractor: 'grunt-protractor-runner',
uglify: 'grunt-contrib-uglify'
});
// Time how long tasks take. Just for fun
require('time-grunt')(grunt);
// Define the configuration for all the tasks
grunt.initConfig({
// clean out directories
clean: {
browser: {
files: [{
cwd: '.',
src: ['tmp', 'browser-dist/*']
}]
} ,
npm: {
files: [{
cwd: '.',
src: ['source-cjs/*']
}]
}
},
// This configures the npm build (for which we just need the modules
// converted to CommonJS modules).
babel: {
npm: {
options: {
sourceMap: true,
plugins: ["@babel/plugin-transform-modules-commonjs", "@babel/plugin-proposal-class-properties"],
},
files: [{
cwd: 'source',
expand: true,
src: '*.js',
dest: './source-cjs/'
}]
}
},
// use browserify to prepare the files for client-side use
// This is now also used for the npm package. We need to transpile
// for server-side use because of the use of ES6 modules.
browserify: {
browser: {
options: {
browserifyOptions: {
debug: true,
standalone: "ucumPkg"
},
transform: [["babelify", { "presets": ["@babel/preset-env"],
plugins: ["@babel/plugin-transform-modules-commonjs", "@babel/plugin-proposal-class-properties"] }]]
},
debug: true,
files: [{dest: "./browser-dist/ucum-lhc.js",
src: ["./source/ucumPkg.js"]}
]
}
},
extract_sourcemap: {
browser: {
files: {
'browser-dist': ['browser-dist/ucum-lhc.js']
}
}
},
// use uglify to minify the javascript files
uglify: {
options: { sourceMap: true, compress: true },
browser: {
options: {
sourceMap: {
includeSources: true
},
sourceMapIn: './browser-dist/ucum-lhc.js.map'
},
files: {
'./browser-dist/ucum-lhc.min.js' : [ './browser-dist/ucum-lhc.js']
}
}
} ,
// using mocha for the tests
mochaTest: {
options: {
// require: '@babel/register', // Commenting out automatic transpilation so we can test the CommonJS (npm) build
reporter: 'spec'
} ,
src: ['./test/*.spec.js']
}
}); // end grunt.initConfig
// load and register the tasks
grunt.loadNpmTasks("grunt-babel");
grunt.loadNpmTasks("grunt-browserify");
grunt.registerTask("build:npm", ["clean:npm", "babel:npm"]);
grunt.registerTask("build:browser", ["clean:browser",
"browserify:browser",
"extract_sourcemap:browser",
"uglify:browser"]);
grunt.registerTask("build", ["build:browser",
"build:npm"]);
grunt.registerTask("test", ['build',
'mochaTest']);
};