-
Notifications
You must be signed in to change notification settings - Fork 7
add grunt replace package
kuang edited this page Mar 26, 2015
·
2 revisions
- 项目使用:angular,grunt
- 项目已经在跑,有一个配置项,开发的时候与生产环境不一样,经常需要在svn更新后修改,很麻烦
- 参考文章: http://segmentfault.com/blog/houxiyang/1190000002538772
第一次运行grunt replace:development
的时候报错
Running "replace:development" (replace) task
Warning: Destination is not defined! If you want to overwrite files, then make sure to set overwrite: true. If you don't wish to overwrite, then make sure to set a destination Use --force to continue.
Aborted due to warnings.
把错误google,发现几乎是在描述一个叫grunt-text-replace
的包,意识到应该是名字冲突了
修改Gruntfile.js
grunt.loadNpmTasks('grunt-replace');
grunt.renameTask('replace','gruntReplace');
就没事了
- generator-env-config 这个包只是用来生成development.json、config.js这些文件,也可以手动去添加这些文件的
- 但也说明,有些命令可以帮你生成好项目的种子框架
- 参考文章中的yo也是要安装的
npm install yo -g
- 执行
npm install grunt-replace --save-dev
,会自动修改package.json
到最后,还是决定把开发变量__DEV__
加到window下就好了,不用angular的constant
目录结构如下
│ const.js
│
└─environments
development.json
production.json
const.js
!function(){
window.__DEV__ = !!'@@dev';
}();
development.json
{
"dev": 1
}
production.json
{
"dev": ""
}
以后 if(__DEV__
) 就说明是开发环境