-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
164 lines (146 loc) · 5.04 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
'use strict';
var path = require('path');
var sass = require('node-sass');
const bourbon_includePaths = require('node-bourbon').includePaths;
const slick_includePaths = path.join(__dirname,'node_modules','slick-carousel', 'slick');
const theme_root = './wp-content/themes/custom';
const output_dir = path.join( theme_root, 'bundles' );
const scss_main_dir = path.join( theme_root, 'scss' );
const scss_main_src = path.join( scss_main_dir, 'main.scss' );
const scss_admin_src = path.join( scss_main_dir, 'admin.scss' )
const scss_watch_src = path.join( scss_main_dir, '**', '*.scss' );
const css_main_dest = path.join( output_dir, 'bundle.css' );
const css_admin_dest = path.join( output_dir, 'admin-bundle.css' );
const js_main_dir = path.join( theme_root, 'js' );
const js_main_src = path.join( js_main_dir, 'main.js' );
const js_watch_src = path.join( js_main_dir, '**', '*.js');
const js_main_dest = path.join( output_dir, 'bundle.js' );
const php_watch_dest = path.join( theme_root, '**', '*.php');
module.exports = function(grunt) {
require('jit-grunt')( grunt, {
'sass': 'grunt-sass',
'watch': 'grunt-contrib-watch',
'extract_sourcemap': 'grunt-extract-sourcemap',
'browserify': 'grunt-browserify'
});
var extract_files = {};
extract_files[ output_dir ] = [ js_main_dest ];
grunt.initConfig({
pkg: grunt.file.readJSON( 'package.json' ),
sass: {
options: {
implementation: sass,
includePaths: [ slick_includePaths ].concat( bourbon_includePaths )
},
adminDev: {
options: {
sourceMap: true,
sourceComments: true,
outputStyle: 'expanded',
},
files: [{
src: [ scss_admin_src ],
dest: css_admin_dest,
}]
},
adminDist: {
options: {
sourceMap: true,
sourceComments: false,
outputStyle: 'compressed'
},
files: [{
src: [ scss_admin_src ],
dest: css_admin_dest,
}]
},
dev: {
options: {
sourceMap: false,
sourceComments: false,
outputStyle: 'compressed',
},
files: [{
src: [ scss_main_src ],
dest: css_main_dest,
}]
},
dist: {
options: {
sourceMap: true,
sourceComments: false,
outputStyle: 'compressed'
},
files: [{
src: [ scss_main_src ],
dest: css_main_dest,
}]
}
},
browserify: {
dev: {
src: [ js_main_src ],
dest: js_main_dest,
options: {
watch: true,
browserifyOptions: {
debug: false // true for sourcemaps
},
transform: [
['babelify', {presets: 'env'}],
['uglifyify', {global: true}] //false for unminified
]
}
},
dist: {
src: [ js_main_src ],
dest: js_main_dest,
options: {
transform: [
['babelify', {presets: 'env'}],
['uglifyify', {global: true}]
]
}
}
},
extract_sourcemap: {
dev: {
options: { removeSourcesContent: true },
files: extract_files
}
},
watch: {
options: {
atBegin: false,
livereload: true
},
scss: {
options: {
livereload: false,
interrupt: true
},
files: [ scss_watch_src ],
tasks: ['sass:dev', 'sass:adminDev'],
},
css: {
files: [ css_main_dest ],
tasks: []
},
js: {
files: [ js_main_dest ],
tasks: []
},
php: {
files: [ php_watch_dest ],
tasks: []
}
},
});
// grunt.loadNpmTasks('grunt-contrib-watch');
// grunt.loadNpmTasks('grunt-sass');
// grunt.loadNpmTasks('grunt-browserify');
// grunt.loadNpmTasks('grunt-extract-sourcemap');
grunt.registerTask('default', ['sass:dev', 'browserify:dev', 'extract_sourcemap:dev', 'watch']);
grunt.registerTask('dev', ['browserify:dev','sass:dev', 'sass:adminDev', 'extract_sourcemap:dev']);
grunt.registerTask('dist', ['browserify:dist','sass:dist', 'sass:adminDist']);
};