oneuptime/Dashboard/webpack.config.js

80 lines
2.0 KiB
JavaScript
Raw Normal View History

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');
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;
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]);
}
2022-12-07 14:13:33 +00:00
2022-05-24 13:22:56 +00:00
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': {
...readEnvFile('../Common/.env'),
...readEnvFile('../CommonUI/.env'),
...readEnvFile('./.env')
}
}
2022-06-27 13:19:59 +00:00
}),
2022-05-24 13:22:56 +00:00
],
2022-05-22 08:49:16 +00:00
module: {
rules: [
{
test: /\.(ts|tsx)$/,
use: 'ts-loader'
},
{
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
}