javascript - gulp 将多个 js 合并为一个 dist 索引
问题描述
几年来一直在使用 grunt,并且第一次使用 gulp 处理项目。
它是一个遗留项目,有一个管道或任务我似乎无法开始工作。
过去,当您运行 gulp 时,似乎有一个任务会监视 js/components/*.js 并将所有 .js 文件合并到 dist/js/index.js 中。
但是我似乎无法运行这个任务,任何人都可以在 gulp 文件中看到这个任务在哪里以及如何运行它?
也许我缺少一些小东西,但是当我运行 gulp 时,它不会更新 dist/js/index.js
gulpfile.js
/// <binding />
/**
* Usage:
* Once per computer:
* $ npm install -g gulp
*
* Once per project, in gulp folder:
* $ npm install
*
*
* Running clumped tasks (defined in this file) --
* see tasks/utils.js config
* $ gulp dev
*
* Running single task (task defined in /tasks. eg. /tasks/css.js)
* $ gulp css // will use the default config
* $ gulp css --env prod // will use the prod config
*
* For details on setConfig, see "user supplied keys" in /tasks/utils.js
**/
// Include gulp and plugins
var gulp = require("gulp"),
utils = require("./tasks/utils"),
notify = require("gulp-notify"),
path = require("path"),
msbuild = require("gulp-msbuild"),
config = utils.loadConfig(); // initialize the config
// set some defaults
utils.setConfig({
// root : path.resolve("../../web/Website"),
// dest : path.resolve("../../web/Website/dist"),
root : path.resolve("../Website"),
dest: path.resolve("../Website/dist"),
env : ""
});
// load the tasks
utils.loadTasks(["init", "js", "css", "styleguide", "copy", "bower", "svg-sprite", "msbuild"]);
/**
* dev task
*/
gulp.task("dev", function () {
// set the dev config (cache in utils.js)
utils.setConfig({
env: "dev",
watch: true,
notify: true,
tasks: ["js", "css", "copy", "bower", "svg-sprite"]
});
// build with this config
utils.build();
});
/**
* dev task, including styleguide build
*/
gulp.task("dev-styleguide", function () {
// set the dev config (cache in utils.js)
utils.setConfig({
env: "dev",
watch: true,
notify: true,
tasks: ["js", "css", "styleguide", "copy", "bower", "svg-sprite"]
});
// build with this config
utils.build();
});
/**
* dev special snowflake task
*/
gulp.task("dev-rsync", function () {
// set the dev config (cache in utils.js)
utils.setConfig({
env: "dev",
watch: true,
notify: true,
tasks: ["js", "css", "copy", "bower", "svg-sprite", "rsync"]
});
// build with this config
utils.build();
});
/**
* dev task
*/
gulp.task("dev-nowatch", function(){
// set the dev config (cache in utils.js)
utils.setConfig({
env : "dev",
watch : false,
notify: false,
tasks: ["js", "css", "copy", "bower", "svg-sprite"]
});
// build with this config
utils.build();
});
/**
* dev task
*/
gulp.task("clean-build", function () {
// set the dev config (cache in utils.js)
utils.setConfig({
env: "dev",
watch: false,
notify: true,
tasks: ["init", "js", "css", "copy", "bower", "svg-sprite"]
});
// build with this config
utils.build();
});
/**
* prod task
*/
gulp.task("prod", function(){
// set the prod config (cache in utils.js)
utils.setConfig({
env : "prod",
watch : false,
tasks: ["js", "css", "copy", "bower", "svg-sprite"]
});
// build with this config
utils.build();
});
// Default Task (run when you run 'gulp'). dev envirnoment
gulp.task("default", [config.local.defaultTask || "dev"]);
解决方案
推荐阅读
- python - 连接列表和字符串以进行递归时出错(后缀到中缀)
- php - 如何通过 PHP 将 HTML 表单中的数据发送到文件?
- html - 为base64数据uri pdf设置初始缩放
- kubernetes-helm - helm 中的 initdbScripts 参数
- spring-boot - 如何获取嵌入式 Redis 指标?
- omnet++ - 用inet实现一种看门狗
- c - 用C语言从文件中读取分离的数据到不同的数据类型
- javascript - 当状态改变时停止重新渲染的方法?(反应原生)
- php - Laravel 使用 Carbon::now() 保存数据的格式与 created_at 不同
- python - 有没有办法在 PuLP 优化中从字符串调用 LpVariables?