【发布时间】:2014-12-13 01:46:31
【问题描述】:
我是新来的咕噜声 我想使用 grunt 将 java 脚本文件连接到一个文件 我有 6 个 js 文件,但它们需要按某种顺序运行代码而不会出现错误,例如应该首先加载 jquery 但是来自 grunt 的结果文件没有保留这个序列 我尝试了很多方法,例如将它们安排在 src 中或创建多个文件夹,但没有成功
注意 - 当我通过复制和粘贴在一个文件中进行手动连接时,它工作正常 那么是否有任何命令可以使 grunt 以我在 src 中编写的序列中连接这些文件作为示例 这也是我的 gruntfile.js
module.exports = function(grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// 1 - this is contecnate js files call them in one file only
concat: {
options: {
separator: ';',
},
dist: {
src: ['src/public/js/jquery.min.js','src/public/js/bootstrap.js','public/js/modernizr.custom.77555.js',
'public/js/jquery.magnific-popup.js',
'public/js/jquery.mixitup.min.js','public/js/popup-box.js' ],
dest: 'dist/1newbuilt.js',
},
},
uglify: {
build: {
src: 'dist/1newbuilt.js',
dest: 'dist/1newbuilt.min.js'
}
}
});
// end 1 - this is contecnate js files call them in one file only
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['concat', 'uglify']);
};
我需要以某些顺序连接文件,例如先添加 1.js,然后在其后添加 2.js 所以我按顺序写了文件,但是这种方式也行不通-
【问题讨论】:
标签: javascript jquery gruntjs grunt-contrib-concat