我看到有人在网页包中使用gulp.但后来我看了网页可以代替大口大口的吗?我完全搞糊涂了...有人能解释一下吗?

使现代化

最后我开始大口大口地喝.我对现代前端还不熟悉,只想站起来快速跑起来.一年多后,我的脚都湿透了,现在我准备搬到webpack.我建议那些穿着同样鞋子的人也走同样的路由.并不是说你不能try webpack,而是说如果它看起来很复杂,先从gulp 开始...这没什么错.

如果你不想狼吞虎咽,是的,有咕噜声,但你也可以在你的包中指定命令.json并从命令行调用它们,而不需要任务运行程序,只需启动并运行一开始.例如:

"scripts": {
      "babel": "babel src -d build",
      "browserify": "browserify build/client/app.js -o dist/client/scripts/app.bundle.js",
      "build": "npm run clean && npm run babel && npm run prepare && npm run browserify",
      "clean": "rm -rf build && rm -rf dist",
      "copy:server": "cp build/server.js dist/server.js",
      "copy:index": "cp src/client/index.html dist/client/index.html",
      "copy": "npm run copy:server && npm run copy:index",
      "prepare": "mkdir -p dist/client/scripts/ && npm run copy",
      "start": "node dist/server"
    },

推荐答案

这个答案可能会有所帮助.Task Runners (Gulp, Grunt, etc) and Bundlers (Webpack, Browserify). Why use together?

...下面是一个在gulp 任务中使用webpack的示例.这更进一步,假设你的网页配置是用es6编写的.

var gulp = require('gulp');
var webpack = require('webpack');
var gutil = require('gutil');
var babel = require('babel/register');
var config = require(path.join('../..', 'webpack.config.es6.js'));

gulp.task('webpack-es6-test', function(done){
   webpack(config).run(onBuild(done));
});

function onBuild(done) {
    return function(err, stats) {
        if (err) {
            gutil.log('Error', err);
            if (done) {
                done();
            }
        } else {
            Object.keys(stats.compilation.assets).forEach(function(key) {
                gutil.log('Webpack: output ', gutil.colors.green(key));
            });
            gutil.log('Webpack: ', gutil.colors.blue('finished ', stats.compilation.name));
            if (done) {
                done();
            }
        }
    }
}

I think you'll find that as your app gets more complicated, you might want to use gulp with a webpack task as per example above. This allows you to do a few more interesting things in your build that webpack loaders and plugins really don't do, ie. creating output directories, starting servers, etc. Well, to be succinct, webpack actually can do those things, but you might find them limited for your long term needs. One of the biggest advantages you get from gulp -> webpack is that you can customize your webpack config for different environments and have gulp do the right task for the right time. Its really up to you, but there's nothing wrong with running webpack from gulp, in fact there's some pretty interesting examples of how to do it. The example above is basically from jlongster.

Node.js相关问答推荐

自动将Selify打开的Chrome窗口移动到Mac OS中的第三个显示器

对于具有重叠列的组合键,在冲突&q;上没有唯一或排除约束匹配错误

获取页面大小为10的所有文章,每篇文章填充一些所需的用户信息

验证器功能在mongoose 中不起作用

如何模拟 mysql2 `getConnection`

GitLab 依赖扫描需要源代码中的 package-lock.json 才能执行

在 Docker 容器内创建一个 cron 作业(job)来执行 run.js 文件中的函数

如何获取文件的中间值?

Nodejs 从链接数组中获取数据并保存到 mongodb

我误解了外键的工作原理吗?使用续集

无法使用 node 预签名 url 从 React 将图像文件上传到 s3

Typescript typeRoots 未检测到类型定义

使用新react 18.0.0 的 create-react-app my-app redux 错误

Node.js 变量声明和范围

如何将子集合添加到 Firestore 中的文档?

如何使用 Node.js、Express 和 Mongoose 进行身份验证?

如何在离线时安装 npm 包?

mongo 可以 upsert 数组数据吗?

#!/bin/env是什么意思(在 node.js 脚本的顶部)?

`return function *(){...}` 是什么意思?