I have a functional React app which has multiple files (image, csv, and manifest.json) in my /public
folder. A local build runs perfectly and I get all those public files working correctly. However, once I build and look into my /build/public folder, these files are absent (manifest.json, the image file, and the csv file) which returns an error saying Resource not found.
My public
folder is:
While my build/public doesn't have these files:
My webpack.prod.config.js looks like:
const HtmlWebpackPlugin = require('html-webpack-plugin');
const InterpolateHtmlPlugin = require('interpolate-html-plugin');
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: './src/index.tsx',
mode: 'production',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.scss', '.css'],
},
devtool: 'inline-source-map',
output: {
clean: true,
filename: '[name].bundle.[fullhash].js',
chunkFilename: '[id].[name].[fullhash].js',
path: path.resolve(__dirname, 'build/public'),
},
optimization: {
splitChunks: {
chunks: 'all',
},
nodeEnv: 'production',
minimize: true,
},
performance: {
maxAssetSize: 50000,
maxEntrypointSize: 50000,
},
module: {
rules: [
{
oneOf: [
{
test: /\.(ttf|woff|woff2|woff?|woff2?)/,
type: 'asset/resource',
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/, /\.tsx?$/],
},
{
test: /\.svg$/,
type: 'asset/resource',
exclude: /node_modules/,
},
{
test: /\.ts$|\.tsx$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.js$|\.jsx$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.(c|sc|sa)ss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
},
{
loader: 'sass-loader',
options: {
sassOptions: {
includePaths: ['app', 'node_modules'],
},
},
},
],
},
],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: 'public/index.html',
favicon: 'public/favicon.ico',
manifest: 'public/manifest.json',
robots: 'public/robots.txt',
GridFactsData: 'public/GridFactsData.csv'
}),
new InterpolateHtmlPlugin({
PUBLIC_URL: 'static',
}),
new webpack.HotModuleReplacementPlugin(),
],
};
I don't understand enough of webpack to fix this issue? Any tips? Thank you