signoz/frontend/webpack.config.ts
Estee Tey Siew Wen 53d52254cb
Update webpack config to typescript (#334)
* added docker generated files to .gitignore

* update webpack.config.js to webpack.config.ts

* change web dev server to use port from env

* update webpack-dev-server to 4.3.1,  update import statement for chartjsAdapter

* Revert "added docker generated files to .gitignore"

This reverts commit 494cfcda0e9ed90de8daac3097957fa63df23570.

* use portfindersync for webpack dev server and remove .env.sample

* add webpack config typing to prod config
2021-10-27 13:24:12 +05:30

89 lines
2.0 KiB
TypeScript

// shared config (dev and prod)
import dotenv from 'dotenv';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { resolve } from 'path';
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import webpack from 'webpack';
import { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
// @ts-ignore
import portFinderSync from 'portfinder-sync';
dotenv.config();
const __dirname = resolve();
console.log(resolve(__dirname, './src/'));
interface Configuration extends webpack.Configuration {
devServer?: WebpackDevServerConfiguration;
}
const config: Configuration = {
mode: 'development',
devtool: 'source-map',
entry: resolve(__dirname, './src/index.tsx'),
devServer: {
historyApiFallback: true,
open: true,
hot: true,
liveReload: true,
port: portFinderSync.getPort(3000),
static: {
directory: resolve(__dirname, "public"),
publicPath: "/",
watch: true,
}
},
target: 'web',
output: {
filename: ({ chunk }) => {
const hash = chunk?.hash;
const name = chunk?.name;
return `js/${name}-${hash}.js`;
},
path: resolve(__dirname, './build'),
publicPath: '/',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
plugins: [new TsconfigPathsPlugin({})],
},
module: {
rules: [
{
test: [/\.jsx?$/, /\.tsx?$/],
use: ['babel-loader'],
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(scss|sass)$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
'file-loader?hash=sha512&digest=hex&name=img/[chunkhash].[ext]',
'image-webpack-loader?bypassOnDebug&optipng.optimizationLevel=7&gifsicle.interlaced=false',
],
},
],
},
plugins: [
new HtmlWebpackPlugin({ template: 'src/index.html.ejs' }),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env),
}),
],
performance: {
hints: false,
},
};
export default config;