我是gulp的新手,我正在尝试了解如何使用'gulp-strip-code'和'webpack-stream'来设置测试测试代码。
出于测试目的,我没有对文件进行任何缩小。
gulp.task('strip-test-code', function(){
return gulp.src(['src/*.js','src/gui/*.js'],{base:'src'})
.pipe(stripCode({
start_comment: "start-test-block",
end_comment: "end-test-block"
}));
});
gulp.task('pack-strip',['strip-test-code'],function(){
return gulp.src(['src/*.js','src/gui/*.js'],{base:'src'})
.pipe(webpack(require('./webpack.config.devel.js')))
.pipe(gulp.dest('dist/'));
});
当我运行gulp pack-strip
时,我仍然会在捆绑包中看到我的测试块标记。
似乎正在运行strip-test-code。
[10:26:57] Using gulpfile ~/project/gulpfile.js
[10:26:57] Starting 'strip-test-code'...
[10:26:57] Finished 'strip-test-code' after 71 ms
[10:26:57] Starting 'pack-strip'...
[10:26:58] Version: webpack 1.15.0
Asset Size Chunks Chunk Names
project.bundle.js 141 kB 0 [emitted] project
[10:26:58] Finished 'pack-strip' after 396 ms
然而,在执行之后我试试了测试块
grep -r start-test-block *
dist/project.bundle.js: /*start-test-block*/
---编辑---
我的webpack配置文件看起来像
1 const path=require('path');
2 module.exports={
3 context:path.resolve(__dirname,'src'),
4 entry:{
5 project:['./project.js']
6 },
7 output:{
8 path:path.resolve(__dirname,'dist'),
9 filename:'[name].bundle.js'
10 },
11 devtool:"#inline-source-map"
12 };
答案 0 :(得分:0)
任务pack-strip
没有使用任务strip-test-code
返回的流,您可以将它们合并为一个任务:
gulp.task('task', function(){
return gulp.src(['src/*.js','src/gui/*.js'],{base:'src'})
.pipe(stripCode({
start_comment: "start-test-block",
end_comment: "end-test-block"
}))
.pipe(webpack(require('./webpack.config.devel.js')))
.pipe(gulp.dest('dist/'));
});
或者您可以先保存剥离的文件,然后再阅读:
gulp.task('strip-test-code', function(){
return gulp.src(['src/*.js','src/gui/*.js'],{base:'src'})
.pipe(stripCode({
start_comment: "start-test-block",
end_comment: "end-test-block"
}));
.pipe(gulp.dest('dist'));
});
gulp.task('pack-strip',['strip-test-code'],function(){
return gulp.src(['dist/*.js','dist/gui/*.js'],{base:'dist'})
.pipe(webpack(require('./webpack.config.devel.js')))
.pipe(gulp.dest('dist/'));
});