forked from mozilla/webextension-polyfill
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
100 lines (90 loc) · 2.67 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
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
const LICENSE = `/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */`;
const MINIFIED_FILE_FOOTER = `\n// <%= pkg.name %> v.<%= pkg.version %> (<%= pkg.homepage %>)\n\n${LICENSE}\n`;
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
eslint: {
src: ["src/browser-polyfill.js", "Gruntfile.js"],
test: ["test/**/*.js", "scripts/**/*.js"],
},
replace: {
dist: {
options: {
patterns: [
{
match: /\{\/\* include\("(.*?)"\) \*\/\}/,
replacement: (match, filename) => {
return grunt.file.read(filename)
.replace(/\n$/, "")
.replace(/^[^{]/gm, " $&");
},
},
{
json: {
"package_name": "<%= pkg.name %>",
"version": "<%= pkg.version %>",
"timestamp": "<%= grunt.template.today() %>",
},
},
],
},
files: [
{
expand: true,
flatten: true,
src: ["src/browser-polyfill.js"],
dest: "dist/",
},
],
},
},
babel: {
minify: {
options: {
babelrc: false,
comments: false,
presets: ["minify"],
sourceMap: true,
},
files: {
"dist/browser-polyfill.min.js": "dist/browser-polyfill.js",
},
},
umd: {
options: {
babelrc: false,
comments: true,
plugins: [
["./scripts/babel-transform-to-umd-module", {
globalName: "browser",
amdModuleName: "webextension-polyfill",
}],
],
sourceMap: true,
moduleId: "webextension-polyfill",
},
files: {
"dist/browser-polyfill.js": "dist/browser-polyfill.js",
},
},
},
concat: {
license: {
src: "dist/browser-polyfill.min.js",
dest: "dist/browser-polyfill.min.js",
options: {footer: MINIFIED_FILE_FOOTER},
},
},
});
grunt.util.linefeed = "\n";
grunt.loadNpmTasks("gruntify-eslint");
grunt.loadNpmTasks("grunt-replace");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-babel");
grunt.registerTask("default", ["eslint", "replace", "babel:umd", "babel:minify", "concat:license"]);
};