MIME type ('text/html') is not a supported stylesheet MIME type

前端 未结 4 1685
囚心锁ツ
囚心锁ツ 2021-02-19 16:08

I have tried almost every solution for the problem which includes. giving type for use of app.use(expre

4条回答
  •  情歌与酒
    2021-02-19 16:35

    I'm adding a second answer because I think there could be a different issue. I think the MIME Type error could be due to the css path not being correct. I think it is trying to serve up an error instead of the css file which is not matching the MIME type. Try removing the following line from your HTML Template and allowing the HtmlWebPackPlugin to inject it automatically.

    
    

    Below is my own webpack.config and index.html template which I hope will help.

    webpack.config

    const MiniCssExtractPlugin = require("mini-css-extract-plugin");
    const HtmlWebpackPlugin = require('html-webpack-plugin');
    const LinkTypePlugin = require('html-webpack-link-type-plugin').HtmlWebpackLinkTypePlugin;
    const CopyPlugin = require('copy-webpack-plugin');
    
    module.exports = {
        entry: './src/index.tsx',
        output: {
            filename: 'app/main.js'
        },
        devServer: {
            contentBase: './',
            watchContentBase: true
        },
        module: {
            rules: [
                {
                    test: /\.scss$/,
                    use: [{
                            loader: MiniCssExtractPlugin.loader,
                            options: {
    
                            }
                        },
                        "css-loader",
                        "resolve-url-loader",
                        {
                            loader: "sass-loader?sourceMap",
                            options: {
                                includePaths: [
                                ],
                                sourceMap: true
                            }
                        }
                    ],
                    exclude: /node_modules/
                },
                {
                    test: /\.tsx?$/,
                    use: {
                        loader: 'babel-loader'
                    },
                    exclude: /node_modules/
                },
                {
                    test: /\.(eot|svg|ttf|woff|woff2)$/,
                    loader: 'file-loader',
                    options: {
                        publicPath: "./",
                        outputPath: "app"
                    }
                }
            ]
        },
        resolve: {
            extensions: ['.tsx', '.ts', '.js']
        },
        plugins: [
            new MiniCssExtractPlugin({
                filename: './app/style.css',
            }),
            new HtmlWebpackPlugin({
                template: 'index.html'
            }),
            new LinkTypePlugin({
                '**/*.css' : 'text/css'
            }),
            new CopyPlugin([
                { from: 'assets', to: 'assets' }
            ])
        ]
    };
    

    index.html

    
    
    
    
        
        
        My Site
        
    
    
    
        

提交回复
热议问题