remotely-save/webpack.config.js

101 lines
3.0 KiB
JavaScript
Raw Normal View History

2021-12-01 02:10:39 +00:00
require("dotenv").config();
2021-11-30 17:49:29 +00:00
const path = require("path");
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
2021-12-01 02:10:39 +00:00
const DEFAULT_DROPBOX_APP_KEY = process.env.DROPBOX_APP_KEY || "";
2021-12-28 16:35:46 +00:00
const DEFAULT_ONEDRIVE_CLIENT_ID = process.env.ONEDRIVE_CLIENT_ID || "";
const DEFAULT_ONEDRIVE_AUTHORITY = process.env.ONEDRIVE_AUTHORITY || "";
2021-12-01 02:10:39 +00:00
2021-11-30 17:49:29 +00:00
module.exports = {
entry: "./src/main.ts",
target: "web",
output: {
filename: "main.js",
path: __dirname,
libraryTarget: "commonjs",
},
plugins: [
2021-12-01 02:10:39 +00:00
new webpack.DefinePlugin({
"process.env.DEFAULT_DROPBOX_APP_KEY": `"${DEFAULT_DROPBOX_APP_KEY}"`,
2021-12-28 16:35:46 +00:00
"process.env.DEFAULT_ONEDRIVE_CLIENT_ID": `"${DEFAULT_ONEDRIVE_CLIENT_ID}"`,
"process.env.DEFAULT_ONEDRIVE_AUTHORITY": `"${DEFAULT_ONEDRIVE_AUTHORITY}"`,
2021-12-01 02:10:39 +00:00
}),
2021-11-30 17:49:29 +00:00
// Work around for Buffer is undefined:
// https://github.com/webpack/changelog-v5/issues/10
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
new webpack.ProvidePlugin({
process: "process/browser",
}),
],
module: {
rules: [
2024-03-24 16:21:56 +00:00
{
test: /\.worker\.ts$/,
loader: "worker-loader",
options: {
inline: "no-fallback",
},
},
2021-11-30 17:49:29 +00:00
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
2021-12-11 14:45:21 +00:00
{
test: /\.svg?$/,
type: "asset/source",
},
2023-12-17 07:18:23 +00:00
{
test: /\.m?js$/,
resolve: {
fullySpecified: false, // process/browser returns some errors before
},
},
2021-11-30 17:49:29 +00:00
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
mainFields: ["browser", "module", "main"],
fallback: {
// assert: require.resolve("assert"),
// buffer: require.resolve("buffer/"),
// console: require.resolve("console-browserify"),
// constants: require.resolve("constants-browserify"),
2021-12-28 16:35:46 +00:00
crypto: require.resolve("crypto-browserify"),
// crypto: false,
2021-11-30 17:49:29 +00:00
// domain: require.resolve("domain-browser"),
// events: require.resolve("events"),
2023-12-17 07:18:23 +00:00
http: false,
2021-11-30 17:49:29 +00:00
// http: require.resolve("stream-http"),
2023-12-17 07:18:23 +00:00
https: false,
2021-11-30 17:49:29 +00:00
// https: require.resolve("https-browserify"),
2022-02-12 04:28:47 +00:00
net: false,
2021-11-30 17:49:29 +00:00
// os: require.resolve("os-browserify/browser"),
path: require.resolve("path-browserify"),
// punycode: require.resolve("punycode"),
process: require.resolve("process/browser"),
// querystring: require.resolve("querystring-es3"),
stream: require.resolve("stream-browserify"),
// string_decoder: require.resolve("string_decoder"),
// sys: require.resolve("util"),
// timers: require.resolve("timers-browserify"),
2022-02-12 04:28:47 +00:00
tls: false,
2021-11-30 17:49:29 +00:00
// tty: require.resolve("tty-browserify"),
2022-02-12 04:28:47 +00:00
url: require.resolve("url/"),
2021-11-30 17:49:29 +00:00
// util: require.resolve("util"),
// vm: require.resolve("vm-browserify"),
// zlib: require.resolve("browserify-zlib"),
},
},
externals: {
obsidian: "commonjs2 obsidian",
},
optimization: {
minimize: true,
minimizer: [new TerserPlugin({ extractComments: false })],
},
};