gulp-concat twice the content
gulp-concat twice the content
这对我来说是一件奇怪的事情,我有一个任务是连接我的.js
文件,然后用观察程序将它们丑化,但concat
任务只是每次调用内容的两倍......
这是我的gulpfile:
'use strict';
let gulp = require('gulp');
let stylus = require('gulp-stylus');
let sourcemaps = require('gulp-sourcemaps');
let concat = require('gulp-concat');
let uglify = require('gulp-uglify');
let plumber = require('gulp-plumber');
let bootstrap = require('bootstrap-styl');
let rupture = require('rupture');
let copy = require('gulp-copy2');
/*
Prepare the paths
*/
let base = './theme';
let themeName = 'own-theme';
let paths = {
stylus : `${base}/${themeName}/css`,
js : `${base}/${themeName}/js`,
vendor : `${base}/${themeName}/js/vendor`
}
/*
Stylus compile
*/
gulp.task('stylus-compile', () => {
return gulp.src([`${paths.stylus}/dev/*.styl`, `${paths.stylus}/!**/_*.styl`])
.pipe(plumber())
.pipe(stylus({
use: [bootstrap(), rupture()],
compress: true
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${paths.stylus}`));
});
/*
Get the bootstrap-styl js files and concat/uglify them
*/
gulp.task('bootstrap-build', () => {
return gulp.src([
'node_modules/bootstrap-styl/js/transition.js',
'node_modules/bootstrap-styl/js/alert.js',
'node_modules/bootstrap-styl/js/button.js',
'node_modules/bootstrap-styl/js/carousel.js',
'node_modules/bootstrap-styl/js/collapse.js',
'node_modules/bootstrap-styl/js/dropdown.js',
'node_modules/bootstrap-styl/js/modal.js',
'node_modules/bootstrap-styl/js/tooltip.js',
'node_modules/bootstrap-styl/js/popover.js',
'node_modules/bootstrap-styl/js/scrollspy.js',
'node_modules/bootstrap-styl/js/tab.js',
'node_modules/bootstrap-styl/js/affix.js'
])
.pipe(sourcemaps.init())
.pipe(concat('bootstrap.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${paths.vendor}`));
});
/*
Get the js assets from NPM
*/
gulp.task('js-copy', () => {
let dirs = [
{ src: 'node_modules/jquery/dist/jquery.min.js', dest: `${paths.vendor}/jquery.min.js` },
{ src: 'node_modules/sweet-scroll/sweet-scroll.min.js', dest: `${paths.vendor}/sweet-scroll.min.js` }
]
return copy(dirs);
});
/*
Concat/Uglify the JS files
*/
gulp.task('js-build', () => {
return gulp.src(`${paths.js}/*.js`)
.pipe(sourcemaps.init())
.pipe(concat('site.min.js'))
// .pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${paths.js}`));
})
/*
Watch
*/
gulp.task('watch', () => {
gulp.watch(`${paths.js}/*.js`, ['js-build']);
gulp.watch(`${paths.stylus}/dev/*.styl`, ['stylus-compile']);
});
gulp.task('default', ['bootstrap-build', 'js-copy', 'watch']);
无论您调用任务多少次,bootstrap-build
任务都不会使内容增加一倍,但js-build
会这样做。
以下是要连接的测试分离脚本和结果:
文件 1:
(function() {
console.log("oh!")
console.log("uh!")
}).call(this);
文件 2:
(function() {
console.log("hey")
}).call(this);
合并文件(呃,哦,文件在观察程序被触发后重新保存):
(function() {
console.log("oh!")
console.log("uh!")
}).call(this);
(function() {
console.log("oh!")
console.log("uh!")
}).call(this);
(function() {
console.log("hey")
}).call(this);
//# sourceMappingURL=site.min.js.map
(function() {
console.log("hey")
}).call(this);
//# sourceMappingURL=site.min.js.map
在每次重新保存中,连接的内容都是两倍......我真的不明白这个问题。知道吗?
谢谢。
bootstrap-build
工作的原因是因为它将生成的bootstrap.min.js
放在与源文件不同的文件夹中。
但是,js-build
任务会连接path.js
文件夹中的所有.js
文件,并将生成的site.min.js
放在同一文件夹中。
这意味着首次运行时js-build
文件file1.js
和file2.js
将连接成site.min.js
。在第二次运行时,文件file1.js
、file2.js
和site.min.js
被连接成site.min.js
。每次运行js-build
任务时,site.min.js
都会增长。
您需要做的是排除与其他文件连接的site.min.js
:
gulp.task('js-build', () => {
return gulp.src([
`${paths.js}/*.js`,
`!${paths.js}/site.min.js`
])
.pipe(sourcemaps.init())
.pipe(concat('site.min.js'))
// .pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${paths.js}`));
})
相关文章:
- Intercept the cellSubmit jqGrid
- CSS中的游标属性似乎不适用于USB On The Go
- @Url.Content(“~”)不适用于localhost
- 节点,express应用程序返回text/javascript响应头(Content-Type),尽管设置了applic
- Appending the innerhtml of <th>
- jquery in the middle of html
- Can't get the tail to wag (animate) in three.js?
- jquery.proxy in the bootstrap-typeahead.js context
- What is the difference between `HTMLImports.whenReady` and `
- X-Content-Type-Options=nosniff解决方法
- 计算content中的数字总和使用Jquery可编辑文本
- 为什么不是't my css `content:`在多个浏览器中工作,并总体上提高跨浏览器兼容性
- Url.Content中的Url不匹配
- confuse about the parentNode
- momentjs toISOString without the "z"
- Ajax content for Twitter Bootstrap Popover
- toDataURL(), from the Web onto my Computer
- gulp-concat twice the content
- JavaScript UI, requirejs and the Flash Of Unstyled Content
- Does it Make Sense to Insert the Google Content Experiements