Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instructions for Parcel #15

Open
niksy opened this issue Feb 4, 2022 · 0 comments
Open

Add instructions for Parcel #15

niksy opened this issue Feb 4, 2022 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@niksy
Copy link
Owner

niksy commented Feb 4, 2022

Even though Parcel has native support for Node packages replacement, we still want to provide support using this module.

global, process and Buffer replacements are handled natively by Parcel inside Rust codebase so we won’t touch it and let Parcel resolve everything by itself.


In your project:

package.json

{
  "devDependencies": {
    "parcel-resolver-node-stdlib-browser": "file:node_modules/node-stdlib-browser/helpers/parcel/parcel-resolver-node-stdlib-browser"
  }
}

.parcelrc

{
  "extends": "@parcel/config-default",
  "resolvers": ["parcel-resolver-node-stdlib-browser", "..."]
}

In this module, for helpers/parcel/parcel-resolver-node-stdlib-browser:

package.json

{
  "name": "parcel-resolver-node-stdlib-browser",
  "main": "index.js",
  "engines": { "parcel": "^2.0.0" }
}

index.js

const { Resolver } = require('@parcel/plugin');
const { promisify } = require('util');
const stdLibBrowser = require('node-stdlib-browser');
const browserResolve = require('browser-resolve');

const pBrowserResolve = promisify(browserResolve);

module.exports = new Resolver({
  async resolve({ specifier }) {
    if (typeof stdLibBrowser[specifier] !== 'undefined') {
      const filePath = await pBrowserResolve(stdLibBrowser[specifier], {});
      return {
        filePath: filePath,
      };
    }
    return null;
  },
});
@niksy niksy added the documentation Improvements or additions to documentation label Feb 4, 2022
@niksy niksy self-assigned this Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant