前提・実現したいこと
React.jsで静的Webページを作っています。
今回のエラーは、CSSが上手く読み込まれないというエラーです。
詳細
localhost:8080/hoge
のように、ルートパス直下のパスでリロードした場合、正常にcssが読み込まれます。
しかし、localhost:8080/hoge/fuga
のように、ルートパス直下のパス以外でリロードした場合、cssが読み込まれません。
以下のようなエラーメッセージが出ます。
発生している問題・エラーメッセージ
Refused to apply style from 'http://localhost:8080/hoge/bundle.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
該当のソースコード
Webpack.config.js
const path = require('path'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); const publidDir = path.join(__dirname, '/public/'); module.exports = [ { entry: [ './src/index.js', ], output: { path: publidDir, publicPath: '/', filename: 'bundle.js', }, module: { loaders: [{ exclude: /node_modules/, loader: 'babel-loader', query: { presets: ['react', 'es2015'], }, }], }, resolve: { extensions: ['.js', '.jsx'], }, devServer: { historyApiFallback: true, contentBase: publidDir, }, }, { entry: { style: './stylesheets/index.scss', }, output: { path: publidDir, publicPath: '/', filename: 'bundle.css', }, module: { loaders: [ { test: /.css$/, loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' }), }, { test: /.scss$/, loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader!sass-loader' }), }, ], }, plugins: [ new ExtractTextPlugin('bundle.css'), ], }, ];
publicのディレクトリ構成
public/ |- assets/ |- bundle.css |- bundle.js |- index.html
試したこと
下記のURLのことを試しましたが、なかなか上手くいきませんでした。。
https://stackoverflow.com/questions/48248832/stylesheet-not-loaded-because-of-mime-type
補足情報(FW/ツールのバージョンなど)
各種バージョン
"react": "^16.3.2", "react-dom": "^16.3.2", "react-router-dom": "^4.3.1", "webpack": "3.10.0", "webpack-dev-server": "2.5.1"
あなたの回答
tips
プレビュー