相关疑难解决方法(0)

从 webpack 加载 bundle.js 文件将 mime 类型更改为 text/html

我正在尝试使用 react-redux 和 express 为服务器实现应用程序的服务器端渲染,webpack 用于创建包。

我开始使用以下文档:

https://redux.js.org/docs/recipes/ServerRendering.html

我有以下设置来加载从 webpack 创建的 main.js:

<script type="application/javascript" src="/static/main.js"></script>
Run Code Online (Sandbox Code Playgroud)

但是,在启动快速服务器时,这是我在控制台中看到的:

Refused to execute script from 'http://localhost:8080/static/main.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
Run Code Online (Sandbox Code Playgroud)

这不会在任何浏览器中启动。知道会发生什么吗?

javascript serverside-javascript express server-side-rendering react-redux

5
推荐指数
1
解决办法
2574
查看次数

嵌套的React路由器4路由无法在Webpack 3上运行

由于小提示我不能得到像这样的路线

<Route path="/events/:id" component={EventDetailRoute} />
Run Code Online (Sandbox Code Playgroud)

工作,因为我读过似乎是index.html中的bundle必须是绝对的,但是我使用的是HtmlWebpackPlugin,所以bundle被注入一个相对路径.

我试图为webpack设置输出配置如下:

output: {
    path: path.resolve('dist'),
    filename: 'index_bundle.js',
    publicPath: '/'
},
Run Code Online (Sandbox Code Playgroud)

但这也不起作用.

如果我尝试这条路线:http:// localhost:8080/events/7,我在尝试查找http:// localhost:8080/events/index_bundle.js收到404错误

这是我的webpack.config:

const path = require('path'),
    HtmlWebpackPlugin = require('html-webpack-plugin'),
    webpack = require('webpack');

const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
    template: './src/index.html',
    filename: 'index.html',
    inject: 'body'
})

module.exports = {
    entry: './src/index.js',
    output: {
        path: "/" + path.resolve('dist', 'build'),
        filename: 'index_bundle.js',
        publicPath: '/'
    },
    devServer: {
        historyApiFallback: true,
        hot: true,
        publicPath: '/'
    },
    module: { …
Run Code Online (Sandbox Code Playgroud)

webpack react-router webpack-dev-server html-webpack-plugin

4
推荐指数
1
解决办法
2024
查看次数