Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过es6教程加载webpack的模块问题_Webpack_Es6 Modules - Fatal编程技术网

通过es6教程加载webpack的模块问题

通过es6教程加载webpack的模块问题,webpack,es6-modules,Webpack,Es6 Modules,我遵循教程试图让模块加载工作,但我一直遇到导入语句不起作用的问题从“/mortgage2”导入抵押-未捕获语法错误:意外的令牌输入 我只有一个文件js/main.js,所以这可能就是问题所在(不应该有编译代码吗?) 我正在运行npm运行网页,然后是npm启动 网页包配置: var path = require('path'); var webpack = require('webpack'); module.exports = { entry: './js/main.js',

我遵循教程试图让模块加载工作,但我一直遇到导入语句不起作用的问题<代码>从“/mortgage2”导入抵押-未捕获语法错误:意外的令牌输入

我只有一个文件
js/main.js
,所以这可能就是问题所在(不应该有编译代码吗?)

我正在运行
npm运行网页
,然后是
npm启动

网页包配置:

 var path = require('path');
 var webpack = require('webpack');

 module.exports = {
     entry: './js/main.js',
     output: {
         path: path.resolve(__dirname, 'build'),
         filename: 'main.bundle.js'
     },
     module: {
         loaders: [
             {
                 test: /\.js$/,
                 loader: 'babel-loader',
                 query: {
                     presets: ['es2015']
                 }
             }
         ]
     },
     stats: {
         colors: true
     },
     devtool: 'source-map'
 };
E:\es6-tutorial>npm run webpack

> es6-tutorial@1.0.0 webpack E:\es6-tutorial
> webpack

(node:22340) DeprecationWarning: loaderUtils.parseQuery() received a non-string
value which can be problematic, see https://github.com/webpack/loader-utils/issu
es/56
parseQuery() will be replaced with getOptions() in the next major version of loa
der-utils.
Hash: 8536c97add80f6d10d01
Version: webpack 2.3.2
Time: 980ms
             Asset     Size  Chunks             Chunk Names
    main.bundle.js  6.64 kB       0  [emitted]  main
main.bundle.js.map  7.62 kB       0  [emitted]  main
   [0] ./js/mortgage2.js 2.23 kB {0} [built]
   [1] ./js/main.js 1.64 kB {0} [built]
package.json

{
  "name": "es6-tutorial",
  "version": "1.0.0",
  "description": "Start the tutorial [here](http://ccoenraets.github.io/es6-tutorial).",
  "main": "index.js",
  "scripts": {
    "babel": "babel --presets es2015 js/main.js -o build/main.bundle.js",
    "start": "http-server",
    "webpack": "webpack"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/ccoenraets/es6-tutorial.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/ccoenraets/es6-tutorial/issues"
  },
  "homepage": "https://github.com/ccoenraets/es6-tutorial#readme",
  "devDependencies": {
    "babel-cli": "^6.24.0",
    "babel-core": "^6.24.0",
    "babel-loader": "^6.4.1",
    "babel-preset-es2015": "^6.24.0",
    "http-server": "^0.9.0",
    "webpack": "^2.3.2"
  },
  "dependencies": {
    "babel-cli": "^6.24.0",
    "babel-core": "^6.24.0",
    "babel-loader": "^6.4.1",
    "babel-preset-es2015": "^6.24.0",
    "http-server": "^0.9.0",
    "webpack": "^2.3.2"
  }
}
控制台输出:

 var path = require('path');
 var webpack = require('webpack');

 module.exports = {
     entry: './js/main.js',
     output: {
         path: path.resolve(__dirname, 'build'),
         filename: 'main.bundle.js'
     },
     module: {
         loaders: [
             {
                 test: /\.js$/,
                 loader: 'babel-loader',
                 query: {
                     presets: ['es2015']
                 }
             }
         ]
     },
     stats: {
         colors: true
     },
     devtool: 'source-map'
 };
E:\es6-tutorial>npm run webpack

> es6-tutorial@1.0.0 webpack E:\es6-tutorial
> webpack

(node:22340) DeprecationWarning: loaderUtils.parseQuery() received a non-string
value which can be problematic, see https://github.com/webpack/loader-utils/issu
es/56
parseQuery() will be replaced with getOptions() in the next major version of loa
der-utils.
Hash: 8536c97add80f6d10d01
Version: webpack 2.3.2
Time: 980ms
             Asset     Size  Chunks             Chunk Names
    main.bundle.js  6.64 kB       0  [emitted]  main
main.bundle.js.map  7.62 kB       0  [emitted]  main
   [0] ./js/mortgage2.js 2.23 kB {0} [built]
   [1] ./js/main.js 1.64 kB {0} [built]

注意,当我加载localhost时,最后两个文件不会出现在chrome开发工具中。

遗漏了一个步骤:

 var path = require('path');
 var webpack = require('webpack');

 module.exports = {
     entry: './js/main.js',
     output: {
         path: path.resolve(__dirname, 'build'),
         filename: 'main.bundle.js'
     },
     module: {
         loaders: [
             {
                 test: /\.js$/,
                 loader: 'babel-loader',
                 query: {
                     presets: ['es2015']
                 }
             }
         ]
     },
     stats: {
         colors: true
     },
     devtool: 'source-map'
 };
E:\es6-tutorial>npm run webpack

> es6-tutorial@1.0.0 webpack E:\es6-tutorial
> webpack

(node:22340) DeprecationWarning: loaderUtils.parseQuery() received a non-string
value which can be problematic, see https://github.com/webpack/loader-utils/issu
es/56
parseQuery() will be replaced with getOptions() in the next major version of loa
der-utils.
Hash: 8536c97add80f6d10d01
Version: webpack 2.3.2
Time: 980ms
             Asset     Size  Chunks             Chunk Names
    main.bundle.js  6.64 kB       0  [emitted]  main
main.bundle.js.map  7.62 kB       0  [emitted]  main
   [0] ./js/mortgage2.js 2.23 kB {0} [built]
   [1] ./js/main.js 1.64 kB {0} [built]
在代码编辑器中打开index.html,并按如下所示修改标记以加载编译版js/main.bundle.js: