0
我正在關注THIS教程試圖讓模塊加載工作,但我一直遇到導入語句不起作用的問題。 import Mortgage from './mortgage2';
- 未捕獲的語法錯誤:意外的令牌輸入。通過es6教程加載模塊問題與webpack教程
我只有一個文件js/main.js
,所以這可能是問題(是不是存在應該被編譯的代碼?)
我跑npm run webpack
其次npm start
。
的WebPack配置:
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'
};
的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"
}
}
控制檯輸出:
E:\es6-tutorial>npm run webpack
> [email protected] 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開發工具中。