我知道这里有很多类似的话题。
我试着自己解决但是我搞砸了。
我用
卓异
Livereload(Sublime包,Windows应用程序和chrome扩展程序)
Sublime服务器
然后Chrome控制台告诉我:
Navigated to http://localhost:8080/es6/
Hello world! (from webpack) with an autimatic update bundle.js:73
Uncaught SyntaxError: Unexpected token import index.js:3
我尝试了很多方法,但它们对我不起作用。
所有npm安装都是本地的。
./的index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ES6</title>
</head>
<body>
<script type="text/javascript" src="./.build/bundle.js"></script>
<script type="text/javascript" src="./app/index.js"></script>
</body>
</html>
./应用程序/ index.js
console.log('Hello world!');
import { fellowship, total } from './app/fellowship.js';
console.log( fellowship, total );
我尝试'团契''团契.js''./fellowship''。/ app / fellowship'
没有人工作。
./应用程序/ fellowship.js
const fellowship = ['frodo', 'Samwise', 'Gandalf'];
const total = fellowship.length;
export { fellowship, total };
./ babelrc
{
"plugins": [
"check-es2015-constants",
"transform-es2015-block-scoping"
]
}
{
"presets": ["es2015"]
}
./的package.json
{
"name": "es6",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"transpile-es2015": "babel src -d lib",
},
"babel": {
"preset": [
"es2015"
]
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.23.0",
"babel-core": "^6.23.1",
"babel-loader": "^6.4.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.23.0",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.4.1"
},
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2"
}
}
./ webpack.config.js
module.exports = {
entry: ['./app/index.js'],
output: {
path: '.build',
filename: 'bundle.js'
}
module: {
loaders: [
{
loader: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/,
}]
},
}