29.12.2022 UPDT:
When I visit all routes of initial nesting(such as / or /company or /users and so) my bundle.js comes from /static/js/bundle.js, it contains js and all is fine. But when I visit pages with more route nesting by entering it's url or refreshing page being on them it gives me error, cuz bundle.js now comes not from /static/js/bundle.js but for example from /company/static/js/bundle.js and it contains html. So error occurs
[Error] SyntaxError: Unexpected token '<'
(anonymous function) (bundle.js:1)
[Error] SyntaxError: Unexpected token '<'
(anonymous function) (vendors~main.chunk.js:1)
[Error] SyntaxError: Unexpected token '<'
(anonymous function) (main.chunk.js:1)
So it seems like i have to change webpack configuration to give /static/js/bundle.js on every request no matter what nesting, but i can't get where i should change that
This is my config-overrides.js file:
const path = require("path");
// const TerserPlugin = require("terser-webpack-plugin");
const { DefinePlugin } = require("webpack");
const rewireSvgSpriteLoader = require("react-app-rewired-svg-sprite-loader");
// const webpack = require("react-app-rewired");
// const { devServer } = require('react-app-rewired/config-overrides')
module.exports = {
webpack: function override(config, env) {
config.resolve = {
...config.resolve,
alias: {
...config.alias,
"@components": path.resolve(__dirname, "src/components"),
"@pages": path.resolve(__dirname, "src/pages"),
"@hooks": path.resolve(__dirname, "src/hooks"),
"@mock": path.resolve(__dirname, "src/mock"),
"@scss": path.resolve(__dirname, "src/scss"),
"@services": path.resolve(__dirname, "src/services"),
"@store": path.resolve(__dirname, "src/store"),
"@interfaces": path.resolve(__dirname, "src/types"),
"@utils": path.resolve(__dirname, "src/utils"),
"@ui": path.resolve(__dirname, "src/ui"),
"@modals": path.resolve(__dirname, "src/modals"),
"@assets": path.resolve(__dirname, "src/assets"),
"@http": path.resolve(__dirname, "src/http"),
},
};
config.module.rules = [
...config.module.rules,
{
test: /\.module\.scss$/,
include: path.resolve(__dirname, "./src/components"),
use: [
{
loader: "sass-resources-loader",
options: {
resources: require("./src/scss/scss-resourses"),
},
},
],
},
];
config = rewireSvgSpriteLoader(config, env);
config.resolve.modules = [path.resolve("src")].concat(config.resolve.modules);
config.output = {
...config.output,
publicPath: "",
};
config.plugins = [
...config.plugins,
new DefinePlugin({
"process.env.URL": JSON.stringify(process.env.URl),
"process.env.API_URL": JSON.stringify(process.env.API_URL),
"process.env.EDITOR_URL": JSON.stringify(process.env.EDITOR_URL),
}),
];
return config;
},
devServer: function(configFunction) {
return function(proxy, allowedHost) {
const config = configFunction(proxy, allowedHost)
config.historyApiFallback.disableDotRule = true
return config
}
}
}
importan html file?