5 ms·
I don't (think I) have much of a problem with JS syntax, generally speaking, but I'm often baffled by the surrounding ecosystem of build tools and "helpers". Th
by toyg 6y ago
I don't (think I) have much of a problem with JS syntax, generally speaking, but I'm often baffled by the surrounding ecosystem of build tools and "helpers". There are a million tutorials, all doing things slightly differently without really explaining why, and stuff breaks so often...
Any recommendation for something covering that sort of thing (npm, yarn, webpack...) in a more structured and in-depth way than "here's how to make a todo list in 10 minutes with some magical command that may or may not still work 3 months later"?
- m0ck 6y agoAs a backend developer getting his foot into frontend I feel you. Configuring TSLint with Prettier and all the plugins was tiresome only to learn few months later it's getting deprecated and you should move to ESlint. This article helped me bit, it explains "what is what" in modern JS ecosystem https://medium.com/the-node-js-collection/modern-javascript-explained-for-dinosaurs-f695e9747b70 https://medium.com/the-node-js-collection/modern-javascript-...
- Uberphallus 6y agoExcellent article, I just hope that's kind of stable... every time I look into the JS it feels like I've never looked into JS before.
- harrygeez 6y agoIt's quite simple actually. With native modules support you don't really need any of these helpers. However, if you're concerned about users on older browsers, you can use Babel to "transpile" your code to equivalent code that older browsers can understand, often at the expense of size. npm and yarn are simply 2 competing implementation for package management. Start with npm and you'll know it when you want yarn. Webpack and other module bundlers are just tools to automate things like transpiling, code-transformation, bundle-splitting, minification which are not all that essential actually. The point is all of these are extras. Think of them as enhancements/optimizations. If you have a solid understanding of JS you can write JS in a way that doesn't require any of this. I blame the tutorials out there that say you need this and that without many justifications that make it seem more complicated than it is.
- rikroots 6y ago> Webpack and other module bundlers are just tools to automate things like transpiling, code-transformation, bundle-splitting, minification which are not all that essential actually. I wish this were true. My experience to illustrate the point: I have a Javascript library[1] for working with the HTML5 <canvas> element. It's a nice library (in my opinion) but it is a bit on the large side. Also, I developed it as something that can be added to a website in the old-fashioned way, using a <script> tag. However, most non-personal websites these days are built with toolchains which include code bundlers like Webpack (many React sites), Rollup (Svelte sites), Packet etc. Developers working on those sites don't want to add a <script> tag to their HTML file; they want all their Javascript npm-included or yarn-added so it can be shaken and bundled and tied up in ribbons and bows for delivery to the user's browser or device. So I did the work of turning my library into an NPM package and tried building a toy project with a toolchain. The failure was embarrassing. It turns out that I was using a JS feature in my library code which isn't supported by any of the main bundlers (`import.meta`, for the curious[2]. I raised a ticket with one of the bundlers to see if they could add support in a future release[3] but it seems the feature is too obscure to care about.) I sorted the problem by rewriting my library (in a very unsatisfactory, ugly way) to get bundlers to bundle the code. Now people can add my library to their React/Svelte/whatever project. But the whole learning episode left a bad taste in my mouth: Being tripped up by Vanilla JS is one thing; having your work trashed by the bundlers in the toolchain is just nasty! [1] - https://scrawl-v8.rikweb.org.uk/ https://scrawl-v8.rikweb.org.uk/ [2] - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... [3] - https://github.com/parcel-bundler/parcel/issues/3269 https://github.com/parcel-bundler/parcel/issues/3269
- tyingq 6y agoI sympathize with this. I wanted to use, and slightly modify, a small web app I found on GitHub. Despite it being client-side only, it used node. An older version, with older versions of webpack, Babel, and so on. And tons of now deprecated npm packages. It was only a couple of years old. The only way I could make it work, after days of trying, was a docker container of an older Linux distro. I did try just upgrading packages, but the avalanche of dependency hell made that literally impossible. I have not had this experience with any other language. Edit: Noting I have had to update/upgrade older Perl, Python, etc, projects. And they weren't all easy. But they were at least possible. Dozens of things to chase down. Not hundreds.
- r_police 6y agoYeah, because package-lock.json files were never a thing.
- greggman3 6y agoI've had the opposite experience trying to get python and/or ruby not to trash my global environment and various things wanting the system to be setup for their versions and libraries. I like that NPM by default makes all dependencies local and npm lets you include your dev dependencies local to that project. Note: I know their are magic incantations for python and ruby to get them to make everything project local but they aren't what python and ruby do by default.
- cercatrova 6y agoI'd recommend the Webpack tutorial by Andrew Mead, interestingly enough. It goes through all these tools and why they're needed, and you build out a simple config with Webpack and understand exactly what it does and why.
- scruple 6y agoI'm interested in checking this tutorial out but I can't locale it anywhere. Got any links?
- cercatrova 6y agohttps://www.youtube.com/playlist?list=PLblA84xge2_zwxh3XJqy6UVxS60YdusY8 https://www.youtube.com/playlist?list=PLblA84xge2_zwxh3XJqy6... Looks like I misremembered, it's actually by Colt Steele.
- scruple 6y agoThank you!
- cercatrova 6y agoWhat do you think of it?
- scruple 6y agoI really like it, actually. I finally had a free hour this afternoon to start getting into it. I'm only on video 6 so far but I've already learned quite a few things that I had missed and/or misunderstood previously. I've also sent it out to my team so that they can check it out next week, after the holidays, (and during work hours) to fill in some of the gaps they may have, as well. Thanks again for mentioning it and linking it!
- IshKebab 6y agoI agree. Even just finding out what the tools are is ridiculously hard. Here's a list: * NPM: Package / dependency manager. Also has some basic support for running scripts. * Yarn: Very similar alternative to NPM. * Babel: Transpiles modern Javascript to "old" Javascript, in case you need to support IE9 but want to use async/await or whatever. If you only support modern browsers you don't need this. * Webpack: Originally it was for "bundling" Javascript files. You don't want to write all your code in a single file, but you often want to deliver it that way. Webpack reads the 'import' statements of all your files, and them converts them into a single file with emulated modules. Also helps when you are targeting a browser that doesn't support modules natively. However Webpack also comes with a load of "loaders" that can transform input files in various ways, e.g. allowing importing CSS files from Javascript, compiling Typescript, etc. So now it is kind of a big ugly build system. * Node: The Javascript engine extracted from Chrome, plus a load of native APIs that let you do stuff you can't do in the browser because of security (write files, make TCP connections, etc). * Electron: Basically Chrome plus Node. You can set it up so that your web pages can access the Node APIs inside Chrome, but you can also have them talk to an actual Node process via IPC.
- e12e 6y agoA little npm actually goes quite a long way: https://www.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/ https://www.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool... https://github.com/keithamus/npm-scripts-example https://github.com/keithamus/npm-scripts-example Although you should probably prefer yarn these days (concepts should mostly transfer over). As for tranformations/transpiling/minifying... You could use webpack - it is popular, but quite complex. I've found this a decent introduction to understand how it works: https://www.freecodecamp.org/news/creating-a-production-ready-webpack-4-config-from-scratch/ https://www.freecodecamp.org/news/creating-a-production-read... The good part about going that route, is that is quite explicit... You might get away with throwing out explicit in favour of convention - by using parcel instead: https://github.com/parcel-bundler/parcel https://github.com/parcel-bundler/parcel (looks like gh readme is currently best entry point for 2.0 docs).
- IshKebab 6y ago
- mrpotato 6y agoYeah, I'm in the same boat, I'm still struggling to figure out how to write a library in typescript and then use it as a browser library. I have a feeling that I just need a better understanding of the core concepts (modules, bundlers, etc..)
- brlewis 6y agoIt's good to understand modules well. Understanding bundlers is less important and can be postponed. Just use let parcel do the transpiling and bundling for browsers.
- tomlagier 6y agoMy honest opinion is that you should read the npm-cli docs[0], the babel docs[1] and the webpack docs[2]. I think that most tutorials want to skip to the "getting stuff done" bit, and learning these tools with a bit of granularity is well worth it for any serious Javascript project. These three tools form the backbone of most modern Javascript projects. Understanding what they are, why they do what they do, and how to extend them is vital to being able to work with modern JS. The docs, particularly the introductions are written for a fairly inexperienced audience and I find them easy to work with. [0] https://docs.npmjs.com/cli/npm https://docs.npmjs.com/cli/npm [1] https://babeljs.io/docs/en/ https://babeljs.io/docs/en/ [2] https://webpack.js.org/concepts/ https://webpack.js.org/concepts/