Skip to content

Replace requirejs with webpack to enable ES6+ and non-AMD modules #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Gruntfile.js
test/test.js
webpack.config.js
lib/
154 changes: 8 additions & 146 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const webpackConfig = require('./webpack.config.js');

module.exports = function(grunt) {

grunt.initConfig({
Expand All @@ -10,148 +12,9 @@ module.exports = function(grunt) {
src: ['src/**/*.js', 'test/tests/**/*.js']
}
},
watch: {
// p5 dist
main: {
files: ['src/**/*.js'],
tasks: ['requirejs'],
options: {
livereload: {
port: 35728
}
},
}
},
requirejs: {
unmin: {
options: {
baseUrl: '.',
findNestedDependencies: true,
include: ['src/app'],
onBuildWrite: function( name, path, contents ) {
if (path.indexOf('node_modules/tone/') > -1) {
return '/** Tone.js module by Yotam Mann, MIT License 2016 http://opensource.org/licenses/MIT **/\n' +
require('amdclean').clean({
'code': contents.replace(/console.log(.*);/g, ''),
'escodegen': {
'comment': false,
'skipDirOptimize':true,
'format': {
'indent': {
'style': ' ',
'adjustMultiLineComment': true
}
}
}
});
} else if (path.indexOf('node_modules/startaudiocontext') > -1) {
// return '/** StartAudioContext.js by Yotam Mann, MIT License 2017 https://github.com/tambien/StartAudioContext http://opensource.org/licenses/MIT **/\n' +
return require('amdclean').clean({
code: contents,
escodegen: {
comment: false,
format: {
indent: {
style: ' ',
adjustMultiLineComment: true
}
}
}
});
} else {
return require('amdclean').clean({
'code':contents,
'escodegen': {
'comment': true,
'format': {
'indent': {
'style': ' ',
'adjustMultiLineComment': true
}
}
}
});
}
},
optimize: 'none',
out: 'lib/p5.sound.js',
paths: {
'Tone' : 'node_modules/tone/Tone',
'StartAudioContext' : 'node_modules/startaudiocontext/StartAudioContext',
'automation-timeline': 'node_modules/web-audio-automation-timeline/build/automation-timeline-amd',
'panner' : 'src/panner',
'shims': 'src/shims',
'audiocontext': 'src/audiocontext',
'master': 'src/master',
'helpers': 'src/helpers',
'errorHandler': 'src/errorHandler',
'soundfile': 'src/soundfile',
'amplitude': 'src/amplitude',
'fft': 'src/fft',
'oscillator': 'src/oscillator',
'pulse': 'src/pulse',
'noise': 'src/noise',
'audioin': 'src/audioin',
'envelope': 'src/envelope',
'delay': 'src/delay',
'effect': 'src/effect',
'panner3d' : 'src/panner3d',
'listener3d': 'src/listener3d',
'filter': 'src/filter',
'reverb': 'src/reverb',
'eq': 'src/eq',
'distortion': 'src/distortion',
'compressor': 'src/compressor',
'looper': 'src/looper',
'soundloop': 'src/soundLoop',
'soundRecorder': 'src/soundRecorder',
'signal': 'src/signal',
'metro': 'src/metro',
'peakdetect': 'src/peakDetect',
'gain': 'src/gain',
'audioVoice': 'src/audioVoice',
'monosynth': 'src/monosynth',
'polysynth': 'src/polysynth'
},
useStrict: true,
wrap: {
start: '/*! p5.sound.js v<%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' + grunt.file.read('./fragments/before.frag'),
end: grunt.file.read('./fragments/after.frag')
}
}
},
min: {
options: {
baseUrl: '.',
findNestedDependencies: true,
include: ['src/app'],
onBuildWrite: function( name, path, contents ) {
if (path.indexOf('node_modules/tone/') > -1) {
return require('amdclean').clean({
'code':contents.replace(/console.log(.*);/g, ''),
'escodegen': {
'comment': false
}
});
} else {
return require('amdclean').clean({
'code':contents,
'escodegen': {
'comment': false
}
});
}
},
optimize: 'uglify2',
out: 'lib/p5.sound.min.js',
paths: '<%= requirejs.unmin.options.paths %>',
useStrict: true,
wrap: {
start: '/*! p5.sound.min.js v<%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' + grunt.file.read('./fragments/before.frag'),
end: grunt.file.read('./fragments/after.frag')
}
}
},
webpack: {
prod: webpackConfig,
dev: Object.assign({ watch: true }, webpackConfig)
},
open: {
testChrome: {
Expand Down Expand Up @@ -179,15 +42,14 @@ module.exports = function(grunt) {
});


grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-webpack');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-open');

grunt.registerTask('lint', ['eslint:source']);
grunt.registerTask('default', ['requirejs']);
grunt.registerTask('dev', ['connect','requirejs', 'watch']);
grunt.registerTask('default', ['webpack:prod']);
grunt.registerTask('dev', ['connect','webpack:dev']);
grunt.registerTask('serve', 'connect:server:keepalive');
grunt.registerTask('run-tests', ['serve', 'open']);
};
10 changes: 0 additions & 10 deletions fragments/before.frag
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,3 @@
*
* Web Audio API: http://w3.org/TR/webaudio/
*/

(function (root, factory) {
if (typeof define === 'function' && define.amd)
define('p5.sound', ['p5'], function (p5) { (factory(p5));});
else if (typeof exports === 'object')
factory(require('../p5'));
else
factory(root['p5']);
}(this, function (p5) {

Loading