Reactjs - Can xterm.js have problem with webpack configuration? - reactjs

So far I am not able to properly integrate xterm.js with reactjs due to which my code breaks in production but works while development.
HELP !!!
import React, {useEffect} from 'react';
import {Terminal} from 'xterm';
import {FitAddon} from 'xterm-addon-fit';
const UITerminal = () => {
const term = new Terminal();
const fitAddon = new FitAddon();
term.loadAddon(fitAddon);
useEffect(() => {
let termDocument = document.getElementById('terminal')
if (termDocument) {
term.open(termDocument)
fitaddon.fit();
}
window.addEventListener('resize', () => {
fitaddon.fit();
})
}, [])
return (<div id="terminal"></div>)
}
Below is the error response from production code. clearly it fails to import xterm
react_devtools_backend.js:4012 ReferenceError: Cannot access 'r' before initialization
at new m (96209.72626fc1cc862aea477a.bundle.js:1:165467)
at new b (96209.72626fc1cc862aea477a.bundle.js:1:159758)
at new M (96209.72626fc1cc862aea477a.bundle.js:1:57572)
at new r.exports.i.Terminal (96209.72626fc1cc862aea477a.bundle.js:1:294972)
at w (96209.72626fc1cc862aea477a.bundle.js:1:15994)
at zo (main.71e827eabc798023c129.bundle.js:1:1260000)
at Ws (main.71e827eabc798023c129.bundle.js:1:1333492)
at Wi (main.71e827eabc798023c129.bundle.js:1:1294411)
at Ui (main.71e827eabc798023c129.bundle.js:1:1294336)
at Pi (main.71e827eabc798023c129.bundle.js:1:1291367)
UPDATE
I have found out that it is happening because of my production webpack configuration but still the root cause is unidentified. please help in soughting this out. I am adding my development and production webpack config here.
Please note that the dev webpack config absolutely works fine if build with it and serve.
webpack.dev.js
const fqdn = "some.fqdn.com"
const path = require("path");
const webpack = require("webpack")
const common = require("./webpack.common");
const { merge } = require("webpack-merge");
const fs = require('fs');
const jsonFormat = require('json-format');
var HtmlWebpackPlugin = require("html-webpack-plugin");
const jsonFromatConfig = {
type: 'space',
size: 4
}
module.exports = merge(common, {
mode: "development",
devtool: "source-map",
output: {
filename: "bundle.js",
publicPath: '/',
},
plugins: [
new HtmlWebpackPlugin({
template: "./public/index.html"
}),
new webpack.HotModuleReplacementPlugin()
],
module: {
rules: [
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
},
target: "web",
devServer: {
open: true,
static: {
directory: path.join(__dirname, '../public'),
},
historyApiFallback: true,
},
});
webpack.prod.js
const path = require("path");
const common = require("./webpack.common");
const { merge } = require("webpack-merge");
var MinifyPlugin = require('babel-minify-webpack-plugin')
var CompressionPlugin = require('compression-webpack-plugin');
const CleanWebpackPlugin = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const TerserPlugin = require("terser-webpack-plugin");
var HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = merge(common, {
mode: "production",
output: {
filename: "naming.[name].contenthash.[contenthash].bundle.js",
path: path.resolve(__dirname, "../build")
},
optimization: {
minimizer: [
new TerserPlugin(),
new HtmlWebpackPlugin( {
template: "./public/index.html",
minify: {
removeAttributeQuotes: true,
collapseWhitespace: true,
removeComments: true
}
} ),
new MinifyPlugin({}, {
comments: false
})
],
splitChunks: {
chunks: 'all',
minChunks: 3
}
},
plugins: [
new CompressionPlugin({
test: /\.js$|\.css$|\.html$/
}),
new MiniCssExtractPlugin({ filename: "naming.[name].contenthash.[contenthash].css" }),
new CleanWebpackPlugin()
],
module: {
rules: [
{
test: /\.css/i,
use: [
MiniCssExtractPlugin.loader,
"css-loader"
]
},
]
}
});

The error shows that you might use Xterm before its initialization,
You might find it useful to use react-aptor or the idea behind it to connect pure js packages like Xterm.js into react world.
import useAptor from 'react-aptor';
const initializer = (node, params) => {
// user params for further configuration
const terminal = new Terminal();
term.open(node);
return terminal;
}
const getAPI = (terminal, params) => {
return () => ({ terminal })
}
const ReactXterm = (props, ref) => {
const aptorRef = useAptor(ref, {
getAPI,
instantiate,
/* params: anything */
});
return <div ref={aptorRef} />;
};
function App() {
const ref = useRef();
const writeToTerminal = () => {
ref.current.terminal?.write('Hello from \x1B[1;3;31mxterm.js\x1B[0m $ ');
};
return (
<div>
<ReactXterm ref={ref} />
<button onClick={writeToTerminal}>write to terminal</button>
</div>
);
}
Disclosure: I am the maintainer of react-aptor

Related

Image not loading in React JS

I am new to React JS world, without web pack Image loading properly but when am using webpack Image not loading if image size greater than 24*24 pixel.
if Image size less than (24*24 pixel) then image is loading properly.
Image under src/assets/Image/exportImage.jpg'; I have no idea about this.
import exportImage from '../../assets/image/exportImage.png';
<img src={exportImage} id="ui-image"></img>
config-overrides.js
const name = '';
const publicPath = process.env.NODE_ENV === 'production' ? 'https://qiankun.umijs.org/' : 'http://localhost:3000/';
const {
override,
fixBabelImports,
addLessLoader,
overrideDevServer
} = require("customize-cra");
const path = require("path");
module.exports = override(
fixBabelImports('import',{
libraryName:'antd',
libraryDirectory:'es',
style:true
}),
addLessLoader({
javascriptEnabled:true,
})
);
module.exports = {
webpack: function overide(config, env) {
config.output.library = `${name}`;
config.output.libraryTarget = 'umd';
config.output.jsonpFunction = `webpackJsonp_${name}`;
config.output.globalObject = 'window';
return config;
}
,
devServer: function (configFunction) {
return function (proxy, allowedHost) {
const config = configFunction(proxy, allowedHost);
config.open = false;
config.hot = false;
config.headers = {
'Access-Control-Allow-Origin': '*',
};
return config;
};
},
module: {
rules: [
{
test: /\.(png|jpe?g|gif|webp|jpg)$/i,
use: [
{
loader: 'file-loader',
options: {
name: 'img/[name].[hash:8].[ext]',
publicPath,
},
},
],
},
{
test: /\.(woff2?|eot|ttf|otf)$/i,
use: [
{
loader: 'file-loader',
options: {
name: 'fonts/[name].[hash:8].[ext]',
publicPath,
},
},
],
},
],
},
};
please help me, how can I overcome this issue.
finally I found the solution, use the below attribute set to bigger than the image size
IMAGE_INLINE_SIZE_LIMIT

WDS Disconnected! sockjs-node refused, webpack-dev-middleware, expressjs

Some sockjs-node errors here
I'm building a dev server using express...
ADDED webpack-dev-middleware and webpack-hot-middleware for my React
Here's my webpack.config.js:
// require('dotenv').config()
const ESLintPlugin = require('eslint-webpack-plugin')
const ErrorOverlayPlugin = require('error-overlay-webpack-plugin')
const HTMLWebpackPlugin = require('html-webpack-plugin')
const { WebpackManifestPlugin } = require('webpack-manifest-plugin')
const path = require('path')
const webpack = require('webpack');
const eslintPlugin = new ESLintPlugin({ fix: true })
const manifestPlugin = new WebpackManifestPlugin()
const HMRPlugin = new webpack.HotModuleReplacementPlugin()
const htmlPlugin = new HTMLWebpackPlugin({
template: path.resolve(__dirname, 'build/app.html'),
filename: 'index.html',
})
const errorPlugin = new ErrorOverlayPlugin()
module.exports = {
mode: 'development',
entry: [
'webpack-dev-server/client?http://127.0.0.1:3999/',
'webpack/hot/only-dev-server',
'./src/index.js',
],
output: {
path: path.resolve(__dirname, 'build'),
filename: 'main.bundle.js',
publicPath: '/',
pathinfo: true,
},
devServer: {
socket: 'socket',
hot: true,
overlay: true,
port: 3999,
inline: true,
stats: 'normal',
historyApiFallback: true,
},
performance: {
hints: false,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
include: path.resolve(__dirname, 'src'),
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.(scss)$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.(png|svg|jpe?g|gif|ico)$/i,
type: 'asset/resource',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
],
},
plugins: [eslintPlugin, manifestPlugin, errorPlugin, htmlPlugin, HMRPlugin],
devtool: 'cheap-module-source-map',
}
My server.js:
import express from 'express'
import debug from 'debug'
import logger from 'morgan'
import chalk from 'chalk'
import dotenv from 'dotenv'
import webpack from 'webpack'
import hotMiddleware from 'webpack-hot-middleware'
import wpDevMiddleware from 'webpack-dev-middleware'
import cors from 'cors'
import wpConf from './webpack.config'
dotenv.config()
const app = express()
const port = process.env.PORT
const ecoS = debug('ECO-Server')
const ecoC = debug('ECO-Client')
const compiler = webpack(wpConf)
const skipLog = (req, res) => {
var { url } = req
if (url.match(/sockjs/gi)) {
return true
}
return false
}
app.set('port', port)
app.use(cors({ maxAge: 1000 * 60 * 60 * 24 * 2 }))
app.use(
logger('dev', {
stream: {
write: msg => ecoC(msg.trimEnd()),
},
skip: skipLog,
})
)
app.use(wpDevMiddleware(compiler))
app.use(hotMiddleware(compiler))
setTimeout(() => {
app.listen(port, () => ecoS('Listening on port', chalk.cyanBright(port)))
}, 4000)
127.0.0.1:3999/sockjs-node/info?t=1615910198493:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
sockjs.js:1609 XHR failed loading: GET "http://127.0.0.1:3999/sockjs-node/info?t=1615910266231".
please help me this... anyone?

How to set environment variables on React with custom webpack

My React app isn't run by create-react-app, but a custom Webpack config.
I"ve installed dotenv / dotenv-expand / and also dotenv-webpack.
I have .env / .env.development files with API_URL variable in it.
On my url file,
const { API_URL } = process.env
and use this API_URL to fetch data.
But on this file, when I console.log(process.env), it is empty.
I also have tried to update webpack.config.js file with
const Dotenv = require('dotenv-webpack');
and
new Dotenv()
in plugins array.
But still doesn't work.
I also tried having variable name REACT_APP_API_URL but was same result.
Could anyone help me to set the env vars?
Thank you.
webpack.config.js
const webpack = require('webpack')
const Dotenv = require('dotenv-webpack');
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpackMerge = require('webpack-merge')
const modeConfig = env => require(`./build-utils/webpack.${env}`)(env)
const presetConfig = require('./build-utils/loadPresets')
module.exports = ({ mode, presets } = { mode: 'production', presets: [] }) => {
console.log('mode', mode, 'presets', presets)
return webpackMerge(
{
mode,
module: {
rules: [
{
test: /\.(png|jpe?g|svg)$/,
use: {
loader: 'file-loader',
options: {
name: 'assets/[name].[ext]',
}
},
},
],
},
node: {
fs: 'empty'
},
resolve: {
extensions: ['.js', '.json'],
},
output: {
filename: 'bundle.js',
chunkFilename: '[name].lazy-chunk.js',
path: path.resolve(__dirname, 'build'),
publicPath: mode === 'development' ? '/' : './'
},
devServer: {
historyApiFallback: true
},
plugins: [
new HtmlWebpackPlugin({
template: './build-utils/template.html'
}),
new webpack.ProgressPlugin(),
new Dotenv()
]
},
modeConfig(mode),
presetConfig({ mode, presets })
)
}
If you're trying to access the env values in your JS files, you typically need to have the dotenv plugin.
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpackMerge = require('webpack-merge')
require('dotenv').config() // may need to set path to your .env file if it isn't at the root at the project
const modeConfig = env => require(`./build-utils/webpack.${env}`)(env)
const presetConfig = require('./build-utils/loadPresets')
module.exports = ({ mode, presets } = { mode: 'production', presets: [] }) => {
return webpackMerge(
...
plugins: [
new HtmlWebpackPlugin({
template: './build-utils/template.html'
}),
new webpack.ProgressPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
SOME_VALUE: JSON.stringify(process.env.SOME_VALUE),
...
}
})
]
},
...
)
}
NOTE: With this implementation you won't be able to do
const { API_URL } = process.env because DefinePlugin does a search and replace of the JavaScript where it will look up any references to process.env.API_URL and replace it with whatever that value is. Therefore API_URL won't exist on porcess.env, so to use it just do process.env.API_URL
You could also use dotenv-webpack, I think you were close to getting it to work.
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpackMerge = require('webpack-merge')
const Dotenv = require('dotenv-webpack');
const modeConfig = env => require(`./build-utils/webpack.${env}`)(env)
const presetConfig = require('./build-utils/loadPresets')
module.exports = ({ mode, presets } = { mode: 'production', presets: [] }) => {
return webpackMerge(
...
plugins: [
new HtmlWebpackPlugin({
template: './build-utils/template.html'
}),
new webpack.ProgressPlugin(),
new Dotenv({
path: envPath
})
]
},
...
)
}
If you need more help please share more details in by creating a Minimal, Reproducible Example.

deploying officejs fabric react word add in

I have a word add in written in typescript using Officejs and office-ui-fabric-react. Everything works fine with the server running locally. I'd like to deploy into AWS S3 with Cloudfront. I'm building with npm run build, and npm run deploy (using deploy command "aws --profile profile-name s3 sync dist/ s3://bucketname". Static web site hosting is enabled in the S3 bucket. All files from the dist directory are seen in the bucket. After inserting the add in into Word with a manifest.xml file that points to the cloudfront endpoint I'm getting the error "Uncaught ReferenceError: React is not defined". The same error occurs when I point directly to the S3 static web endpoint. To see if I've missed anything I deployed a generic create-react-app using the steps above and it runs fine. I'm assuming that the problem lies with my webpack config so I've included that here (common, and prod). I'd be happy to include anything else that's needed. I'm also open to other deployment options if using AWS is causing the problem.
webpack.common.js:
const webpack = require('webpack');
const path = require('path');
const package = require('../package.json');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');
const build = (() => {
const timestamp = new Date().getTime();
return {
name: package.name,
version: package.version,
timestamp: timestamp,
author: package.author
};
})();
const entry = {
vendor: [
'react',
'react-dom',
'core-js',
'office-ui-fabric-react'
],
app: [
'react-hot-loader/patch',
'./index.tsx',
],
'function-file': '../function-file/function-file.ts'
};
const rules = [
{
test: /\.tsx?$/,
use: [
'react-hot-loader/webpack',
'ts-loader'
],
exclude: /node_modules/
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.less$/,
use: ['style-loader', 'css-loader', 'less-loader']
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
use: {
loader: 'file-loader',
query: {
name: 'assets/[name].[ext]'
}
}
}
];
const output = {
path: path.resolve('dist'),
publicPath: '/',
filename: '[name].[hash].js',
chunkFilename: '[id].[hash].chunk.js'
};
const WEBPACK_PLUGINS = [
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.BannerPlugin({ banner: `${build.name} v.${build.version} (${build.timestamp}) © ${build.author}` }),
new webpack.DefinePlugin({
ENVIRONMENT: JSON.stringify({
build: build
})
}),
new webpack.LoaderOptionsPlugin({
options: {
postcss: [
autoprefixer({ browsers: ['Safari >= 8', 'last 2 versions'] }),
],
htmlLoader: {
minimize: true
}
}
})
];
module.exports = {
context: path.resolve('./src'),
entry,
output,
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.scss', '.css', '.html']
},
module: {
rules,
},
optimization: {
splitChunks: {
chunks: 'async',
minChunks: Infinity,
name: 'vendor'
}
},
plugins: [
...WEBPACK_PLUGINS,
new ExtractTextPlugin('[name].[hash].css'),
new HtmlWebpackPlugin({
title: 'letterConfig',
filename: 'index.html',
template: './index.html',
chunks: ['app', 'vendor', 'polyfills']
}),
new HtmlWebpackPlugin({
title: 'letterConfig',
filename: 'function-file/function-file.html',
template: '../function-file/function-file.html',
chunks: ['function-file']
}),
new CopyWebpackPlugin([
{
from: '../assets',
ignore: ['*.scss'],
to: 'assets',
}
])
]
};
webpack.prod.js:
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const commonConfig = require('./webpack.common.js');
const ENV = process.env.NODE_ENV = process.env.ENV = 'development';
module.exports = webpackMerge(commonConfig, {
devtool: 'source-map',
externals: {
'react': 'React',
'react-dom': 'ReactDOM'
},
performance: {
hints: "warning"
},
optimization: {
minimize: true
}
});
index.tsx:
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import { initializeIcons } from 'office-ui-fabric-react/lib/Icons';
import App from './components/App';
import './styles.less';
import 'office-ui-fabric-react/dist/css/fabric.min.css';
initializeIcons();
let isOfficeInitialized = false;
const title = 'letterConfig';
const render = (Component) => {
ReactDOM.render(
<AppContainer>
<Component title={title} isOfficeInitialized={isOfficeInitialized} />
</AppContainer>,
document.getElementById('container')
);
};
/* Render application after Office initializes */
Office.initialize = () => {
console.log('init');
isOfficeInitialized = true;
render(App);
};
/* Initial render showing a progress bar */
render(App);
if ((module as any).hot) {
(module as any).hot.accept('./components/App', () => {
const NextApp = require('./components/App').default;
render(NextApp);
});
}
It turned out that it was looking for a globally defined "React", and so not resolving via an npm module. In the webpack.prod.js file removing the following solved the problem:
externals: {
'react': 'React',
'react-dom': 'ReactDOM'
},

express-typescript-react: 404 (not found) frontend bundle file

I am making a full stack application, with Express(written in Typescript) and React. I am using webpack to bundle both backend and frontend.
I have two separate configs for webpack. One for frontend and the other one for backend.
Frontend config (webpack-fe.config.js)
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpack = require('clean-webpack-plugin');
const FRONTENDSRC = path.resolve(__dirname, 'frontend/src');
module.exports = {
target: 'web',
// #babel/polyfill is needed to use modern js functionalities in old browsers.
entry: ['#babel/polyfill', path.resolve(FRONTENDSRC, 'index.js')],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle-fe.js'
},
module: {
rules: [
{
test: /\.jsx$|.js$/,
use: {
loader: 'babel-loader',
options: {
// To process async functions.
plugins: ['#babel/plugin-transform-async-to-generator']
}
},
exclude: /(node_modules|bower_components)/
},
{
test: /\.scss$|.sass/,
loaders: ['style-loader', 'css-loader', 'sass-loader']
}
]
},
resolve: {
modules: ['node_modules', FRONTENDSRC],
extensions: ['.js', '.jsx', '.ts', '.tsx', '.css', '.scss']
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(FRONTENDSRC, 'index.html')
}),
new CleanWebpack(['./dist/bundle-be.js', './dist/index.html'])
],
watch: true,
mode: 'development',
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
compress: true,
port: 9000
}
};
Backend config (webpack-be.config.js)
const path = require('path');
const CleanWebpack = require('clean-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const projectDir = 'string value used to define path';
module.exports = {
context: projectDir,
target: 'node',
// #babel/polyfill is needed to use modern js functionalities in old browsers.
entry: [
'#babel/polyfill',
path.join(projectDir, 'backend', 'src', 'index.ts')
],
output: {
path: path.join(projectDir, 'dist'),
filename: 'bundle-be.js',
publicPath: path.join(projectDir, 'dist')
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
// To process async functions.
plugins: ['#babel/plugin-transform-async-to-generator']
}
},
exclude: /(node_modules|bower_components)/
},
{
test: /.ts$/,
loaders: ['ts-loader'],
exclude: /(node_modules|bower_components)/
}
]
},
resolve: {
modules: ['node_modules', path.join(projectDir, 'backend', 'src')],
extensions: ['.js', 'web.js', 'webpack.js', '.ts', '.tsx']
},
plugins: [new CleanWebpack([path.join(projectDir, 'dist', 'bundle-be.js')])],
watch: true,
externals: [nodeExternals()],
mode: 'development',
devtool: 'inline-source-map'
};
webpack.config.js
const feConfig = require('./webpack-fe.config');
const beConfig = require('./webpack-be.config');
module.exports = [feConfig, beConfig];
Here is the code for Server Initialization (index.ts)
import http from 'http';
import debug from 'debug';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import App from './server';
const config = require('../../webpack-be.config.js');
const compiler = webpack(config);
debug('ts-express:server');
class InitServer {
private port: number | boolean | string;
private server: any;
constructor() {
this.port = this.normalizePort(process.env.port || 7000);
App.set('port', this.port);
App.use(
webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath
})
);
this.server = http.createServer(App);
this.server.listen(this.port);
this.server.on('error', this.onError);
this.server.on('listening', this.onListening);
}
private normalizePort = (val: number | string): number | string | boolean => {
let port: number = typeof val === 'string' ? parseInt(val, 10) : val;
if (isNaN(port)) return val;
else if (port >= 0) return port;
else return false;
};
private onError = (error: NodeJS.ErrnoException): void => {
if (error.syscall !== 'listen') throw error;
let bind =
typeof this.port === 'string' ? 'Pipe ' + this.port : 'Port ' + this.port;
switch (error.code) {
case 'EACCES':
console.error(`${bind} requires elevated privileges`);
process.exit(1);
break;
case 'EADDRINUSE':
console.error(`${bind} is already in use`);
process.exit(1);
break;
default:
throw error;
}
};
private onListening = (): void => {
console.log(`listening on ${this.port}`);
let addr = this.server.address();
let bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`;
debug(`Listening on ${bind}`);
};
}
new InitServer();
Here is the server config file(server.ts)
import express from 'express';
import bodyParser from 'body-parser';
import path from 'path';
import { projectDir } from './shared/constants';
class App {
public express: express.Application;
constructor() {
this.express = express();
this.middleware();
this.routes();
}
private middleware(): void {
this.express.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', '*');
next();
});
this.express.use(bodyParser.json());
this.express.use(bodyParser.urlencoded({ extended: false }));
}
private routes(): void {
this.express.get('/', function(req, res) {
res.sendFile(path.join(projectDir, 'dist', 'index.html'));
});
}
}
export default new App().express;
I use the following commands in the npm scripts:
"bundle": "webpack",
"serve": "node dist/bundle-be.js"
When I start the server, it serves my index.html file from the dist folder, but it gives me a 404 error for bundle-fe.js. I have checked that bundle-fe.js is generated in the dist folder. So why does it give me a 404 for bundle-fe.js ?
Thanks in advance!
Found it, I had to change the config file that I was using in index.ts file.
const config = require('../../webpack-fe.config.js'); // instead of webpack-be.config.js
Lol ^^ !!

Resources