-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gruntfile.js
134 lines (124 loc) · 3.21 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
var path = require('path')
var webpack = require('webpack')
module.exports = function (grunt) {
var user_config = grunt.file.readJSON('user_config.json');
var paths = {
header: 'src/greasemonkey_header.js',
dest: 'bin/tofu.user.js'
};
// TODO(): avoid using prepends for gm wrapper and jsutils
function prependFile() {
var header = grunt.file.read(paths.header);
var bin = grunt.file.read(paths.dest);
grunt.file.write(paths.dest, header + bin);
}
// webpack plugins are objects with an apply method
var afterWebpackBuild = {
apply: function (compiler) {
compiler.plugin('done', function () {
prependFile();
})
}
};
grunt.initConfig({
'gm-header': {
options: {
dest: 'bin/tofu.user.js'
}
},
copy: {
main: {
src: 'src/tofu-dev.user.js',
dest: 'bin/tofu-dev.user.js',
},
},
jshint: {
options: {
jshintrc: 'src/.jshintrc'
},
beforeconcat: ['Gruntfile.js', 'src/includes/*.js', 'src/includes/**/*.js']
//afterconcat : ['tofu.user.js']
},
webpack: {
options: {
resolve: {
alias: {
utils: path.resolve(__dirname, 'src/core/utils'),
libs: path.resolve(__dirname, 'src/assets/libs'),
templates: path.resolve(__dirname, 'src/templates'),
plugins: path.resolve(__dirname, 'src/plugins_disabled'),
// 'jquery': 'cash-dom',
'jquery': 'jquery-slim',
},
modules: [
'node_modules',
'src',
]
}
},
devel: {
entry: {
tofu: './src/main.js'
},
plugins: [
new webpack.LoaderOptionsPlugin({
debug: true
})
],
output: {
path: path.resolve(__dirname, 'bin'),
filename: '[name].user.js'
},
devtool: "source-map",
module: {
rules: [
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'base64-inline-loader',
],
},
],
},
mode: "production",
},
watch: {
entry: {
tofu: './src/main.js'
},
plugins: [
new webpack.LoaderOptionsPlugin({
debug: true
})
],
output: {
path: path.resolve(__dirname, 'bin'),
filename: '[name].user.js'
},
mode: "development",
module: {
rules: [
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'base64-inline-loader',
],
},
]
},
plugins: [afterWebpackBuild],
watch: true,
failOnError: false,
keepalive: true
}
}
});
grunt.loadNpmTasks('grunt-webpack');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('gm-header', prependFile);
grunt.registerTask('release', ['webpack:devel']);
// grunt.registerTask('release', ['webpack:devel', 'gm-header']);
grunt.registerTask('default', ['copy', 'webpack:watch' ]);
};