我正在尝试创建一个小的npm库,以使与API的接口更加整洁。我的文件夹结构如下...
dist/
index.js
src/
index.js
endpoints/
endpoint1.js
package.json
webpack.config.js
我的src / index.js文件中..
import {endpoint1} from './endpoints'
module.exports = class lib {
...
}
当我 npm运行build (运行 webpack --display-error-details --mode production )时,webpack抛出一个大错误,提示“ Module not找到:错误:无法解析“ my \ project \ dir \ src”中的“ ./端点” 。
我的webpack.config.js文件当前看起来像...
const path = require('path');
module.exports = {
mode: 'production',entry: path.join(__dirname,'/src/index.js'),output: {
path: path.resolve('dist'),filename: 'index.js',libraryTarget: 'commonjs2'
},module: {
rules: [
{
test: /.js?$/,exclude: /(node_modules)/,use: 'babel-loader'
}
]
},resolve: {
modules: [
path.resolve(__dirname,'src/endpoints')
],extensions: ['.js']
}
};
我可以看到之前曾问过类似的问题,并且列出的解决方案似乎对我不起作用,所以我认为我应该把它发布出来,以防我出现菜鸟错误。如果需要更多信息,请说!抱歉,如果它是一堆文字。谢谢。