Is it possible to configure Ionic to copy custom JS files to the dist folder?

I’ve created a custom JS file in a Ionic2 TypeScript project, located in /app/scripts, and I want it copied to the /build/js automatically when using ionic serve. This is probably a simple task but I couldn’t find any information or an example on how to achieve it. Then I decided to make some experiments and ionic.config.js seemed the logical place to start so I added the following code:

// ...
paths: {
	// ...
	scripts: {
		src: ['app/scripts/**/*.js'],
		dest: 'www/build/js'
	// ...

	watch: {
		// ...
		scripts: ['app/scripts/**/*.js'],
		// ...
// ...

However, this doesn’t seem to work. I also tried with js instead of scripts (as I saw in some partial code pieces I found) but it didn’t work either. I don’t know where to find the code which processes this configuration file (ionic or ionic-cli - any clues are welcome) so I have no idea how to configure it properly.

I’m also not sure if it’s possible to do this only with configuration or I have to create a custom gulp task for it, so I hope that someone can give me a hint.

I just changed the scripts task in the gulpfile.js


//gulp.task('scripts', copyScripts);

gulp.task('scripts', function(){
    var options = {
        'src': [
        'dest': 'www/build/js'
    return copyScripts(options);
1 Like

Thanks for the reply. I agree that now with Gulp it’s a lot easier to achieve this. Back then, when Ionic 2 was still using only Webpack and a custom configuration file, it was not so simple though. :slight_smile:

Do you know where ionic2 decides which js files installed with npm get loaded ? seeing some strange things with some getting loaded and some do not.

Just worked out you have to play with the src property of the options that feed into the browserify command in the gulpfile.