久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" 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>

                            主站蜘蛛池模板: 81精品国产乱码久久久久久 | 91视频网址 | a天堂在线| 久久久久一区二区 | 成年人在线视频 | 亚洲精品视频在线观看视频 | www免费视频 | 久久久免费电影 | 国产九九精品视频 | 日韩中文字幕 | a欧美 | 男人av网 | 在线观看第一页 | 国产激情一区二区三区 | 男人天堂免费在线 | 91不卡 | 国产精品一区二区福利视频 | av一区二区在线观看 | 亚洲+变态+欧美+另类+精品 | 亚洲免费人成在线视频观看 | 久久久久中文字幕 | 日韩av免费看 | 国产福利资源在线 | 精品亚洲一区二区三区 | 男人久久天堂 | 日本字幕在线观看 | 99久久影院 | 亚洲黄色网址视频 | 91在线电影 | 超碰在线人 | 免费看片在线播放 | 日韩精品一区二区三区中文在线 | 国产ts人妖系列高潮 | 亚洲福利精品 | 亚洲乱码一区二区三区在线观看 | 亚洲一区二区三区在线播放 | 二区成人 | 亚洲激情一区二区 | www.日韩系列 | 97视频精品 | 性做久久久久久免费观看欧美 |