我有一个 React 应用程序,我正在通过 Grunt 对其进行改造、丑化和浏览器化。我的 grunt 文件看起来像这样...
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
dist: {
files: {
'./Scripts/build/App.js': ['./Scripts/src/**/*.js']
},
options: {
browserifyOptions: {
debug: true
},
transform: [ require('grunt-react').browserify ],
ignore: './Scripts/src/**/*-test.js'
}
}
},
uglify: {
my_target: {
files: {
'./Scripts/build/App-min.js': ['./Scripts/build/App.js']
}
}
},
watch: {
scripts: {
files: ['./Scripts/src/**/*.js'],
tasks: ['browserify', 'uglify'],
options: {
spawn: false
},
},
},
})
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-watch');
}
您会注意到 browserify 任务的忽略属性告诉它忽略文件名中带有 -test.js 的任何文件,原因是我的测试存储在我正在测试的文件旁边的文件夹中(看起来像这是查看 React Flux 示例时的惯例),并且我不希望将测试文件捆绑到我的 app.js 文件中。谁能告诉我我是否做错了,因为到目前为止它似乎根本不起作用?测试文件被捆绑到 app.js 中,然后我收到有关 jest 未定义的控制台错误。
最佳答案
进行了一些横向谷歌搜索,并在堆栈上找到了一篇文章 Here
似乎您可以将文件添加到 src 数组中,并且如果您在它们前面加上“!”前缀它将它们标记为被忽略的文件。
我现在正在工作的 grunt 文件......
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
dist: {
files: {
'./Scripts/build/App.js': ['./Scripts/src/**/*.js', '!./Scripts/src/**/*-test.js']
},
options: {
browserifyOptions: {
debug: true
},
transform: [ require('grunt-react').browserify ]
}
}
},
uglify: {
my_target: {
files: {
'./Scripts/build/App-min.js': ['./Scripts/build/App.js']
}
}
},
jest: {
options: {
coverage: true,
testPathPattern: /.*-test.js/
}
},
watch: {
scripts: {
files: ['./Scripts/src/**/*.js'],
tasks: ['browserify', 'uglify'],
options: {
spawn: false
},
},
},
})
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-jest');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-watch');
}
关于javascript - Grunt-Browserify 忽略选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29034967/