gpt4 book ai didi

jquery - 凉亭 + gulp : main-bower-files fails to grab backbone-amd and underscore-amd?

转载 作者:行者123 更新时间:2023-12-01 07:11:21 30 4
gpt4 key购买 nike

main-bower-files无法抓取backbone-amdunderscore-amd ,有什么想法为什么以及如何解决它吗?

gulpfile.js

var mainBowerFiles = require('main-bower-files');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var filter = require('gulp-filter');

gulp.task('js', function() {
var jsFiles = ['app/scripts/*'];
gulp.src(mainBowerFiles().concat(jsFiles))
.pipe(filter('*.js'))
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest(dest + 'js'));
});

bower.json,

{
"name": "requirejs",
"version": "1.0.0",
"dependencies": {
"requirejs": "latest",
"jquery": "latest",
"backbone-amd": "latest",
"underscore-amd": "latest",
"ember": "latest",
"ember-data": "latest"
},
"authors": [
"xxx"
],
"license": "MIT",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"app/scripts/vendor",
"test",
"tests"
]
}

main.js,

require.config({
paths: {
'jquery': 'vendor/jquery/dist/jquery',
'underscore': 'vendor/underscore-amd/underscore',
'backbone': 'vendor/backbone-amd/backbone',
}
});

require(['views/app'], function(AppView) {
new AppView;
console.log($(".div").length);
});

它只能压缩jquery , ember ,和ember-data into one main.js file接受 backbone-amdunderscore-amd

我用其他方法测试过,

gulp.task('bower', function() {
return gulp.src(mainBowerFiles(), {
base: 'app/scripts/vendor/'
})
.pipe(gulp.dest('public/lib'));
});

或者,

// grab libraries files from bower_components, minify and push in /public
gulp.task('libs', function() {

var jsFilter = filter('*.js');

return gulp.src(mainBowerFiles())

// grab vendor js files from bower_components, minify and push in /public
.pipe(jsFilter)
.pipe(gulp.dest(dest + '/js/vendor'))
.pipe(uglify())
.pipe(rename({
suffix: ".min"
}))
.pipe(gulp.dest(dest + '/js/vendor'))
.pipe(jsFilter.restore());
});

相同的结果 - 它忽略 backbone-amdunderscore-amd 。这是 main-bower-files 中的错误吗? ?

最佳答案

不是错误。 backbone-amdunderscore-amd没有 Bower.json,因此没有可以指定主文件的 main 属性。这是 Ember 的 bower.json进行比较。

“这将读取您的 Bower.json,迭代您的依赖项并返回包 Bower.json 的主属性中定义的文件数组。”

https://github.com/ck86/main-bower-files#usage

您可以将 overrides 属性添加到您的 Bower.json 以自行指定正确的文件:

"overrides": {
"backbone-amd": {
"main": "backbone.js"
},
"underscore-amd": {
"main": "underscore.js"
}
}

https://github.com/ck86/main-bower-files#overrides-options

关于jquery - 凉亭 + gulp : main-bower-files fails to grab backbone-amd and underscore-amd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26515429/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com