Code Monkey home page Code Monkey logo

Comments (14)

osdevisnot avatar osdevisnot commented on May 18, 2024

thank you for the issue @marcuslindblom, but I don't think any of the other JS bundler packages/bundles a URL import.

For your use case, since you've canvas-confetti already installed, perhaps you can change the import statement to:

import confetti from 'canvas-confetti';

from klap.

marcuslindblom avatar marcuslindblom commented on May 18, 2024

Tried that one also but the output is just

import"canvas-confetti";var o=()=>{console.log("Hello, world.")};export{o as hello};

Maybe it's important to tell you that my target is the browser and plain vanilla js in an es module.

from klap.

osdevisnot avatar osdevisnot commented on May 18, 2024

with the import changed to import confetti from 'canvas-confetti';, you should be able to get it bundled.

Please note that, klap will mark all the dependencies and peerDependencies as external by default.

If you really want to bundle canvas-confetti, you should move it to devDependencies. That way, when your library is installed, user's don't have to install canvas-confetti since your dist file already bundles it.

from klap.

marcuslindblom avatar marcuslindblom commented on May 18, 2024

Ah cool, that was the issue. Using devDependencies instead if dependencies did the trick.

Thanks 🙏

from klap.

marcuslindblom avatar marcuslindblom commented on May 18, 2024

Opening this issue again.

I'm using klap only to build my production package so for development I'm using imports like this import { openDB, deleteDB } from 'https://cdn.skypack.dev/idb';.

For production I would like Klap to bundle the external libraries and it's not an option to use import { openDB, deleteDB } from 'idb'; Installing idb as a devDependencies did not work?

from klap.

osdevisnot avatar osdevisnot commented on May 18, 2024

Without changing the import to from 'idb', there is now way for klap to map it to the devDependency.

Can you speak more about your workflow? One way to resolve this is to add a CDN plugin, which downloads the file when building for production and just ignore the urls when building for development.

from klap.

marcuslindblom avatar marcuslindblom commented on May 18, 2024

My workflow is pretty simple. My project use vanilla js with es modules. In production I bundle all my modules into a single file. I have two external dependencies that I would like to bundle because CDNs harm the performance of my app. A CDN plugin would work but maybe it's better to just download the scripts and put them in a lib folder. Seems like the easiest way atm :)

from klap.

osdevisnot avatar osdevisnot commented on May 18, 2024

Great, that helps. If it's not too much to ask, can you create a smallest reproduction for this workflow, or perhaps point me to existing project?

from klap.

osdevisnot avatar osdevisnot commented on May 18, 2024

🎉 This issue has been resolved in version 6.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

from klap.

osdevisnot avatar osdevisnot commented on May 18, 2024

@marcuslindblom Let me know if you notice any issues with this feature.

from klap.

marcuslindblom avatar marcuslindblom commented on May 18, 2024

@osdevisnot I just tried the new release and it fails with this exception.

❯ npx klap build -s wwwroot/scripts/index.js -e wwwroot/app.js
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'typescript'
Require stack:
- /Users/marcus/Library/Mobile Documents/com~apple~CloudDocs/Projects/private/wieldy/src/app/node_modules/klap/dist/index.js
- /Users/marcus/Library/Mobile Documents/com~apple~CloudDocs/Projects/private/wieldy/src/app/node_modules/klap/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.975034 (/Users/marcus/Library/Mobile Documents/com~apple~CloudDocs/Projects/private/wieldy/src/app/node_modules/klap/dist/index.js:723366:18)
    at __webpack_require__ (/Users/marcus/Library/Mobile Documents/com~apple~CloudDocs/Projects/private/wieldy/src/app/node_modules/klap/dist/index.js:723415:43)
    at Object.956237 (/Users/marcus/Library/Mobile Documents/com~apple~CloudDocs/Projects/private/wieldy/src/app/node_modules/klap/dist/index.js:607953:17)
    at __webpack_require__ (/Users/marcus/Library/Mobile Documents/com~apple~CloudDocs/Projects/private/wieldy/src/app/node_modules/klap/dist/index.js:723415:43)
    at Module.600669 (/Users/marcus/Library/Mobile Documents/com~apple~CloudDocs/Projects/private/wieldy/src/app/node_modules/klap/dist/index.js:694664:30)
    at __webpack_require__ (/Users/marcus/Library/Mobile Documents/com~apple~CloudDocs/Projects/private/wieldy/src/app/node_modules/klap/dist/index.js:723415:43) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/marcus/Library/Mobile Documents/com~apple~CloudDocs/Projects/private/wieldy/src/app/node_modules/klap/dist/index.js',
    '/Users/marcus/Library/Mobile Documents/com~apple~CloudDocs/Projects/private/wieldy/src/app/node_modules/klap/cli.js'
  ]
}

This is a vanilla js project with es modules only

from klap.

osdevisnot avatar osdevisnot commented on May 18, 2024

This is strange. typescript is marked as external dependency.

What version of klap are you upgrading from?

Also, can you please add a dependency on typescript temporarily, until this issue is resolved?

from klap.

marcuslindblom avatar marcuslindblom commented on May 18, 2024

I'm using 6.0.9 atm

from klap.

osdevisnot avatar osdevisnot commented on May 18, 2024

@marcuslindblom the latest version should fix this issue. Can you point me yo your repository if this is not the case?

from klap.

Related Issues (20)

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.