pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<i id='xIb7e'><tr id='xIb7e'><dt id='xIb7e'><q id='xIb7e'><span id='xIb7e'><b id='xIb7e'><form id='xIb7e'><ins id='xIb7e'></ins><ul id='xIb7e'></ul><sub id='xIb7e'></sub></form><legend id='xIb7e'></legend><bdo id='xIb7e'><pre id='xIb7e'><center id='xIb7e'></center></pre></bdo></b><th id='xIb7e'></th></span></q></dt></tr></i><div class="dzlhdp1" id='xIb7e'><tfoot id='xIb7e'></tfoot><dl id='xIb7e'><fieldset id='xIb7e'></fieldset></dl></div>
    <tfoot id='xIb7e'></tfoot>
  • <small id='xIb7e'></small><noframes id='xIb7e'>

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

      1. 使用 Gulp 的 ES6 導入模塊

        ES6 import module with Gulp(使用 Gulp 的 ES6 導入模塊)
        • <legend id='BW44I'><style id='BW44I'><dir id='BW44I'><q id='BW44I'></q></dir></style></legend>
          • <bdo id='BW44I'></bdo><ul id='BW44I'></ul>
          • <tfoot id='BW44I'></tfoot>
            <i id='BW44I'><tr id='BW44I'><dt id='BW44I'><q id='BW44I'><span id='BW44I'><b id='BW44I'><form id='BW44I'><ins id='BW44I'></ins><ul id='BW44I'></ul><sub id='BW44I'></sub></form><legend id='BW44I'></legend><bdo id='BW44I'><pre id='BW44I'><center id='BW44I'></center></pre></bdo></b><th id='BW44I'></th></span></q></dt></tr></i><div class="bhdtx5z" id='BW44I'><tfoot id='BW44I'></tfoot><dl id='BW44I'><fieldset id='BW44I'></fieldset></dl></div>

              <tbody id='BW44I'></tbody>

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

                1. 本文介紹了使用 Gulp 的 ES6 導入模塊的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在嘗試將我的 ES6 模塊導入文件并運行 Gulp 以連接和縮小文件.我遇到了 ReferenceError: require is not defined at all.js(transpiled) line no 3.我已經使用 gulp-babel 編譯了代碼.

                  I am trying to import my ES6 module into a file and running Gulp to concat and minify the file. I'm running into a ReferenceError: require is not defined at all.js(transpiled) line no 3. I have transpiled the code using gulp-babel.

                  我的js文件是:

                  cart.js:

                  class Cart{
                    constructor(){
                      this.cart = [];
                      this.items = items = [{
                          id: 1,
                          name: 'Dove Soap',
                          price: 39.99
                      },{
                          id: 2,
                          name: 'Axe Deo',
                          price: 99.99
                      }];
                    }
                  
                  
                    getItems(){
                      return this.items;
                    }
                  
                  
                  }
                  
                  export {Cart};
                  

                  app.js:

                  import {Cart} from 'cart.js';
                  
                  let cart = new Cart();
                  
                  console.log(cart.getItems());
                  

                  gulpfile.js:

                  "use strict";
                  
                  let gulp = require('gulp');
                  let jshint = require('gulp-jshint');
                  let concat = require('gulp-concat');
                  let uglify = require('gulp-uglify');
                  let rename = require('gulp-rename');
                  let babel = require('gulp-babel');
                  
                  
                  // Lint Task
                  gulp.task('lint', function() {
                      return gulp.src('js/*.js')
                          .pipe(jshint())
                          .pipe(jshint.reporter('default'));
                  });
                  
                  
                  // Concatenate & Minify JS
                  gulp.task('scripts', function() {
                      return gulp.src('js/*.js')
                          .pipe(babel({
                              presets: ['env']
                          }))
                          .pipe(concat('all.js'))
                          .pipe(gulp.dest('dist'))
                          .pipe(rename('all.min.js'))
                          .pipe(uglify().on('error', function(e){
                            console.dir(e);
                          }))
                          .pipe(gulp.dest('dist/js'));
                  });
                  
                  // Default Task
                  gulp.task('default', ['lint','scripts']);
                  

                  app.js(轉譯):

                  'use strict';
                  
                  var _cart = require('cart.js'); //Uncaught ReferenceError: require is not defined
                  
                  var cart = new _cart.Cart();
                  
                  console.log(cart.getItems());
                  'use strict';
                  
                  Object.defineProperty(exports, "__esModule", {
                    value: true
                  });
                  
                  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
                  
                  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
                  
                  var Cart = function () {
                    function Cart() {
                      _classCallCheck(this, Cart);
                  
                      this.cart = [];
                      this.items = items = [{
                        id: 1,
                        name: 'Dove Soap',
                        price: 39.99
                      }, {
                        id: 2,
                        name: 'Axe Deo',
                        price: 99.99
                      }];
                    }
                  
                    _createClass(Cart, [{
                      key: 'getItems',
                      value: function getItems() {
                        return this.items;
                      }
                    }]);
                  
                    return Cart;
                  }();
                  
                  exports.Cart = Cart;
                  

                  推薦答案

                  你需要一個像 Webpack 這樣的打包工具或 Browserify 以使用 ES6 導入.Babel 只能將 ES6 代碼編譯成 ES5(原生 JS).

                  You would need a bundler like Webpack or Browserify in order to use ES6 imports. Babel is only capable of compiling ES6 code to ES5 (native JS).

                  Webpack 和 Browserify 都為 gulp 制定了配方:

                  Both Webpack and Browserify have made recipes for gulp:

                  • https://webpack.js.org/guides/integrations/#gulp
                  • https://github.com/gulpjs/gulp/tree/master/文檔/食譜

                  希望這會有所幫助.

                  這篇關于使用 Gulp 的 ES6 導入模塊的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 傳播運算符上的意外令牌)
                  Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以將標志傳遞給 Gulp 以使其以不同的方式運行任務?)
                  Why do we need to install gulp globally and locally?(為什么我們需要在全局和本地安裝 gulp?)
                  How to run Gulp tasks sequentially one after the other(如何一個接一個地依次運行 Gulp 任務)
                  Stylesheet not loaded because of MIME-type(由于 MIME 類型而未加載樣式表)
                  Visual Studio 2015 crashes when opening Javascript files(打開 Javascript 文件時 Visual Studio 2015 崩潰)
                  • <bdo id='NSTUB'></bdo><ul id='NSTUB'></ul>

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

                  • <tfoot id='NSTUB'></tfoot>
                          <tbody id='NSTUB'></tbody>

                      1. <i id='NSTUB'><tr id='NSTUB'><dt id='NSTUB'><q id='NSTUB'><span id='NSTUB'><b id='NSTUB'><form id='NSTUB'><ins id='NSTUB'></ins><ul id='NSTUB'></ul><sub id='NSTUB'></sub></form><legend id='NSTUB'></legend><bdo id='NSTUB'><pre id='NSTUB'><center id='NSTUB'></center></pre></bdo></b><th id='NSTUB'></th></span></q></dt></tr></i><div class="rx577fr" id='NSTUB'><tfoot id='NSTUB'></tfoot><dl id='NSTUB'><fieldset id='NSTUB'></fieldset></dl></div>

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

                            主站蜘蛛池模板: 液压升降平台_剪叉式液压/导轨式升降机_传菜机定做「宁波日腾升降机厂家」 | 协议书_协议合同格式模板范本大全 | ?水马注水围挡_塑料注水围挡_防撞桶-常州瑞轩水马注水围挡有限公司 | 万濠投影仪_瑞士TRIMOS高度仪_尼康投影仪V12BDC|量子仪器 | 丁基胶边来料加工,医用活塞边角料加工,异戊二烯橡胶边来料加工-河北盛唐橡胶制品有限公司 | 常州减速机_减速机厂家_常州市减速机厂有限公司| 山东聚盛新型材料有限公司-纳米防腐隔热彩铝板和纳米防腐隔热板以及钛锡板、PVDF氟膜板供应商 | 亿诺千企网-企业核心产品贸易 | 回转炉,外热式回转窑,回转窑炉-淄博圣元窑炉工程有限公司 | 奇酷教育-Python培训|UI培训|WEB大前端培训|Unity3D培训|HTML5培训|人工智能培训|JAVA开发的教育品牌 | 都江堰招聘网-都江堰人才网 都江堰人事人才网 都江堰人才招聘网 邢台人才网_邢台招聘网_邢台123招聘【智达人才网】 | 酒精检测棒,数显温湿度计,酒安酒精测试仪,酒精检测仪,呼气式酒精检测仪-郑州欧诺仪器有限公司 | LED投光灯-工矿灯-led路灯头-工业灯具 - 山东普瑞斯照明科技有限公司 | 粉末包装机-给袋式包装机-全自动包装机-颗粒-液体-食品-酱腌菜包装机生产线【润立机械】 | 自动部分收集器,进口无油隔膜真空泵,SPME固相微萃取头-上海楚定分析仪器有限公司 | 环氧乙烷灭菌器_压力蒸汽灭菌器_低温等离子过氧化氢灭菌器 _低温蒸汽甲醛灭菌器_清洗工作站_医用干燥柜_灭菌耗材-环氧乙烷灭菌器_脉动真空压力蒸汽灭菌器_低温等离子灭菌设备_河南省三强医疗器械有限责任公司 | 广州物流公司_广州货运公司_广州回程车运输 - 万信物流 | 北京征地律师,征地拆迁律师,专业拆迁律师,北京拆迁律师,征地纠纷律师,征地诉讼律师,征地拆迁补偿,拆迁律师 - 北京凯诺律师事务所 | 品牌策划-品牌设计-济南之式传媒广告有限公司官网-提供品牌整合丨影视创意丨公关活动丨数字营销丨自媒体运营丨数字营销 | 迪威娱乐|迪威娱乐客服|18183620002| 空气净化器租赁,空气净化器出租,全国直租_奥司汀净化器租赁 | 量子管通环-自清洗过滤器-全自动反冲洗过滤器-沼河浸过滤器 | 环氧乙烷灭菌器_压力蒸汽灭菌器_低温等离子过氧化氢灭菌器 _低温蒸汽甲醛灭菌器_清洗工作站_医用干燥柜_灭菌耗材-环氧乙烷灭菌器_脉动真空压力蒸汽灭菌器_低温等离子灭菌设备_河南省三强医疗器械有限责任公司 | 山东信蓝建设有限公司官网| 磁力抛光机_磁力研磨机_磁力去毛刺机_精密五金零件抛光设备厂家-冠古科技 | 脑钠肽-白介素4|白介素8试剂盒-研域(上海)化学试剂有限公司 | 2-羟基泽兰内酯-乙酰蒲公英萜醇-甘草查尔酮A-上海纯优生物科技有限公司 | 海水晶,海水素,海水晶价格-潍坊滨海经济开发区强隆海水晶厂 | 聚合氯化铝-碱式氯化铝-聚合硫酸铁-聚氯化铝铁生产厂家多少钱一吨-聚丙烯酰胺价格_河南浩博净水材料有限公司 | 耐酸碱泵-自吸耐酸碱泵型号「品牌厂家」立式耐酸碱泵价格-昆山国宝过滤机有限公司首页 | 电解抛光加工_不锈钢电解抛光_常州安谱金属制品有限公司 | 石家庄装修设计_室内家装设计_别墅装饰装修公司-石家庄金舍装饰官网 | 广州印刷厂_广州彩印厂-广州艺彩印务有限公司 | 光栅尺_Magnescale探规_磁栅尺_笔式位移传感器_苏州德美达 | 路斯特伺服驱动器维修,伦茨伺服驱动器维修|万骏自动化百科 | 防爆大气采样器-防爆粉尘采样器-金属粉尘及其化合物采样器-首页|盐城银河科技有限公司 | 工业铝型材-铝合金电机壳-铝排-气动执行器-山东永恒能源集团有限公司 | 聚氨酯复合板保温板厂家_廊坊华宇创新科技有限公司 | 铣刨料沥青破碎机-沥青再生料设备-RAP热再生混合料破碎筛分设备 -江苏锡宝重工 | 亚洲工业智能制造领域专业门户网站 - 亚洲自动化与机器人网 | 臻知网大型互动问答社区-你的问题将在这里得到解答!-无锡据风网络科技有限公司 |