我的文件结构如下:
-node_modules
-public
--scripts
-src
还有我的webpack.config.js:
const path = require('path');
module.exports = () => {
return {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'public/scripts'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /nodule_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
],
},
mode: process.env.WEBPACK_MODE || 'development',
devServer: {
static: {
directory: path.join(__dirname, 'public'),
publicPath: '/scripts'
},
hot: true,
compress: true,
port: 3000,
},
};
};
我的问题是浏览器不加载任何内容报告:在192.168.0.11/:1
处Failed to load resource: the server responded with a status of 404 (Not Found)
当我删除publicPath
属性时,HTML被呈现,但是找不到bundle.js。
1条答案
按热度按时间oug3syen1#
我希望这对那些正在寻找答案的人有帮助,在webpack 5上,我们可以将多个路径设置为公共的,只需用列表替换对象即可。