GithubHelp home page GithubHelp logo

surajp / npm-to-lwc Goto Github PK

View Code? Open in Web Editor NEW
34.0 2.0 4.0 9 KB

A script to install any npm package as an LWC-ready static resource

License: MIT License

Shell 100.00%
bash cli lightning lwc npm salesforce sfdx staticresources

npm-to-lwc's Introduction

Instantly install any npm package as an LWC-ready static resource

The only script you will ever need to use an npm package in LWC. This script faciliates installation, and ease of usage by removing ambiguities around how you would refer to the loaded modules in your LWC.

Important: The script does not magically make a library locker-service compatible. The library won't work correctly if it is not locker-service compatible.

Prerequisites

  • Bash shell (with curl)
  • NodeJS and NPM
  • Salesforce CLI

Usage

Download the script and copy it to your sfdx project root folder. Run ./npmtolwc.sh <list of modules to include in your static resource> <optional flags>

./npmtolwc.sh without any arguments will show you the list of flags and usage instructions.

Examples

  • Running ./npmtolwc.sh d3-scale,d3-time -s time will create a static resource file named time in your project's staticResources folder. The name of the library inside the static resource would be d3scale_d3time. After importing the resource in your LWC you can use the functions in d3-scale with the syntax d3scale_d3time.d3scale.<function name>

  • Running ./npmtolwc.sh d3-scale,d3-time -s time -l timescale will create a static resource file named time in your project's staticresources folder. The name of the library inside the static resource would be timescale. After importing the resource in your LWC you can use the functions in d3-scale with the syntax timescale.d3scale.<function name>

Features

  • A single command to convert any npm package to an LWC-ready static resource.
  • Import multiple modules (related or unrelated) into a single static resource file.
  • Clear instructions on how to refer to the module(s) in your LWC once loaded.

The script might take a bit longer to run the first time as it downloads webpack and other dependencies.

npm-to-lwc's People

Contributors

agurtovoy avatar surajp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

npm-to-lwc's Issues

Error in bundle.js

Is it normal to get these errors?

ERROR in bundle.js from Terser
Error: error:0308010C:digital envelope routines::unsupported
   at new Hash (node:internal/crypto/hash:69:19)
   at Object.createHash (node:crypto:138:10)
   at <LocalPath>/node_modules/terser-webpack-plugin/dist/index.js:217:37
   at Array.forEach (<anonymous>)
   at TerserPlugin.optimizeFn (<LocalPath>/node_modules/terser-webpack-plugin/dist/index.js:160:259)
   at AsyncSeriesHook.eval [as callAsync] (eval at create (<LocalPath>/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:7:1)
   at AsyncSeriesHook.lazyCompileHook (<LocalPath>/node_modules/tapable/lib/Hook.js:154:20)
   at <LocalPath>/node_modules/webpack/lib/Compilation.js:1409:36
   at AsyncSeriesHook.eval [as callAsync] (eval at create (<LocalPath>/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
   at AsyncSeriesHook.lazyCompileHook (<LocalPath>/node_modules/tapable/lib/Hook.js:154:20)
   at <LocalPath>/node_modules/webpack/lib/Compilation.js:1405:32
   at AsyncSeriesHook.eval [as callAsync] (eval at create (<LocalPath>/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
   at AsyncSeriesHook.lazyCompileHook (<LocalPath>/node_modules/tapable/lib/Hook.js:154:20)
   at Compilation.seal (<LocalPath>/node_modules/webpack/lib/Compilation.js:1342:27)
   at <LocalPath>/node_modules/webpack/lib/Compiler.js:675:18
   at <LocalPath>/node_modules/webpack/lib/Compilation.js:1261:4

Also when running bash ./npmtolwc.sh d3-scale,d3-time -s time I don't see staticresources folder getting populated?

Not able to create static resource for xml2js

Hi @surajp I am trying to install xml2js library to create static reasource for my project sinse I couldn't find exact lib file for xml2js.
but I am facing this error

opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'

can you please provide your help to understand what's the exact issue is?

Not able to access module

Hi, I tried the script with the library "angular-expressions". After importing the static resource and doing loadScript, I added a debugger statement.
If I do console.log(window.angularexpressions), it is undefined. But all other objects are logged in the console.

Is it because angularexpressions is a module? And if so how do I access/import(?) it? AFAIK dynamic imports in LWC are not supported...

Silly me.. I was trying to access angularExpressions this whole time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.