-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
129 lines (117 loc) · 3.38 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
"use strict";
const webpackConfig = require("./webpack.config");
const { merge } = require('webpack-merge');
module.exports = function (grunt) {
grunt.initConfig({
watch: getWatch(),
webpack: getWebpack(),
clean: getClean(),
checkDependencies: {
this: {}
}
});
getGruntLibs(grunt);
registerGruntTasks(grunt);
};
function getWatch() {
return {
updateSourceFiles: {
files: ["./src/**/*"],
tasks: ["webpack:develop"],
options: {
debounceDelay: 250,
livereload: true
}
}
};
}
function getWebpack() {
return {
develop: webpackConfig,
developProd: webpackConfigDevProd,
release: webpackConfigRelease,
test: webpackConfigTest
};
}
function getClean() {
return {
build: [
"./dist/**/*",
"./dist/testresults/**/*",
]
};
}
function getGruntLibs(grunt) {
grunt.loadNpmTasks("grunt-check-dependencies");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-file-append");
grunt.loadNpmTasks("grunt-webpack");
}
function registerGruntTasks(grunt) {
grunt.registerTask("default", ["clean build", "watch"]);
grunt.registerTask(
"clean build",
"Compiles all the assets and copies the files to the dist directory.",
["checkDependencies", "clean:build", "webpack:develop"]
);
grunt.registerTask(
"release",
"Compiles all the assets and copies the files to the dist directory. Minified without source mapping",
["checkDependencies", "clean:build", "webpack:release"]
);
grunt.registerTask(
"test",
"Compiles all the assets and copies the files to the dist directory. Minified without source mapping",
["checkDependencies", "clean:build", "webpack:test"]
);
grunt.registerTask(
"developProd",
"Compiles all the assets and copies the files to the dist directory. Minified without source mapping",
["checkDependencies", "clean:build", "webpack:developProd"]
);
grunt.registerTask("build", ["clean build"]);
}
const baseWebpackConfigTest = merge(webpackConfig, {
devtool: false,
optimization: {
minimize: true
}
});
const webpackConfigTest = merge(baseWebpackConfigTest, {
module: {
rules: [
replaceStringInRule(/\.env$/, 'development', 'test')
]
}
});
const webpackConfigDevProd= merge(baseWebpackConfigTest, {
mode: "development",
module: {
rules: [
replaceStringInRule(/\.json$/, 'localhost:3000', '165.227.247.77:3000'),
replaceStringInRule(/\.env$/, 'development', 'production')
]
}
});
const webpackConfigRelease = merge(baseWebpackConfigTest, {
mode: "production",
module: {
rules: [
replaceStringInRule(/\.json$/, 'localhost:3000', 'ment-backend.herokuapp.com:3000'),
replaceStringInRule(/\.env$/, 'development', 'production')
]
}
});
function replaceStringInRule(filePattern, search, replace) {
return {
test: filePattern,
loader: 'string-replace-loader',
options: {
multiple: [{
search, replace
}]
}
};
}