Comments (14)
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.
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.
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.
Ah cool, that was the issue. Using devDependencies
instead if dependencies
did the trick.
Thanks 🙏
from klap.
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.
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.
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.
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.
🎉 This issue has been resolved in version 6.1.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
from klap.
@marcuslindblom Let me know if you notice any issues with this feature.
from klap.
@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.
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.
I'm using 6.0.9 atm
from klap.
@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)
- Klap can't find typescript on init HOT 11
- Custom babel config HOT 4
- Have an option to remove index.js from public directory HOT 6
- Unexpected token HOT 5
- Programmable API HOT 1
- Unhandled child_process exception: init.js HOT 1
- klap adds LICENSE even if LICENSE.md exists HOT 7
- Build development environment? HOT 2
- Make prettier config optional HOT 2
- Question: ncc vs rollup HOT 9
- klap vs microbundle? HOT 7
- Enable support for the experimental syntax 'importAssertions' HOT 3
- No way to override the options that are set by "defaultOptions" HOT 1
- Bundle async function expression used as an IIFE HOT 3
- Bundle and minify es6 modules breaks the named exports HOT 6
- Dynamic imports generates error HOT 1
- Let the user add more Rollup plugins and configure them differently HOT 6
- Support Dev Expressions HOT 1
- Strange import behaviour on importing external dependency HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from klap.