oneuptime/Dashboard/webpack.config.js

85 lines
2.2 KiB
JavaScript
Raw Normal View History

2023-12-12 18:09:50 +00:00
require('ts-loader');
require('file-loader');
require('style-loader');
require('css-loader');
require('sass-loader');
2022-05-22 08:49:16 +00:00
const path = require("path");
const webpack = require("webpack");
2022-05-24 13:22:56 +00:00
const dotenv = require('dotenv');
2022-12-07 14:13:33 +00:00
const express = require('express');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
2022-05-24 13:22:56 +00:00
const readEnvFile = (pathToFile) => {
2022-12-07 14:13:33 +00:00
2022-05-24 13:22:56 +00:00
const parsed = dotenv.config({ path: pathToFile }).parsed;
2023-09-13 07:37:29 +00:00
const env = {
};
2022-12-07 14:13:33 +00:00
2022-05-24 13:22:56 +00:00
for (const key in parsed) {
env[key] = JSON.stringify(parsed[key]);
}
return env;
}
2022-05-22 08:49:16 +00:00
module.exports = {
entry: "./src/Index.tsx",
mode: "development",
output: {
filename: "bundle.js",
2022-12-07 14:13:33 +00:00
path: path.resolve(__dirname, "public", "dist"),
publicPath: "/dashboard/dist/",
2022-05-22 08:49:16 +00:00
},
resolve: {
2022-07-05 13:40:17 +00:00
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.css', '.scss'],
2022-06-27 13:19:59 +00:00
alias: {
react: path.resolve('./node_modules/react'),
}
2022-05-22 08:49:16 +00:00
},
externals: {
'react-native-sqlite-storage': 'react-native-sqlite-storage'
},
2022-05-24 13:22:56 +00:00
plugins: [
new webpack.DefinePlugin({
'process': {
'env': {
2023-07-22 16:45:12 +00:00
...readEnvFile('/usr/src/app/dev-env/.env')
2022-05-24 13:22:56 +00:00
}
}
2022-06-27 13:19:59 +00:00
}),
process.env.analyze === 'true' ? new BundleAnalyzerPlugin() : () => {},
2022-05-24 13:22:56 +00:00
],
2022-05-22 08:49:16 +00:00
module: {
rules: [
{
test: /\.(ts|tsx)$/,
loader: 'ts-loader',
2022-05-22 08:49:16 +00:00
},
{
test: /\.s[ac]ss$/i,
use: ['style-loader', 'css-loader', "sass-loader"]
},
2022-08-02 19:51:46 +00:00
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
},
2022-05-22 08:49:16 +00:00
{
2022-12-07 14:13:33 +00:00
test: /\.(jpe?g|png|gif|svg)$/i,
2022-07-05 13:40:17 +00:00
loader: 'file-loader'
2022-05-22 08:49:16 +00:00
}
],
},
devServer: {
historyApiFallback: true,
2022-07-05 13:40:17 +00:00
devMiddleware: {
writeToDisk: true,
},
2022-12-07 14:13:33 +00:00
allowedHosts: "all",
setupMiddlewares: (middlewares, devServer) => {
devServer.app.use('/dashboard/assets', express.static(path.resolve(__dirname, 'public', 'assets')));
return middlewares;
}
2022-05-22 08:49:16 +00:00
},
2022-06-29 20:51:49 +00:00
devtool: 'eval-source-map',
2022-05-22 08:49:16 +00:00
}