grunt-closure-compiler icon indicating copy to clipboard operation
grunt-closure-compiler copied to clipboard

How to compile js files and put them into the same directory

Open skotchio opened this issue 11 years ago • 2 comments

I need to compile all files in js folder and put them into the same one with the same names. So I have the following structure:

So my compile-compiler task is:

'closure-compiler': {
   js: 'js/*.js',
   jsOutputFile: 'js/*
}

But I get the following error:

Duplicate input js\app.js

skotchio avatar Mar 17 '13 18:03 skotchio

yes this is question - I cant setup this is only compiler - just looping is needed

alamehor avatar Jul 26 '17 23:07 alamehor

@skotchio We recently configured this for our large project. We wanted to compile a .js file minify and put it back into the same path as the regular .js file. The following is how we achieved what you want:

'closure-compiler': {
    // minify JS files in-place 
    compileInPlace: {
        files: [
            {
	        expand: true,
		cwd: './',
		src: [
                    'js/edit.js',
                    // ....more files
                ],
		dest: './',
		rename: function (dest, src) {
		    // NOTE : this is done so we can support files "abc.def.js" and preserve the ".def" part.
		    return dest + '/' + src.replace('.js', '.min.js');
		}
	    }
	],
	options: {} // ... your options here
    },
}

Based on the configuration above, it will take js/edit.js and closure compile it into a file called js/edit.min.js. Hope this helps you out!

sebastianKline avatar Apr 13 '18 15:04 sebastianKline