看起来与Babel unexpected token import when running mocha tests相关,可能是重复的,但在尝试过这些解决方案之后,我仍然面临着问题。
尝试使用Mocha运行一些测试:
./ node_modules / .bin / mocha --compilers js:babel-core / register
问题
$ ./node_modules/.bin/mocha --compilers js:babel-core / register C:\ devel的\ jtreports \ node_modules \反应的小部件\ lib中\少\反应-widgets.less:1 (函数(exports,require,module,__ filename,__ dirname){@ import" ./ variables.less&#34 ;; ^
SyntaxError:意外的令牌ILLEGAL 在exports.runInThisContext(vm.js:53:16)
首先不确定为什么导入(必须有错误配置的东西)是一个问题,其次,node_modules正在处理?期望根据下面的webpack配置排除node_modules目录。
webpack.config.js:
const webpack = require('webpack');
module.exports = {
entry: [
'webpack-dev-server/client?http://localhost:80',
'./app/main.js'
],
output: {
path: './app',
filename: 'app.bundle.js'
},
module: {
loaders: [
{
test: /\.js?$/,
exclude: /node_modules/,
loaders: ["babel-loader"]
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.less$/,
loader: "style-loader!css-loader!less-loader"
},
{
test: /\.woff(2)?(\?v=[0-9].[0-9].[0-9])?$/,
loader: "url-loader?mimetype=application/font-woff"
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9].[0-9].[0-9])?$/,
loader: "file-loader?name=[name].[ext]"
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
hot: true,
inline: true,
host: 'localhost',
port: 80,
contentBase: "./app",
secure: false,
colors: true,
noInfo: false,
proxy: {
'/rest': {
target: 'http://localhost:8080',
}
},
historyApiFallback: true
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
}
.bablerc
{
"presets": [
"es2015",
"react"
],
"plugins": [
[
"transform-object-rest-spread",
"transform-react-jsx-img-import",
"react-transform",
{
"transforms": [
{
"transform": "react-transform-hmr",
"imports": [
"react"
],
"locals": [
"module"
]
}
]
}
]
]
}