Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kettek/snowpack-plugin-selective-import-to-require

A selective import to require snowpack plugin.
https://github.com/kettek/snowpack-plugin-selective-import-to-require

Last synced: 19 days ago
JSON representation

A selective import to require snowpack plugin.

Awesome Lists containing this project

README

        

# snowpack-plugin-selective-import-to-require
Selectively convert `import` calls into `require` calls. Useful for running snowpack with Electron.

```
npm install --save-dev snowpack-plugin-selective-import-to-require
```

```js
// snowpack.config.json
module.exports = {
"plugins": [
[
"snowpack-plugin-selective-import-to-require",
{
"modules": ["os", "child_process"],
"types": ['.js'],
}
]
]
}
```

#### Plugin Options

| Name | Type | Description |
| :----------------- | :--------- | :---------- |
| `modules` | `string[]` | An array of module names to match against, such as `['os', 'child_process']`.
| `types` | `string[]` | (optional) By default, this plugin matches against `['.js']`. Provide an array if you need to match other extensions.

#### Match Built-in Node Modules
It may be convenient to match all built-in node modules.

```
npm install builtin-modules --save-dev
```

```js
// snowpack.config.json
const builtinModules = require('builtin-modules')

module.exports = {
"plugins": [
[
"snowpack-plugin-selective-import-to-require",
{
"modules": builtinModules,
"types": ['.js'],
}
]
],
"packageOptions": {
"external": builtinModules
},
}

```