我想在我的Yeoman项目中使用browserify而不是RequireJS。你能否告诉我如何交换它,以便我的app /和test /可以利用module.exports和require()?
答案 0 :(得分:14)
这就是我的所作所为:
npm install grunt-browserify --save-dev
npm install coffeeify --save-dev
在Gruntfile.js
中添加grunt-browserify步骤:
browserify: {
basic: {
src: ['<%= yeoman.app %>/scripts/**/*.js', '<%= yeoman.app %>/scripts/**/*.coffee'],
options: {
transform: ['coffeeify']
},
dest: '.tmp/scripts/application.js'
}
}
向并发/观看步骤添加步骤,例如:
concurrent: {
server: [
'...',
'browserify'
],
dist: [
'...',
'browserify'
]
}
watch: {
coffee: {
files: ['<%= yeoman.app %>/scripts/{,*/}*.coffee'],
tasks: ['...', 'browserify']
}
}
修改默认的app / index.html模板,因此usemin将连接并缩小,从而:
<!-- build:js scripts/main.js -->
<script src="bower_components/jquery/jquery.js"></script>
<script src="scripts/main.js"></script>
<!-- endbuild -->
<!-- build:js(.tmp) scripts/coffee.js -->
<script src="scripts/hello.js"></script>
<!-- endbuild -->
对此:
<!-- build:js({.tmp,app}) scripts/main.js -->
<script src="bower_components/jquery/jquery.js"></script>
<script src="scripts/application.js"></script>
<!-- endbuild -->