我正在尝试将webpack合并到我的电子项目中以启用热重新加载。我开始使用simp [le webpack配置来打包捆绑包中的依赖项。我的配置是:
'use strict';
const path = require('path');
let config = {
target:'electron',
entry:'./app/Initializer',
output:{
path:path.resolve(__dirname, 'dist'),
filename: 'appbundle.js',
publicPath:'/dist/'
},
resolve: {
extensions:["",".js",".jsx"]
},
module: {
loaders:[{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel'
},
{
test: /\.json/,
loader: 'json-loader'
}
],
},
}
module.exports = config;
但是,这会引发以下错误:
ERROR in ./~/babel-core/lib/api/node.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../../package in /home/shashi/projects/kaal-clients/atman-desktop/node_modules/babel-core/lib/api
resolve file
/home/shashi/projects/kaal-clients/atman-desktop/node_modules/babel-core/package doesn't exist
/home/shashi/projects/kaal-clients/atman-desktop/node_modules/babel-core/package.js doesn't exist
/home/shashi/projects/kaal-clients/atman-desktop/node_modules/babel-core/package.jsx doesn't exist
resolve directory
/home/shashi/projects/kaal-clients/atman-desktop/node_modules/babel-core/package doesn't exist (directory default file)
/home/shashi/projects/kaal-clients/atman-desktop/node_modules/babel-core/package/package.json doesn't exist (directory description file)
[/home/shashi/projects/kaal-clients/atman-desktop/node_modules/babel-core/package]
[/home/shashi/projects/kaal-clients/atman-desktop/node_modules/babel-core/package.js]
[/home/shashi/projects/kaal-clients/atman-desktop/node_modules/babel-core/package.jsx]
@ ./~/babel-core/lib/api/node.js 42:15-39
babel-core确实有一个有效的package.json文件,因此我不确定为什么会抛出这个错误。
答案 0 :(得分:2)
添加" .json"到解决方案下的扩展变量修复了这个
resolve: {
extensions:["",".js",".jsx",".json"]
}