【发布时间】:2018-09-10 00:20:15
【问题描述】:
我目前面临一个奇怪的问题,我刚刚从 webpack 3 中的应用程序过渡到 webpack 4。
我可以使用地址栏让这样的路径工作:
$myapp/a/b 或 $myapp/a/b/c 或 $myapp/a/
但一切都像:
$myapp/a 或 $myapp/b 完美运行
在应用程序中,我可以使用历史记录从第一个类别到达路径。
我正在以这种方式启动我的应用程序:
webpack-dev-server --mode development --host 0.0.0.0 --history-api-fallback
我的 webpack 配置如下所示:
/* eslint-disable */
const path = require('path')
const resolve = path.resolve
const DotenvPlugin = require('webpack-dotenv-plugin')
const HtmlWebPackPlugin = require('html-webpack-plugin')
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: { minimize: true }
}
]
},
{
test: /\.scss$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
},
{
loader: "sass-loader",
options: {
includePaths: [__dirname]
}
}]
},
{ test: /\.css$/,
loader: "style-loader!css-loader",
include: __dirname
},
{
test: /\.(woff|woff2)$/,
use: {
loader: 'url-loader',
options: {
name: 'fonts/[hash].[ext]',
limit: 5000,
mimetype: 'application/font-woff'
}
}
},
{
test: /\.(ttf|eot|svg|png)$/,
use: {
loader: 'file-loader',
options: {
name: 'fonts/[hash].[ext]'
}
}
}
]
},
resolve: {
extensions: [".js"],
alias: {
["~"]: resolve(__dirname)
}
},
plugins: [
new HtmlWebPackPlugin({
template: './src/index.html',
filename: './index.html'
}),
new DotenvPlugin({
sample: './.env.sample',
path: './.env'
})
]
}
在浏览器中,我收到以下错误消息:
GET http://localhost:8081/path/main.js net::ERR_ABORTED
d:1 Refused to execute script from 'http://localhost:8081/path/main.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
有人对此有想法吗?
【问题讨论】:
标签: webpack ecmascript-6 react-router