Skip to content

Commit 7388d2e

Browse files
therewasaguyoshoham
authored andcommitted
Replace requirejs with webpack to enable ES6+ and non-AMD modules (#366)
Replace requirejs with webpack to enable ES6+ and non-AMD modules
1 parent d685d9e commit 7388d2e

35 files changed

+15805
-11979
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
Gruntfile.js
22
test/test.js
3+
webpack.config.js
4+
lib/

Gruntfile.js

Lines changed: 8 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const webpackConfig = require('./webpack.config.js');
2+
13
module.exports = function(grunt) {
24

35
grunt.initConfig({
@@ -10,148 +12,9 @@ module.exports = function(grunt) {
1012
src: ['src/**/*.js', 'test/tests/**/*.js']
1113
}
1214
},
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(/console.log(.*);/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(/console.log(.*);/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)
15518
},
15619
open: {
15720
testChrome: {
@@ -179,15 +42,14 @@ module.exports = function(grunt) {
17942
});
18043

18144

182-
grunt.loadNpmTasks('grunt-contrib-requirejs');
45+
grunt.loadNpmTasks('grunt-webpack');
18346
grunt.loadNpmTasks('grunt-eslint');
184-
grunt.loadNpmTasks('grunt-contrib-watch');
18547
grunt.loadNpmTasks('grunt-contrib-connect');
18648
grunt.loadNpmTasks('grunt-open');
18749

18850
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']);
19153
grunt.registerTask('serve', 'connect:server:keepalive');
19254
grunt.registerTask('run-tests', ['serve', 'open']);
19355
};

fragments/before.frag

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,3 @@
6262
*
6363
* Web Audio API: http://w3.org/TR/webaudio/
6464
*/
65-
66-
(function (root, factory) {
67-
if (typeof define === 'function' && define.amd)
68-
define('p5.sound', ['p5'], function (p5) { (factory(p5));});
69-
else if (typeof exports === 'object')
70-
factory(require('../p5'));
71-
else
72-
factory(root['p5']);
73-
}(this, function (p5) {
74-

0 commit comments

Comments
 (0)