我正在使用 AngularJS 和 Grunt 构建一个应用程序,并且我有一行特定的代码,我只想在我的应用程序的“dist”版本中使用它,有没有办法告诉 grunt 删除该行代码,除非我运行“grunt build”?
angular
.module('myModule', [
'ngResource',
'ngRoute',
'ngSanitize'
])
.config(['$routeProvider', '$locationProvider',function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
$locationProvider.hashPrefix('!');
/** Insert code if 'grunt build' **/
$locationProvider.html5Mode(true);
/** End of code inserted for build **/
}]);
最佳答案
您可以使用像 grunt-string-replace ( https://www.npmjs.org/package/grunt-string-replace ) 这样的任务,然后只需留下评论,然后将该评论替换为您想要的构建内容。
options: {
replacements: [{
pattern: '// insert code here',
replacement: '$locationProvider.html5Mode(true);'
}]
}
关于javascript - 有没有办法插入 "grunt build"专用的Javascript代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25652406/