brunodd brunodd - 2 months ago 18
Javascript Question

Grunt uglify - Update src after combining files

I am combining all my js files for production using

unglify
but after combining them and generating my final
app.min.js
file, how I can update the
script src
?

The index file should have only one
<script>
tag with
app.min.js
but instead its pointing to all sources that I used on develop mode.

uglify: {
options: {
mangle: false
},
all: {
files: [{
expand: true,
cwd: 'dev/assets/js',
src: ['*.js', '**/*.js'],
dest: 'prod/assets/js'
}]
},
my_target: {
files: {
'prod/js/app.min.js' : ['prod/assets/js/**/*.js']
}
}
}

Answer

Take a look at the node package 'grunt-processhtml'. It will update the source links in your html file.

<!-- build:js app.min.js -->
<script src="my/lib/path/lib.js"></script>
<script src="my/deep/development/path/script.js"></script>
<!-- /build -->

<!-- changed to -->
<script src="app.min.js"></script>
Comments