1. <tfoot id='PvuDC'></tfoot>

          <bdo id='PvuDC'></bdo><ul id='PvuDC'></ul>
        <legend id='PvuDC'><style id='PvuDC'><dir id='PvuDC'><q id='PvuDC'></q></dir></style></legend>

        <small id='PvuDC'></small><noframes id='PvuDC'>

        <i id='PvuDC'><tr id='PvuDC'><dt id='PvuDC'><q id='PvuDC'><span id='PvuDC'><b id='PvuDC'><form id='PvuDC'><ins id='PvuDC'></ins><ul id='PvuDC'></ul><sub id='PvuDC'></sub></form><legend id='PvuDC'></legend><bdo id='PvuDC'><pre id='PvuDC'><center id='PvuDC'></center></pre></bdo></b><th id='PvuDC'></th></span></q></dt></tr></i><div id='PvuDC'><tfoot id='PvuDC'></tfoot><dl id='PvuDC'><fieldset id='PvuDC'></fieldset></dl></div>
      2. 需要另一个 JS 文件的主文件的 Gulp 简单连接

        时间:2023-05-29
        <legend id='kIfZz'><style id='kIfZz'><dir id='kIfZz'><q id='kIfZz'></q></dir></style></legend>

        <tfoot id='kIfZz'></tfoot>
          • <bdo id='kIfZz'></bdo><ul id='kIfZz'></ul>

                  <tbody id='kIfZz'></tbody>
                <i id='kIfZz'><tr id='kIfZz'><dt id='kIfZz'><q id='kIfZz'><span id='kIfZz'><b id='kIfZz'><form id='kIfZz'><ins id='kIfZz'></ins><ul id='kIfZz'></ul><sub id='kIfZz'></sub></form><legend id='kIfZz'></legend><bdo id='kIfZz'><pre id='kIfZz'><center id='kIfZz'></center></pre></bdo></b><th id='kIfZz'></th></span></q></dt></tr></i><div id='kIfZz'><tfoot id='kIfZz'></tfoot><dl id='kIfZz'><fieldset id='kIfZz'></fieldset></dl></div>
              1. <small id='kIfZz'></small><noframes id='kIfZz'>

                1. 本文介绍了需要另一个 JS 文件的主文件的 Gulp 简单连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一个简单的文件:

                  ma​​in.js:

                  'use strict';
                  const somefile = require('somefile')
                  
                  // class MyClass ...
                  // some js
                  

                  我想使用 gulp 创建一个包含 somefile.js 代码的缩小文件.但由于某种原因,我找不到这样做的方法.在我的缩小文件中,我有 require('somefile'),而不是完整的代码.

                  I want to use gulp to create a minified file that has the code from somefile.js included too. But for some reason, I can't find a way to do this. Inside my minified file I have require('somefile'), not the full code.

                  gulpfile.js

                  const gulp = require('gulp');
                  const minify = require('gulp-minify');
                  const babel = require('gulp-babel');
                  const include = require("gulp-include");
                  const sourcemaps = require('gulp-sourcemaps');
                  const jsImport = require('gulp-js-import');
                  const resolveDependencies = require('gulp-resolve-dependencies');
                  
                  gulp.task('default', () =>
                      gulp.src('src/main.js')
                          .pipe(sourcemaps.init())
                          .pipe(resolveDependencies({
                            pattern: /* @requires [s-]*(.*.js)/g
                          }))
                          .pipe(jsImport({hideConsole: true}))
                          .pipe(babel({
                              presets: ['@babel/env']
                          }))
                          .pipe(minify({
                              ext: {
                                  min: '.min.js'
                              }
                          }))
                          .pipe(gulp.dest('dist'))
                  );
                  

                  我也尝试过 gulp-concat.

                  我遗漏了一些东西,但不确定是什么.

                  I'm missing something, but not sure what.

                  有什么想法吗?

                  推荐答案

                  在 resolveDependencies 管道中,您复制了 gulp-resolve-dependencies 将用于查找代码中的任何 require 语句.但是您的 require 看起来与文档示例非常不同.你的:

                  In the resolveDependencies pipe you copied the default regex pattern which the gulp-resolve-dependencies will use to find any require statements in the code. But your require looks very different than the documentation example. Yours:

                  const somefile = require('somefile')
                  

                  所以试试这个模式:pattern:/.*requires*('(.*)')/g

                  这应该捕获括号内的文件(然后自动传递给路径解析器函数).然后连接这些文件.

                  That should capture the file inside the parentheses (which is then automatically passed to the path resolver function). And then concat those files.

                  const gulp = require('gulp');
                  const minify = require('gulp-minify');
                  const babel = require('gulp-babel');
                  
                  // const include = require("gulp-include");  you don't need this
                  
                  const sourcemaps = require('gulp-sourcemaps');
                  
                  // const jsImport = require('gulp-js-import');  you don't need this
                  
                  const resolveDependencies = require('gulp-resolve-dependencies');
                  const concat = require('gulp-concat');
                  
                  gulp.task('default', () =>
                      gulp.src('src/main.js')
                          .pipe(sourcemaps.init())
                          .pipe(resolveDependencies({
                            pattern: /.*requires*('(.*)')/g
                          }))
                  
                           // added the following:
                          .pipe(concat('a filename here'))
                  
                          .pipe(babel({
                              presets: ['@babel/env']
                          }))
                          .pipe(minify({
                              ext: {
                                  min: '.min.js'
                              }
                          }))
                  
                           // added the following:
                          .pipe(sourcemaps.write('some destination folder for the soucemaps'))
                  
                          .pipe(gulp.dest('dist'))
                  );
                  

                  我无法对此进行测试,但它应该会有所帮助.

                  I haven't been able to test this but it should help.

                  这篇关于需要另一个 JS 文件的主文件的 Gulp 简单连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:gulp watch 不看 下一篇:如何为 gulp 组成管道序列?

                  相关文章

                  最新文章

                2. <i id='onq3D'><tr id='onq3D'><dt id='onq3D'><q id='onq3D'><span id='onq3D'><b id='onq3D'><form id='onq3D'><ins id='onq3D'></ins><ul id='onq3D'></ul><sub id='onq3D'></sub></form><legend id='onq3D'></legend><bdo id='onq3D'><pre id='onq3D'><center id='onq3D'></center></pre></bdo></b><th id='onq3D'></th></span></q></dt></tr></i><div id='onq3D'><tfoot id='onq3D'></tfoot><dl id='onq3D'><fieldset id='onq3D'></fieldset></dl></div>

                      • <bdo id='onq3D'></bdo><ul id='onq3D'></ul>
                    1. <tfoot id='onq3D'></tfoot>

                    2. <small id='onq3D'></small><noframes id='onq3D'>

                      <legend id='onq3D'><style id='onq3D'><dir id='onq3D'><q id='onq3D'></q></dir></style></legend>