-
Notifications
You must be signed in to change notification settings - Fork 495
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
A few observations #38
Comments
Had most of this feedback myself :). I ended up taking out all the HTML & HMR stuff where it wasn't relevant.
If you properly declare your dependencies (or peer dependencies), you actually can just run {
"module": "dist/src/<library>.js",
"scripts": {
"postbuild": "tsc --outDir dist/src"
}
} Note: If you're using webpack to, well, pack any dependencies and not take a dependency on them, this won't work. |
Yeah, I ended up doing that but still haven got a simple 'import {foo} from 'mylib' to work when using wepack against my umd bundle without crazy errors errors about no default export. This stuff is crazy fragile and complex. I can't believe how long I've spent trying to get a basic lib build and consumer set up to NOT work. I have a hard deadline coming up fast . :( You suggestion highlights one issue that confuses me. My expectation is webpack uses the entry to figure out which files to get tsc to compile via the load. But I found unless my tsconfig has a file entry all my files get processed, huh? But I'll give it a go. :) |
@SteveALee If you want to be explicit (which would probably be a good idea), I'd recommend adding this: "include": [
"src/**/*"
], to out your tsconfig. |
now to generate a single .d.ts file for the library... |
Hi gentlemen! Thanks for raising the issue. Let's go by parts:
Honestly, I wasn't totally convinced about including this, since for writing a library I do it in a TDD way, so I run Some people gets confused by this and they think this starter is for a frontend library, which is not. So I was thinking in take that out to another branch, let's say
Already had a question about this #33. I thought you must specify which libraries to exclude, so in the end the user has to know about that and include it by themselves on the
This is on track, see #35 and #34. Also want to experiment with Rollup, and probably use it along with Webpack as Todd Motto does in ngxErrors library I will not have too much time to work on this in the coming weeks, but feel free to send a PR and I'll review it ;)
Don't know what you mean, but -p is equivalent to
You cannot auto-generate a single d.ts file, and there is no need for it, TypeScript resolves the different d.ts files. You just have to point to the entry d.ts file, which in this starter is already configured for you. This is on track by the TypeScript team, and possible with external packages (dts-generator?), althought I haven't tried.
That should work out of the box with this library starter. I even use it myself for ShortcutJS. It seems you're confusing here how modules work in ES6/TS. With that syntax you're not using a default export. Also, keep in mind TypeScript treats differently the import whatever from 'whatever'` In TypeScript would be: import * as whatever from 'whatever'`
// Or
import whatever = require('whatever') Check this issue for more info Note: we're mixing here generic Webpack + TypeScript questions. Please let's try to here to report issues or questions related to this starter, and use StackOverflow or any other question. |
Apologies - after a weekend of going round in circles it's hard to tell which is which. Especially as I tried to understand and fix tools usage issues in the template for my use. I also got confused about what this starter is for. The server bit confused me. I now see you are only creating the global script for consumption in a browser. I expected something a bit different - along the lines of a typescript npm package library (collection of JS and .d.ts( usable form TS or JS node packages. Actually you currently need both, ie [3 separate versions of a library(http://marcobotto.com/compiling-and-bundling-typescript-libraries-with-webpack/) I'll split up my comments and create new issues. I'm also very busy but hope to help out.
But that only applies if you are distributing separate files- not a global script bundle
I only meant your script also defines NODE_ENV="'production'" which would appear to be redundant given what -p is equivalent too
I subsequently thought that this makes no sense as TS will never use the generated single global bundle - not even relevant for intellisense. But now I wonder if I was wrong all along on #40 and infact typescript can import the single js file with the separate types if --module UMD? I need to try it out! But anyway I agree it's not need and if lib is separate js (not bundle) files then user can also import subfiles to keep size down (though not needed with treeshaking).
I agree, that type of import is valid and does not involve any default export. The problem that caused the error was that I was trying to import the generate UMD bundle from some test typescript. It obviously got confused - perhaps I need to specify module = UMD? |
I think that'd be smarter. Once I dug into the skeleton it made sense, but that did throw me for a loop at first glance.
Yup! This all has to be done manually. One of the ironies of using webpack for this, as there's very little bundling happening :).
You should indeed have to specify UMD if you want UMD, and also make sure you're setting the correct root for externals and loading those into the global context wherever you're loading them. Great work btw @alexjoverm. This starter did seriously help reduce friction spinning up internal projects :) |
I'm finding this starter really useful! Thanks!
I've found a few things in using it and digging into the webpack docs
Is should raise as separate issues but for now...
See webpack 2 library building docs for more info
I hope these are useful
The text was updated successfully, but these errors were encountered: