svgdom
Version:
Straightforward DOM implementation for SVG, HTML and XML
47 lines (40 loc) • 1.25 kB
JavaScript
import { build } from 'esbuild'
import { polyfillNode } from 'esbuild-plugin-polyfill-node'
// import NodeResolve from '@esbuild-plugins/node-resolve'
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'
const importsDoIgnore = [
'fontkit',
'defaults.js'
]
// build regex from array
const ignoreRegex = new RegExp(importsDoIgnore.join('|'))
const ignorePlugin = {
name: 'ignore',
setup (build) {
// Intercept import paths that contain strings from array so esbuild doesn't attempt
// to map them to a file system location. Tag them with the "ignore-ns"
// namespace to reserve them for this plugin.
build.onResolve({ filter: ignoreRegex }, args => ({
path: args.path,
namespace: 'ignore-ns'
}))
// Load paths tagged with the "env-ns" namespace and behave as if
// they point to a JSON file containing the environment variables.
build.onLoad({ filter: /.*/, namespace: 'ignore-ns' }, () => ({
contents: 'export default {}'
// loader: ''
}))
}
}
build({
entryPoints: [ './main-module.js' ],
bundle: true,
outfile: './svgdom.js',
format: 'esm',
plugins: [
polyfillNode({
}),
NodeModulesPolyfillPlugin(),
ignorePlugin
]
})