forked from silvermine/videojs-quality-selector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
170 lines (148 loc) · 4.54 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* Copyright (c) 2017 Jeremy Thomerson
* Licensed under the MIT license.
*/
var path = require('path'),
getCodeVersion = require('silvermine-serverless-utils/src/get-code-version');
const sass = require('sass');
module.exports = function(grunt) {
var DEBUG = !!grunt.option('debug'),
pkgJSON = grunt.file.readJSON('package.json'),
config, versionInfo;
try {
versionInfo = getCodeVersion.both();
} catch(e) {
// When this package is installed as a git URL, getCodeVersion throws an error and
// is not able to find the git version for this package. So, we fall back to using
// the version number from package.json
versionInfo = pkgJSON.version;
}
config = {
js: {
all: [ 'Gruntfile.js', 'src/**/*.js', 'tests/**/*.js' ],
standalone: path.join(__dirname, 'src', 'js', 'standalone.js'),
},
sass: {
base: path.join(__dirname, 'src', 'scss'),
all: [ 'src/**/*.scss' ],
},
dist: {
base: path.join(__dirname, 'dist'),
jsFileName: 'silvermine-videojs-quality-selector',
},
};
config.dist.js = {
bundle: path.join(config.dist.base, 'js', '<%= config.dist.jsFileName %>.js'),
minified: path.join(config.dist.base, 'js', '<%= config.dist.jsFileName %>.min.js'),
};
config.dist.css = {
base: path.join(config.dist.base, 'css'),
all: path.join(config.dist.base, '**', '*.css'),
};
grunt.initConfig({
pkg: pkgJSON,
versionInfo: versionInfo,
config: config,
browserify: {
main: {
src: config.js.standalone,
dest: config.dist.js.bundle,
options: {
transform: [
[
'babelify',
{
presets: [
[
'@babel/preset-env',
{
debug: true,
useBuiltIns: 'usage',
shippedProposals: true,
corejs: 3,
},
],
],
},
],
],
},
},
},
uglify: {
main: {
files: {
'<%= config.dist.js.minified %>': config.dist.js.bundle,
},
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> <%= versionInfo %> */\n',
sourceMap: true,
sourceMapIncludeSources: true,
mangle: true,
compress: true,
beautify: false,
},
},
},
sass: {
options: {
implementation: sass,
sourceMap: DEBUG,
indentWidth: 3,
outputStyle: DEBUG ? 'expanded' : 'compressed',
sourceComments: DEBUG,
},
main: {
files: [
{
expand: true,
cwd: config.sass.base,
src: [ '**/*.scss' ],
dest: config.dist.css.base,
ext: '.css',
extDot: 'first',
},
],
},
},
postcss: {
options: {
map: DEBUG,
processors: [
require('autoprefixer')({ browsers: '> .05%' }), // eslint-disable-line global-require
],
},
main: {
src: config.dist.css.all,
},
},
clean: {
dist: config.dist.base,
},
watch: {
grunt: {
files: [ 'Gruntfile.js' ],
tasks: [ 'build' ],
},
js: {
files: [ 'src/**/*.js' ],
tasks: [ 'build-js' ],
},
css: {
files: [ 'src/**/*.scss' ],
tasks: [ 'build-css' ],
},
},
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-sass');
grunt.registerTask('build-js', [ 'browserify', 'uglify' ]);
grunt.registerTask('build-css', [ 'sass', 'postcss' ]);
grunt.registerTask('build', [ 'build-js', 'build-css' ]);
grunt.registerTask('develop', [ 'build', 'watch' ]);
grunt.registerTask('default', [ 'standards' ]);
};