Ecmascript 6 我能';t在网页包配置文件中使用ES6
是否可以在网页包配置文件中使用ES6(特别是导入-而不是要求) 我有Ecmascript 6 我能';t在网页包配置文件中使用ES6,ecmascript-6,webpack,Ecmascript 6,Webpack,是否可以在网页包配置文件中使用ES6(特别是导入-而不是要求) 我有 import webpack from 'webpack'; 但是我得到了以下错误 (function (exports, require, module, __filename, __dirname) { import webpack from'webpack'; SyntaxError: Unexpected reserved word import 在我将配置命名为“webpack.config.babel.js
import webpack from 'webpack';
但是我得到了以下错误
(function (exports, require, module, __filename, __dirname)
{ import webpack from'webpack';
SyntaxError: Unexpected reserved word import
在我将配置命名为“webpack.config.babel.js”之后,我将babel(6.0.15)和babel core(6.1.2)安装为dev deps,但没有任何效果。正在尝试WinXP
谢谢您的帮助。您可以像这样使用gulp和babel/注册:
var gulp = require('gulp');
var webpack = require('webpack');
var gutil = require('gutil');
var babel = require('babel/register');
var config = require(path.join('../..', 'webpack.config.es6.js'));
gulp.task('webpack-es6-test', function(done){
webpack(config).run(onBuild(done));
});
function onBuild(done) {
return function(err, stats) {
if (err) {
gutil.log('Error', err);
if (done) {
done();
}
} else {
Object.keys(stats.compilation.assets).forEach(function(key) {
gutil.log('Webpack: output ', gutil.colors.green(key));
});
gutil.log('Webpack: ', gutil.colors.blue('finished ', stats.compilation.name));
if (done) {
done();
}
}
}
}
…并且您的网页包配置可以有任何es6。经过测试,适合我。Rabet
您是否有代码回购的链接?如果你能联系我们,对调试会很有帮助。听起来你可能错过了babel loader软件包
我已经写了一篇关于如何在ES6中配置webpack(用于react)的教程
下面是一些可能与您相关的代码片段
import path from 'path'
export default {
entry:['./js/app.js',
],
output: {
filename: 'bundle.js',
path: path.join(__dirname, 'build'),
publicPath: 'http://localhost:8080/',
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['react-hot', 'babel'],
}],
},
}
和我的package.json文件
{
“name”: “Todo_tutorial”,
“version”: “1.0.0”,
“description”: “”,
“main”: “index.js”,
“scripts”: {
“test”: “echo \”Error: no test specified\” && exit 1",
“build”: “webpack --colors --progress”,
“start”: “webpack-dev-server --hot --inline --color --progress ”
},
“author”: “”,
“license”: “ISC”,
“dependencies”: {
“react”: “^0.14.0”
},
“devDependencies”: {
“babel-core”: “^5.8.25”,
“babel-loader”: “^5.3.2”,
“flux”: “^2.1.1”,
“webpack”: “^1.12.2”,
“webpack-dev-server”: “^1.12.0”
}
}
来源:如果您通过babel编译器将其运行到节点中,它可能会工作。i、 e.
babel webpack.config.es6 |节点
,但这并不能将其放入webpack。