Gulp 大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口

Gulp 大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口,gulp,Gulp,我正在使用缩小和压缩CSS和JS文件,并重命名index.html中的引用。但我的项目也使用requireJS从多个文件加载AMD模块,这些文件在index.html中没有直接引用,也没有与其余文件连接 <!-- build:js js/app.js --> <script src="js/libs/accounting.js"></script> <script src="js/libs/farbtastic.js"></script>

我正在使用缩小和压缩CSS和JS文件,并重命名index.html中的引用。但我的项目也使用requireJS从多个文件加载AMD模块,这些文件在index.html中没有直接引用,也没有与其余文件连接

<!-- build:js js/app.js -->
<script src="js/libs/accounting.js"></script>
<script src="js/libs/farbtastic.js"></script>
<script src="js/libs/lz-string-1.3.3.js"></script>
<script src="js/libs/color.js"></script>
<script data-main="js/main" src="js/libs/require.js"></script>
<!-- endbuild -->


如何将usemin与其他gulp插件结合起来,使requireJS文件成为输出的一部分?答案可能包含这样的内容,但我还不明白如何将其与gulp usemin结合起来

不确定我是否正确,但看起来您可能希望对所有JS文件使用requireJS,而仅对CSS使用Min

如果我查看您的代码,我会将您的lib文件添加到
main.js
中,并将它们从
index.html
中删除。稍后使用创建构建js文件

希望这有帮助

更新:

通常我会尝试检查libs是否与RequireJS一起工作,然后使用

require.config.js:

main.js:

需要([
“jquery”,
“滑稽的”
],
函数(){
$('colorpicker1')。farbtastic('color1');
$('#colorpicker2').farbtastic({callback:'#color2',width:150});
});
如果您使用RequireJS,这适用于。希望其他LIB也能像这样使用。
通过这种方式,您可以使用RequireJS组合所有JS。

问题是这些LIB不是RequireJS模块,我认为不可能在JS文件中“包含”JS库。谢谢,我对您的努力投了赞成票,但这不是我想要的方式。不是所有的库都是AMD插件,我不想这样对待它们。啊,好吧,我明白了。可怜。也许值得检查AMD的替代品。通常bower中的LIB支持AMD,如果不支持,大多数时候github上已经出现了问题。我认为这是更好的方法。但听起来好像你一定要这么做。
require.config({
    // List of all the dependencies
    paths: {
        jquery:     'bower_components/jquery/jquery',
        farbtastic: 'bower_components/farbtastic/src/farbtastic'
    },
    // Ensure that the dependencies are loaded in the right order
    shim: {
        jquery: {
            exports: '$'
        },
        farbtastic: {
            deps: ['jquery']
        }
    }
});
require(['main']);