remotely-save/webpack.config.js
2021-11-02 10:11:45 +08:00

69 lines
2.0 KiB
JavaScript

const path = require("path");
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
entry: "./src/main.ts",
target: "web",
output: {
filename: "main.js",
path: __dirname,
libraryTarget: "commonjs",
},
plugins: [
// 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: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
],
},
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"),
crypto: require.resolve("crypto-browserify"),
domain: require.resolve("domain-browser"),
events: require.resolve("events"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
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"),
tty: require.resolve("tty-browserify"),
url: require.resolve("url"),
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 })],
},
};