Edg*_*rka 6 webpack webpack-dev-server
Webpack 开发服务器在未登陆索引页面时返回 404。
问题是当将示例登陆到localhost:8080/page应用程序请求bundle.js然后http://localhost:8080/page/bundle.js?08386a6ab2de89169893返回 404 时
http://localhost:8080/bundle.js?08386a6ab2de89169893当来自索引开发服务器的尝试请求返回 200 时
我的 webpack.config.js:
const HtmlWebpackPlugin = require('html-webpack-plugin')
const path = require('path')
const webpack = require('webpack')
const CompressionPlugin = require('compression-webpack-plugin')
const createStyledComponentsTransformer = require('typescript-plugin-styled-components').default
const styledComponentsTransformer = createStyledComponentsTransformer()
const basePath = __dirname
module.exports = function(env, arg) {
const base = {
context: path.join(basePath, 'src'),
entry: ['./index.tsx'],
output: {
path: path.join(basePath, 'dist'),
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader',
},
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
getCustomTransformers: () => ({
before: [styledComponentsTransformer],
}),
},
},
{
test: /\.js$/,
use: ['source-map-loader'],
enforce: 'pre',
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
resolve: {
extensions: ['.mjs', '.tsx', '.ts', '.js'],
alias: {
react: path.resolve(__dirname, 'node_modules', 'react'),
'~': path.resolve('./src'),
},
},
devtool: 'source-map',
externals: {
React: 'react',
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
inline: true,
compress: true,
historyApiFallback: true,
proxy: {
'/graphql': {
secure: false,
target: 'http://gepick.com:4002/graphql',
changeOrigin: true,
},
'/predict': {
secure: false,
target: 'http://localhost:5000',
changeOrigin: true,
},
},
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html', //Name of file in ./dist/
template: 'index.html', //Name of template in ./src
hash: true,
}),
],
}
return base
}
Run Code Online (Sandbox Code Playgroud)
我添加publicPath: '/'到output
output: {
path: path.join(basePath, 'dist'),
filename: 'bundle.js',
publicPath: '/',
},
Run Code Online (Sandbox Code Playgroud)
现在它按预期工作了
| 归档时间: |
|
| 查看次数: |
8352 次 |
| 最近记录: |