2016-05-21 1 views
3

私はVueを使用しています。 これは私が私のgulpfileに構築しています方法です:Vueify: 'import'と 'export'は 'sourceType:module'としか表示されません

browserify('./main.js') 
.transform(vueify) 
.bundle() 
.pipe(fs.createWriteStream('./build/bundle.js')); 

問題はvueifyが私の.jsファイルでES6の輸出を処理しないです。 .vueコンポーネントでのみ動作します。 module.exportsと動作しますが、私の.jsファイルでes6コードを利用したいと思います。 bundle()が呼び出されると

、私は現在のエラーを取得:

'import' and 'export' may appear only with 'sourceType: module'

は私の.vueコンポーネントがインポートされES6を使用してJSファイルを処理するためのgulpfileを変更する方法はありますか?

答えて

4

数時間の苦労の末、私はついにそれを理解しました。

  1. babelifyインストール:npm install --save-dev babelify
  2. があなたのgulpfileの先頭にこれを追加します。var babelify = require('babelify')
  3. .transform(babelify)を追加します。

    return browserify('./main.js') //tells browserify where to start, but doesn't run the resolve algorithm yet 
    .transform(vueify) //executes vueify to transform vue components to js 
    .transform(babelify) //executes babelify to transform es6 to es5 
    .bundle() //runs the module resolve algorithm on all the require() statements  
    .pipe(fs.createWriteStream('./build/bundle.js')); 
    
+2

これは非常に便利でした –

関連する問題