Skip to content

Commit

Permalink
feat: add null-loader to simpleserialze webpack config
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewkeil committed Jun 10, 2024
1 parent bc68bad commit 7b170dc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 39 deletions.
1 change: 1 addition & 0 deletions packages/simpleserialize.com/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"eyzy-tree": "^0.2.2",
"file-saver": "^2.0.5",
"js-yaml": "^4.1.0",
"null-loader": "^4.0.1",
"react": "^17.0.2",
"react-alert": "^7.0.1",
"react-alert-template-basic": "^1.0.0",
Expand Down
86 changes: 47 additions & 39 deletions packages/simpleserialize.com/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const webpack = require('webpack');
const { resolve } = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require("webpack");
const {resolve} = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");

const isProd = process.env.NODE_ENV === 'production';
const isProd = process.env.NODE_ENV === "production";

const config = {
devtool: "source-map",
mode: isProd ? 'production' : 'development',
mode: isProd ? "production" : "development",
entry: {
index: './src/index.tsx',
index: "./src/index.tsx",
},
output: {
path: resolve(__dirname, 'dist'),
filename: '[name].js',
path: resolve(__dirname, "dist"),
filename: "[name].js",
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
module: {
rules: [
Expand All @@ -27,68 +27,72 @@ const config = {
},
},
{
test: /\.scss$/,
use: [
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader'
loader: "css-loader",
},
{
loader: 'sass-loader',
loader: "sass-loader",
options: {
sourceMap: true,
}
}
]
},{
},
},
],
},
{
test: /\.tsx?$/,
use: 'babel-loader',
use: "babel-loader",
exclude: /node_modules/,
}
},
{
use: "null-loader",
test: /@chainsafe\/hashtree/,
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
process: "process/browser",
Buffer: ["buffer", "Buffer"],
}),
new MiniCssExtractPlugin({
filename: 'css/[name].bundle.css'
filename: "css/[name].bundle.css",
}),
new HtmlWebpackPlugin({
title: 'Simple Serialize | Chainsafe Systems',
template: 'src/index.html',
title: "Simple Serialize | Chainsafe Systems",
template: "src/index.html",
}),
],
};

if (isProd) {
config.optimization = {
minimizer: [
],
minimizer: [],
};
} else {
config.devServer = {
port: 8080, // https://webpack.js.org/configuration/dev-server/#devserverport
open: true, // https://webpack.js.org/configuration/dev-server/#devserveropen
hot: true, // https://webpack.js.org/configuration/dev-server/#devserverhot
compress: true, // https://webpack.js.org/configuration/dev-server/#devservercompress
stats: 'errors-only', // https://webpack.js.org/configuration/dev-server/#devserverstats-
stats: "errors-only", // https://webpack.js.org/configuration/dev-server/#devserverstats-
overlay: true, // https://webpack.js.org/configuration/dev-server/#devserveroverlay
};
}

const workerConfig = {
name: "worker",
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
entry: {
index: './src/components/worker/index.ts',
index: "./src/components/worker/index.ts",
},
output: {
path: resolve(__dirname, 'dist'),
filename: 'worker.js',
path: resolve(__dirname, "dist"),
filename: "worker.js",
},
module: {
rules: [
Expand All @@ -100,21 +104,25 @@ const workerConfig = {
},
{
test: /worker?$/,
loader: 'threads-webpack-plugin',
loader: "threads-webpack-plugin",
},
{
test: /\.ts?$/,
use: 'babel-loader',
use: "babel-loader",
exclude: /node_modules/,
}
},
{
use: "null-loader",
test: /@chainsafe\/hashtree/,
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
process: "process/browser",
Buffer: ["buffer", "Buffer"],
}),
]
}
],
};

module.exports = [config, workerConfig];
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8980,6 +8980,14 @@ nth-check@^2.0.1:
dependencies:
boolbase "^1.0.0"

null-loader@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/null-loader/-/null-loader-4.0.1.tgz#8e63bd3a2dd3c64236a4679428632edd0a6dbc6a"
integrity sha512-pxqVbi4U6N26lq+LmgIbB5XATP0VdZKOG25DhHi8btMmJJefGArFyDg1yc4U3hWCJbMqSrw0qyrz1UQX+qYXqg==
dependencies:
loader-utils "^2.0.0"
schema-utils "^3.0.0"

nx@19.0.4, "nx@>=17.1.2 < 20":
version "19.0.4"
resolved "https://registry.yarnpkg.com/nx/-/nx-19.0.4.tgz#c39803f6186f6b009c39f5f30f902ce8e136dcde"
Expand Down

0 comments on commit 7b170dc

Please sign in to comment.