Reputation: 33
I am using Webpack to add support for ES6, react and some other things.
Right now I am getting error:
Refused to apply style from
http://localhost:5500/bundle.css
because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
So I checked sources tab in Google Chrome Developer Tools and the bundle.css
doesn't even exist. What i am doing wrong ?
Here's my webpack config:
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: "./index.js",
output: {
path: path.resolve(__dirname, "/"),
publicPath: "/",
filename: "bundle.js"
},
mode: "development",
module: {
rules: [
{
test: /\.(js\jsx)$/,
exclude: /(node_modules|framework)/,
loader: require.resolve("babel-loader"),
options: { presets: ["@babel/preset-env"] }
},
{
test: /\.css$/,
use: [require.resolve("style-loader"), require.resolve("css-loader")]
},
{
test: /\.scss$/,
use: [
require.resolve("style-loader"),
require.resolve("css-loader"),
require.resolve("sass-loader")
]
}
]
},
resolve: { extensions: ["*", ".js", ".jsx"] },
devServer: {
port: 5500,
host: "<ip address>",
publicPath: "http://localhost:5500",
hotOnly: true
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "index.html"),
filename: "index.html",
inject: true
})
]
};
Upvotes: 2
Views: 2178
Reputation: 66425
By default css is compiled into the js bundle during dev, to extract it out to a file for your prod build in webpack 4 use https://webpack.js.org/plugins/mini-css-extract-plugin/.
Older versions of webpack should use https://github.com/webpack-contrib/extract-text-webpack-plugin
Upvotes: 4