webpack.config.js 配置:
const path = require('path');
const paths = {
appSrc: path.resolve(__dirname, 'src'),
buildPath: path.resolve(__dirname, 'dist'),
nodeModules: path.resolve(__dirname, 'node_modules'),
}
module.exports = (env, argv) => {
return {
target: 'web',
entry: path.resolve(__dirname, 'src/index.js'),
output: {
path: paths.buildPath,
filename: 'bundle .js',
publicPath: path.resolve(__dirname, 'public')
},
module: {
rules: [{
test: /\.js$/,
exclude: paths.nodeModules,
loaders: ['babel-loader']
},
{
test: /\.css$/,
loaders: ['style-loader', 'css-loader']
},
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.svg$/],
exclude: paths.appNodeModules,
use: [{
loader: 'url-loader',
options: {
limit: 1024 //小于1024kb的图片使用base64
}
}]
}
]
},
devServer: {
publicPath: '/',
//之前 index.html 在 public 下,后来放到根路径下都不行
// contentBase: path.resolve(__dirname, 'public'),
hot: true,
hotOnly: true,
inline: true,
port: 3000,
open: true,
//使用代理,处理所有包含 /api 的请求
proxy: {
'/api': {
target: 'http://localhost:8001',
secure: false
}
}
}
}
}
//index.html
<script type="text/javascript" src="bundle.js"></script>
这里试了 /dist/bundle.js 也不行.
工程结构:
报错.
路径不对吧 public/dist/bundle.js