ObsidianPluginWebpackPlugin
A webpack plugin that builds an Obsidian plugin.
What it does, each only when the consumer’s config has not said otherwise:
entryissrc/main.ts, andmodefollows the build mode. - The output is one CommonJS (commonjs2)main.jsindist/build(dist/devin development), with no async chunks, so a dynamic import cannot become a sibling file. -targetisnode, which is what Obsidian’s renderer runs, so Node builtins resolve, while the export conditions are the browser’s (browser,webpack, the mode,module,import,require, and nevernode), so packages hand over their browser builds, as on mobile they must. -devtoolis an inline source map in development only.
And always: Obsidian’s own modules (obsidian, electron, CodeMirror, Lezer) and the Node builtins are external beside the consumer’s own externals, the generated-file banner heads main.js, license comments a minimizer extracted into main.js.LICENSE.txt (which no Obsidian release ships) are put back into main.js, the output folder is emptied before the first build, every emitted CSS file ends up in styles.css, manifest.json (and in development .hotreload) is copied beside it, and a development build is deployed into the vault named by OBSIDIAN_CONFIG_FOLDER.
TypeScript stays the consumer’s choice of loader, as it would be without this plugin. The build features (ObsidianPluginFeatureOptions) are the plugin’s:
framework: 'react' | 'preact'needs nothing here: the TypeScript loader reads the automatic JSX runtime from the toolkit’s tsconfig preset, and webpack’smodedefinesprocess.env.NODE_ENV. -framework: 'solid' | 'svelte'adds rules that compile the components with the toolkit’s shared transforms, and'vue'appliesunplugin-vueand defines Vue’s feature flags. -stylesadds the one rule every stylesheet goes through (PostCSS and Tailwind, thencss-loader, scoping*.module.cssonly withcssModules, thenmini-css-extract-plugin), and appliesmini-css-extract-pluginunless the config already does; leave your own.cssrule out.styles: {}compiles plain CSS. -wasmimports a.wasmmodule as its bytes.
Import:
import { ObsidianPluginWebpackPlugin } from '@mnaoumov/obsidian-dev-toolkit/bundlers/webpack';Signature:
export class ObsidianPluginWebpackPlugin implements WebpackPluginInstanceImplements: WebpackPluginInstance
Constructor
new ObsidianPluginWebpackPlugin(options?: ObsidianPluginWebpackPluginOptions)Creates the plugin.
Methods
| Method | Returns | Description |
|---|---|---|
| apply(compiler) | void | Applies the plugin to a webpack compiler. |
Links to this page: