# webpack-rpc-inline-plugin

> This plugin will inline scripts to the places where they are imported.

Latest version **0.2.2** (published 2021-11-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install webpack-rpc-inline-plugin
pnpm add webpack-rpc-inline-plugin
yarn add webpack-rpc-inline-plugin
bun add webpack-rpc-inline-plugin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2021-11-11 |
| First published | 2021-11-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | meathill |

## Links

- npm: https://www.npmjs.com/package/webpack-rpc-inline-plugin
- Repository: https://github.com/meathill/webpack-rpc-inline-plugin
- Homepage: https://github.com/meathill/webpack-rpc-inline-plugin#readme
- Issues: https://github.com/meathill/webpack-rpc-inline-plugin/issues
- npm.io page: https://npm.io/package/webpack-rpc-inline-plugin

## Dependencies (1)

- [schema-utils](https://npm.io/package/schema-utils.md) ^3.1.1

## Recent versions

- 0.2.2 (latest) — 2021-11-11
- 0.2.1 — 2021-11-11
- 0.2.0 — 2021-11-08

## README

Webpack RPC Inline Plugin
========

![Workflow status](https://github.com/meathill/webpack-rpc-inline-plugin/actions/workflows/node.js.yml/badge.svg)


This plugin will inline scripts to the places where they are imported.


Built for
---------

Sometimes, we may need to execute script in another context. Like in puppeteer,
we will call `page.evaluate(func, param1, param2)` to execute the function in
the context of THAT `page`.

In the situation, the whole function will be stringifies and passed to another
context. Then over there, **the another context**, the function will be re-instanced,
and executed.

If we use module methods as usual, like below:

```js
import someFunc from './some-func.js';

const param1 = 'hello';

page.evaluate(function (param1) {
  someFunc(param1);
}, param1);
```

JS engine won't find any matched function called `someFunc`, because it were
not passed.


Usage
-----

Install via `npm i webpack-rpc-inline-plugin -D`

Setup plugin in webpack.config.js:

```js
const InlinePlugin = require('webpack-rpc-inline-plugin');

module.exports = {
  plugins: [
    new InlinePlugin({
      // the rules will tell plugin which destination files should be inlined
      rules: [
        /my-rpc-file\.js$/,
      ],
      // the exclue has higher priority than `rules`
      exclude: [

      ],
    }),
  ],
};
```

```js
// inline-function.js
module.exports = function sayHello() {
  return 'hello';
}

// index.js
function rpcFunction() {
  const sayHello = require('./inline-function.js');
}
doRpcExecute(rpcFunction);


// will be compiled to: main.js
function rpcFunction() {
  const sayHello = function sayHello() {
    return 'hello';
  }
}
```


Demo
----

You can run `npm run dev` to see the result in `/dist` folder.


Author
------

Meathill <[mailto:meathill@gmail.com](meathill@gmail.com)>


LICENCE
-------

[MIT](https://opensource.org/licenses/MIT)

---
_Source: https://npm.io/package/webpack-rpc-inline-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
