Skip to content

Instantly share code, notes, and snippets.

@vtanathip
Last active December 21, 2015 05:49
Show Gist options
  • Save vtanathip/6260183 to your computer and use it in GitHub Desktop.
Save vtanathip/6260183 to your computer and use it in GitHub Desktop.
grunt configuration for profile management with grunt replace plugin ref: https://github.com/outaTiME/grunt-replace
replace: {
local:{
options:{
variables:{
'host':'http://localhost'
},
prefix: '@@'
},
files: [
{src: ['app/scripts/services/services.js'], dest: 'app/scripts/prod/services/services.js'}
]
},
dist:{
options:{
variables:{
'host':'http://some.dist.host.com'
},
prefix: '@@'
},
files: [
{src: ['app/scripts/services/services.js'], dest: 'app/scripts/prod/services/services.js'}
]
}
}
//and declare var in javascript files (in this case services.js)
var host = "@@host";
grunt replace:dist
grunt replace:local
//for running server
grunt.registerTask('server', function (target) {
if (target === 'dist') {
return grunt.task.run([
//add task to replace it (dist)
'replace:dist',
'build',
'open',
'connect:dist:keepalive',
'replace:dist'
]);
}
grunt.task.run([
//add task to replace it (local)
'replace:local',
'clean:server',
'concurrent:server',
'connect:livereload',
'open',
'watch'
]);
});
//for maven-yeo-plugin or when we want to deploy it
grunt.registerTask('build', [
//and don't forget to add this task to build process
'replace:dist',
'clean:dist',
'useminPrepare',
'concurrent:dist',
'concat',
'copy',
'cdnify',
'ngmin',
'cssmin',
'uglify',
'rev',
'usemin'
]);
<!-- change include file path to compiled file-->
<script src="scripts/compiled/services/services.js"></script>
//pom.xml configuration for integrate with java project (that's mean you can use java profile and build yo from `mvn`)
<plugin>
<groupId>com.github.trecloux</groupId>
<artifactId>yeoman-maven-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment