我正在尝试运行依赖于使用来自ES6 Girder的新导入语法的库的节点代码。它因Unexpected identifed
错误而失败。因此,在webpack的帮助下,我使用Babel转换了源代码和该节点模块。但是,babel-loader不遵守测试变量(仅js文件),从而导致编译错误。
.babelrc:
{
"presets": ["@babel/preset-env"]
}
package.json:
{
"name": "oncofinder_web",
"version": "1.0.0",
"dependencies": {
"backbone": "^1.3.3",
"express": "^4.16.3",
"girder": "^2.5.0",
"underscore": "^1.9.1"
},
"devDependencies": {
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"babel-loader": "^8.0.4",
"clean-webpack-plugin": "^0.1.19",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2"
},
"scripts": {
"build": "webpack",
"build:prod": "webpack -p",
"watch": "webpack --watch"
}
}
webpack.config.js:
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const config = {
target: 'node',
context: path.resolve(__dirname, 'client'),
entry: {
app: './app.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: './bundle.js'
},
module: {
rules: [
{
test: /\.m?js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
plugins: [
new CleanWebpackPlugin(['dist'])
],
}
module.exports = config;
有没有办法使用Girder库(无论是否进行转译)?
致谢