1
+ const webpackConfig = require ( './webpack.config.js' ) ;
2
+
1
3
module . exports = function ( grunt ) {
2
4
3
5
grunt . initConfig ( {
@@ -10,148 +12,9 @@ module.exports = function(grunt) {
10
12
src : [ 'src/**/*.js' , 'test/tests/**/*.js' ]
11
13
}
12
14
} ,
13
- watch : {
14
- // p5 dist
15
- main : {
16
- files : [ 'src/**/*.js' ] ,
17
- tasks : [ 'requirejs' ] ,
18
- options : {
19
- livereload : {
20
- port : 35728
21
- }
22
- } ,
23
- }
24
- } ,
25
- requirejs : {
26
- unmin : {
27
- options : {
28
- baseUrl : '.' ,
29
- findNestedDependencies : true ,
30
- include : [ 'src/app' ] ,
31
- onBuildWrite : function ( name , path , contents ) {
32
- if ( path . indexOf ( 'node_modules/tone/' ) > - 1 ) {
33
- return '/** Tone.js module by Yotam Mann, MIT License 2016 http://opensource.org/licenses/MIT **/\n' +
34
- require ( 'amdclean' ) . clean ( {
35
- 'code' : contents . replace ( / c o n s o l e .l o g ( .* ) ; / g, '' ) ,
36
- 'escodegen' : {
37
- 'comment' : false ,
38
- 'skipDirOptimize' :true ,
39
- 'format' : {
40
- 'indent' : {
41
- 'style' : ' ' ,
42
- 'adjustMultiLineComment' : true
43
- }
44
- }
45
- }
46
- } ) ;
47
- } else if ( path . indexOf ( 'node_modules/startaudiocontext' ) > - 1 ) {
48
- // return '/** StartAudioContext.js by Yotam Mann, MIT License 2017 https://github.com/tambien/StartAudioContext http://opensource.org/licenses/MIT **/\n' +
49
- return require ( 'amdclean' ) . clean ( {
50
- code : contents ,
51
- escodegen : {
52
- comment : false ,
53
- format : {
54
- indent : {
55
- style : ' ' ,
56
- adjustMultiLineComment : true
57
- }
58
- }
59
- }
60
- } ) ;
61
- } else {
62
- return require ( 'amdclean' ) . clean ( {
63
- 'code' :contents ,
64
- 'escodegen' : {
65
- 'comment' : true ,
66
- 'format' : {
67
- 'indent' : {
68
- 'style' : ' ' ,
69
- 'adjustMultiLineComment' : true
70
- }
71
- }
72
- }
73
- } ) ;
74
- }
75
- } ,
76
- optimize : 'none' ,
77
- out : 'lib/p5.sound.js' ,
78
- paths : {
79
- 'Tone' : 'node_modules/tone/Tone' ,
80
- 'StartAudioContext' : 'node_modules/startaudiocontext/StartAudioContext' ,
81
- 'automation-timeline' : 'node_modules/web-audio-automation-timeline/build/automation-timeline-amd' ,
82
- 'panner' : 'src/panner' ,
83
- 'shims' : 'src/shims' ,
84
- 'audiocontext' : 'src/audiocontext' ,
85
- 'master' : 'src/master' ,
86
- 'helpers' : 'src/helpers' ,
87
- 'errorHandler' : 'src/errorHandler' ,
88
- 'soundfile' : 'src/soundfile' ,
89
- 'amplitude' : 'src/amplitude' ,
90
- 'fft' : 'src/fft' ,
91
- 'oscillator' : 'src/oscillator' ,
92
- 'pulse' : 'src/pulse' ,
93
- 'noise' : 'src/noise' ,
94
- 'audioin' : 'src/audioin' ,
95
- 'envelope' : 'src/envelope' ,
96
- 'delay' : 'src/delay' ,
97
- 'effect' : 'src/effect' ,
98
- 'panner3d' : 'src/panner3d' ,
99
- 'listener3d' : 'src/listener3d' ,
100
- 'filter' : 'src/filter' ,
101
- 'reverb' : 'src/reverb' ,
102
- 'eq' : 'src/eq' ,
103
- 'distortion' : 'src/distortion' ,
104
- 'compressor' : 'src/compressor' ,
105
- 'looper' : 'src/looper' ,
106
- 'soundloop' : 'src/soundLoop' ,
107
- 'soundRecorder' : 'src/soundRecorder' ,
108
- 'signal' : 'src/signal' ,
109
- 'metro' : 'src/metro' ,
110
- 'peakdetect' : 'src/peakDetect' ,
111
- 'gain' : 'src/gain' ,
112
- 'audioVoice' : 'src/audioVoice' ,
113
- 'monosynth' : 'src/monosynth' ,
114
- 'polysynth' : 'src/polysynth'
115
- } ,
116
- useStrict : true ,
117
- wrap : {
118
- start : '/*! p5.sound.js v<%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' + grunt . file . read ( './fragments/before.frag' ) ,
119
- end : grunt . file . read ( './fragments/after.frag' )
120
- }
121
- }
122
- } ,
123
- min : {
124
- options : {
125
- baseUrl : '.' ,
126
- findNestedDependencies : true ,
127
- include : [ 'src/app' ] ,
128
- onBuildWrite : function ( name , path , contents ) {
129
- if ( path . indexOf ( 'node_modules/tone/' ) > - 1 ) {
130
- return require ( 'amdclean' ) . clean ( {
131
- 'code' :contents . replace ( / c o n s o l e .l o g ( .* ) ; / g, '' ) ,
132
- 'escodegen' : {
133
- 'comment' : false
134
- }
135
- } ) ;
136
- } else {
137
- return require ( 'amdclean' ) . clean ( {
138
- 'code' :contents ,
139
- 'escodegen' : {
140
- 'comment' : false
141
- }
142
- } ) ;
143
- }
144
- } ,
145
- optimize : 'uglify2' ,
146
- out : 'lib/p5.sound.min.js' ,
147
- paths : '<%= requirejs.unmin.options.paths %>' ,
148
- useStrict : true ,
149
- wrap : {
150
- start : '/*! p5.sound.min.js v<%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' + grunt . file . read ( './fragments/before.frag' ) ,
151
- end : grunt . file . read ( './fragments/after.frag' )
152
- }
153
- }
154
- } ,
15
+ webpack : {
16
+ prod : webpackConfig ,
17
+ dev : Object . assign ( { watch : true } , webpackConfig )
155
18
} ,
156
19
open : {
157
20
testChrome : {
@@ -179,15 +42,14 @@ module.exports = function(grunt) {
179
42
} ) ;
180
43
181
44
182
- grunt . loadNpmTasks ( 'grunt-contrib-requirejs ' ) ;
45
+ grunt . loadNpmTasks ( 'grunt-webpack ' ) ;
183
46
grunt . loadNpmTasks ( 'grunt-eslint' ) ;
184
- grunt . loadNpmTasks ( 'grunt-contrib-watch' ) ;
185
47
grunt . loadNpmTasks ( 'grunt-contrib-connect' ) ;
186
48
grunt . loadNpmTasks ( 'grunt-open' ) ;
187
49
188
50
grunt . registerTask ( 'lint' , [ 'eslint:source' ] ) ;
189
- grunt . registerTask ( 'default' , [ 'requirejs ' ] ) ;
190
- grunt . registerTask ( 'dev' , [ 'connect' , 'requirejs' , 'watch '] ) ;
51
+ grunt . registerTask ( 'default' , [ 'webpack:prod ' ] ) ;
52
+ grunt . registerTask ( 'dev' , [ 'connect' , 'webpack:dev ' ] ) ;
191
53
grunt . registerTask ( 'serve' , 'connect:server:keepalive' ) ;
192
54
grunt . registerTask ( 'run-tests' , [ 'serve' , 'open' ] ) ;
193
55
} ;
0 commit comments