不能将es6模块与webpack一起使用

时间:2015-11-14 13:33:06

标签: webpack babeljs

尝试在webpack中使用带有babel加载程序的es6模块时出错。它适用于require,但不能导入。

如果我这样做:

foo = require( './app/data.js'); //it works 

但是

import foo from './app/data.js'; //gives me a syntax error: 

: Module parse failed Line 1: Unexpected token You may need an appropriate loader to handle this file type.

loaders: [
      {
        test: /\.js$/,
        include: path.join(__dirname, 'src'),
        loader: 'babel-loader',
        query: {
          presets: ['es2015']
        }
      },

路径:

webpackconfig /app/main.js

"devDependencies": {
    "babel-core": "^6.1.20",
    "autoprefixer-loader": "^3.1.0",
    "babel-loader": "^6.0.1",
    "babel-preset-es2015": "^6.1.2",
    "css-loader": "^0.23.0",
    "less": "^2.5.1",
    "less-loader": "^2.2.0",
    "node-libs-browser": "^0.5.2",
    "style-loader": "^0.13.0",
    "webpack": "^1.10.0",
    "webpack-dev-server": "^1.10.1"
  },
  "dependencies": {
    "babel-polyfill": "^6.1.19"
  }

1 个答案:

答案 0 :(得分:1)

看起来巴贝尔没有参加派对。有关包含#include <DueTimer.h> int v[5000]; void setup(){ Serial.begin(9600); Timer3.attachInterrupt(Read); Timer3.start(100); analogReadResolution(12); } void loop(){} void display(){ for(int j=0; j<5000; j++){ Serial.println(v[j]); } } int i=0; void Read(){ v[i]=analogRead(A0); i++; if (i>=5000){ i=0; Timer3.stop(); } } 语句的文件的检查事项:

  1. 检查文件是否在/** * @Route("/logout", name="logout") */ public function logingOut() { $this->get('security.token_storage')->setToken(null); $this->get('request')->getSession()->invalidate(); return $this->redirect($this->generateUrl('index_page')); } 目录下。
  2. 检查文件扩展名是否为import foo from 'data';
  3. 作为旁注...... ES6相当于:

    src

    会是,

    .js