Skip to content

Instantly share code, notes, and snippets.

@stephenplusplus
Last active October 4, 2022 18:52
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stephenplusplus/523314c4bdda1a8ad1c0 to your computer and use it in GitHub Desktop.
Save stephenplusplus/523314c4bdda1a8ad1c0 to your computer and use it in GitHub Desktop.
`grunt-string-replace` in action
angular
.module('app', [
'appDev', // <-- this line will be removed.*
'ngCookies',
'ngSanitize',
'ui.router',
'angularLocalStorage',
'btford.modal',
'reCAPTCHA'
]);
/*
* `appDev` is a module delcared in a file, "app-dev.js". If you look in
* `index.html`, you'll see a reference to this file between a `<!-- remove -->`
* block. That block is removed by `grunt-string-replace`.
*/
module.exports = function (grunt) {
grunt.initConfig({
'string-replace': {
dist: {
files: {
'.tmp/concat/scripts/app.js': ['.tmp/concat/scripts/app.js'],
'<%= yeoman.dist %>/index.html': ['<%= yeoman.dist %>/index.html']
},
options: {
replacements: [
{
pattern: /['"]appDev['"],*/gi,
replacement: ''
},
{
pattern: /[\s\t]*<!--\s*remove\s*-->(\n|\r|.)*?(<!--\s*endremove\s*-->)/gi,
replacement: ''
}
]
}
}
}
});
};
<html>
<body>
<!-- build:js /scripts/vendor.js -->
<!-- bower:js -->
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular-cookies/angular-cookies.js"></script>
<script src="/bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="/bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="/bower_components/angularLocalStorage/src/angularLocalStorage.js"></script>
<script src="/bower_components/angular-modal/modal.js"></script>
<!-- endbower -->
<script src="/bower_components/angular-re-captcha/angular-re-captcha.js"></script>
<!-- endbuild -->
<!-- remove -->
<script src="/bower_components/angular-mocks/angular-mocks.js"></script>
<script src="/scripts/app-dev.js"></script>
<!-- endremove -->
<!-- build:js({.tmp,app}) /scripts/app.js -->
<script src="/scripts/app.js"></script>
<!-- endbuild -->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment