我正在使用Webpack-Dev-Server,但在从路由中切断文件时无法重新加载它。
因此,重新加载效果很好,我正在从http://localhost:8080/查看页面,但是如果尝试通过http://localhost:8080/store这样的路径提供文件,则不会重新加载页面。
这是我的webpack配置。
const webpack = require('webpack');
const express = require('express');
const path = require('path');
const app = express()
module.exports = {
entry: "./src/index.tsx",
output: {
filename: "bundle.js",
path: path.join(__dirname, 'dist')
},
devtool: "source-map",
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"]
},
devServer: {
open: true,
openPage: 'store/',
disableHostCheck: true,
before: function(app) {
app.use('/store/', express.static('dist'));
app.use('/store/liveness', (req, res) => res.send('Live!'));
app.use('/store/readiness', (req, res) => res.send('Ready!'));
app.use(function(req, res, next) {
res.status(404).send(`could not find resource: ` + req.url);
});
app.listen('8080', () => console.log('::Server Running::: ==> localhost: 8080'));
}
},
module: {
rules: [
{ test: /\.tsx?$/, loader: "ts-loader" },
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" },
{
test: /\.(jpg|png|svg)$/,
loader: "url-loader"
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
},
};