diff --git a/package.json b/package.json index 603d3d0..df8cec2 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "An Obsidian plugin for displaying markdown notes as mindmaps using Markmap", "scripts": { "dev": "webpack --mode development --watch", - "build": "webpack --mode production", + "build": "node --loader ts-node/esm ./node_modules/webpack/bin/webpack.js --mode production", "coverage": "nyc -r lcov -e .ts -x \"*.test.ts\" npm run test", "test": "vitest" }, @@ -18,6 +18,7 @@ "@types/node": "^22.10.7", "@types/ramda": "^0.30.2", "@typescript-eslint/parser": "^8.21.0", + "buffer": "^6.0.3", "eslint": "^9.18.0", "moment": "^2.29.4", "nyc": "^17.1.0", @@ -62,6 +63,7 @@ "markmap-toolbar": "^0.18.9", "markmap-view": "^0.18.9", "ramda": "^0.30.1", + "ts-node": "^10.9.2", "tsconfig-paths-webpack-plugin": "^4.2.0", "vitest": "^3.0.4", "webpack": "^5.97.1", diff --git a/tsconfig.json b/tsconfig.json index 502b18f..17d7e86 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,6 +25,11 @@ }, "types": ["vitest/globals"] }, + "ts-node": { + "compilerOptions": { + }, + "esm": true + }, "include": [ "**/*.ts", "src/types" diff --git a/webpack.config.ts b/webpack.config.ts index 3d4d7e8..579f639 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -4,6 +4,10 @@ import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin' import { type Configuration } from 'webpack' import webpack from 'webpack' import ForkTsCheckerPlugin from 'fork-ts-checker-webpack-plugin' +import { Buffer } from 'buffer' +import { createRequire } from 'module' + +const require = createRequire(import.meta.url) export default (env, argv): Configuration => ({ mode: getMode(argv.mode), @@ -15,9 +19,11 @@ export default (env, argv): Configuration => ({ }, resolve: { extensions: ['.ts', '.js'], - plugins: [new TsconfigPathsPlugin] + plugins: [new TsconfigPathsPlugin], + fallback: { + buffer: require.resolve('buffer/') + } }, - target: 'node', module: { rules: [ { @@ -28,6 +34,9 @@ export default (env, argv): Configuration => ({ }, plugins: [ new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }), + new webpack.ProvidePlugin({ + Buffer: ['buffer', 'Buffer'], + }), new CopyPlugin({ patterns: [ { from: 'styles.css', to: '.' },