News for hackers. Stuff that matters.
Re:Webpack 3: Official Release by elmigranto on Tuesday June 20, 2017 @04:03AM (#14592870)
Every time I start a new project, I try using latest webpack first. Result is always me getting frustrated and replacing it with simple `browserify` call with couple of `--transform` flags.

Recently I tried bootstrapping it with `create-react-app` and ejecting, so I can modify webpack config. `yarn start` kept linting something deep inside `node_modules`, and failing for some nefarious reason even after linting step was removed completely from everywhere I could reach. `build` command work fine, though, so go figure.

Not sure if "magic comments" will solve my problem, but it surely is nice to have simple alternative, thanks substack and everyone behind browserify! https://github.com/substack/node-browserify

Re:Webpack 3: Official Release by manigandham on Tuesday June 20, 2017 @04:07AM (#14592884)
webpack is just more complicated, which means it takes longer to start - it also has some bad naming and quirks which happens when design-by-committee decisions take place.

the webpack book by survivejs takes a few hours to read completely, or an hour to read the important parts, and you'll be very comfortable with it.

https://leanpub.com/survivejs-webpack or https://survivejs.com/webpack/preface/

Re:Webpack 3: Official Release by bicubic on Tuesday June 20, 2017 @04:24AM (#14592939)
> the webpack book

Holy shit, I thought you were kidding.

We're at a point where the bundler, one of a dozen elements required for a 'barebones' modern js application, needs a book.

I'm finding it hard to find motivation to do any kind of web based side projects these days because they inevitably begin with 'which combination of latest and greatest libraries do I need to spend an entire day wiring up before I can do hello world this time?'. Someone make this madness end.

Modern javascript tooling makes 90s C++ look pretty pleasant.

Re:Webpack 3: Official Release by manigandham on Tuesday June 20, 2017 @05:39AM (#14593214)
You can write a book about anything and it's also a great way to learn so not sure why that is an issue.

webpack does a lot so it requires lots of knowledge -- or you could just stick to script tags and basic minifiers built into every server side web framework at this point.

npm (or yarn) for downloading dependencies + webpack to squeeze them into a bundle makes for a very powerful combination if you need it and it takes a few mins at most to setup. Why the hyperbole if you don't understand it?

Re:Webpack 3: Official Release by bicubic on Tuesday June 20, 2017 @06:10AM (#14593330)
> takes a few mins at most to setup

Now there's hyperbole.

Let's be honest. Unless you do it for a living, at best it takes a few hours to set up boilerplate for any modern js project today.

And let's also be honest that es6 is a must today and script tags are not an option until browser es6 support is ubiquitous.

Last project I set up, grunt and browserify were the thing. You were an idiot if you weren't using them. Apparently now it's webpack and gulp. In another year it'll be some other crap. The first step to dealing with a problem is admitting there is one. I'm not sure labeling comments that highlight the problem 'hyperbole' is constructive in any way.

Re:Webpack 3: Official Release by cygned on Tuesday June 20, 2017 @06:20AM (#14593373)
I work with JavaScript and related technologies every day and I am still annoyed to setup new projects because if half a year had passed, everything seems to be different - especially in the React ecosystem (at least from my POV).
Re:Webpack 3: Official Release by kbody on Tuesday June 20, 2017 @06:55AM (#14593494)
Exactly, I think one reason why this trend hasn't stopped while most of the fellow devs I know are sick of it, is that JS attracts a lot of new devs. Being new they start developing on JS/React, but they don't have the painful experience and thus have more tolerance until they too get sick of it and try to keep things minimal, but then more new devs start which fuel the never-ending circle.

In the end it's not the new devs' fault of course, but rather the lib authors who don't treat their software as something that needs to be stable among other things.

Personally I try to KISS, but unfortunately on work I have to deal with this mess.

Re:Webpack 3: Official Release by manigandham on Tuesday June 20, 2017 @11:58AM (#14595632)
What exactly do you think the problem is? Especially since you dont have to do anything.

The webpack config is a few lines at minimum, and yes you can type it by hand in a few mins. It's just a bundler which is completely separate from the actual libraries you use.

It takes in a entry file, walks dependencies, gathers the modules together, and outputs a single bundle at the end. It works with JS by default but can handle other file types with loaders. That's it, just a big pipeline of stuff. Use plugins like babili and you can have streamlined source files that are transpiled and minified in a single step with the latest browser compatibility tables.

It's not required yet takes less than an afternoon to learn. Backend development and build steps get very complicated so why is frontend work not allowed to have complexity given the rise of sophisticated webapps today?

Re:Webpack 3: Official Release by rtpg on Tuesday June 20, 2017 @07:55AM (#14593810)
_very_ dependent on what you're using.

If you just use Typescript with some libraries, you just need to setup your tsconfig.json. Maybe a package.json to track your dependencies, or just vendor them in! The compiler even includes an incremental watch mode!

Almost all projects start off with some infrastructure. There's easier paths than others.

Re:Webpack 3: Official Release by bigleagueposter on Tuesday June 20, 2017 @06:37AM (#14593429)
Can't you just use a project starter script and get it set up in minutes?
Re:Webpack 3: Official Release by bicubic on Tuesday June 20, 2017 @07:17AM (#14593601)
Which one?

The one with webpack? 1? 2? Now 3?

What about react? And redux. And react HMR. Oh and you probably need immutable.js if you want to use react the 'proper' way not like those fools last year. Your starter script was configured with react-router? That's a shame, because it's no longer the latest and greatest, and everyone knows you should have moved on to React Mini Router. Or is it React Universal Router now? Wait is the particular configuration of webpack in this starter script even compatible with the latest and greatest babel-loader? Hang on, you wanted to use promises? Yeah, that's another plugin for polyfill and more config that interacts with most of the above. Don't worry though, there's plenty of tutorials to get it working with webpack... Oh wait, they're all for webpack v1 and you're on v2.

Re:Webpack 3: Official Release by aaron-lebo on Tuesday June 20, 2017 @07:23AM (#14593627)
So don't upgrade to the latest and greatest tech? Find something that works and use it just like anything else.

Is your complaint really that there's new tech out and you have the option to use it? Do you complain every time a new language releases? Do you use Django 1.2 because you don't feel like upgrading to 1.3, 1.5, 1.8?

I don't exaggerate in saying that the comments you've posted in this thread have taken more time than it would take to have a basic webpack setup.

Re:Webpack 3: Official Release by aaron-lebo on Tuesday June 20, 2017 @06:48AM (#14593470)
Yeah, or use git clone from a template you've setup. It's a nonsensical complaint.
Re:Webpack 3: Official Release by Sacho on Tuesday June 20, 2017 @05:18AM (#14593129)
I think your hyperbole is unwarranted; if you're building a "hello world" application, you don't need to use a bundler, or any of the "latest and greatest libraries".

Pick tools which you are comfortable with and which solve problems you actually have. Otherwise, you'll be left complaining about some vague "community" that is "forcing" you to adopt the "modern standard", even though there's nothing "standard" about the apps this "community" develops as a whole.

Re:Webpack 3: Official Release by susw on Tuesday June 20, 2017 @05:33AM (#14593196)
Hello World is only your first test case to get all the tooling up and running. The real work starts after Hello World and is expected to become more complex. Within minutes you will grow tired of manually running transpilers, minifiers, tests, adding each new js module to index.html etc. You will want to automate all of this. At least this is my experience every time I start a new project.
Re:Webpack 3: Official Release by positivecomment on Tuesday June 20, 2017 @04:39AM (#14592981)
JavaScript is trying to get rid of the script!

https://www.manning.com/books/java-development-with-ant

Re:Webpack 3: Official Release by _Codemonkeyism on Tuesday June 20, 2017 @08:07AM (#14593891)
Re:Webpack 3: Official Release by baystep on Tuesday June 20, 2017 @06:48AM (#14593471)
Have you ever tried Gulp? Honestly I had the same feeling with webpack, I like it for my "professional" day job project that's grown to huge size and webpack can chop through it quickly; but for side projects, probably not.

Then I found gulp. Uses a more functional streaming style, but for the end goal of [Turn ES6 into ES5]->[Stick it in this folder] it's dead simple and quick.

Re:Webpack 3: Official Release by Cthulhu_ on Tuesday June 20, 2017 @10:13AM (#14594766)
> Someone make this madness end.

Angular, React and Polymer are hiding the complexity of modern JS app building behind their own CLI, so it's literally down to 'angular build --prod' or 'npm run build'.

Re:Webpack 3: Official Release by owebmaster on Tuesday June 20, 2017 @06:55AM (#14593492)
If you look at Engineering books, you will find this kind of book more often than one that teaches you how to construct a dam.
Re:Webpack 3: Official Release by douche on Tuesday June 20, 2017 @07:18AM (#14593603)
It's bullshit. I'm half tempted to go back to make and just cat'ing JS files together. It was so much faster, easier, and it wasn't always constantly broken.
Re:Webpack 3: Official Release by teknologist on Tuesday June 20, 2017 @04:18AM (#14592921)
It's so horrendously complex. I can already sense the "you-dont-need-webpack" wiki page being made by some pissed off developer out there!
Re:Webpack 3: Official Release by mkohlmyr on Tuesday June 20, 2017 @06:41AM (#14593442)
It really is. Back when I was trying to get excited about learning yet another way to bundle things (YAWTBT(TM)) I attended two tech talks that concerned webpack. I really wanted to 'get it'. I left the second one having decided to never touch it again if avoidable.

The first was by a developer who had recently moved a sizable codebase to webpack. He had pages after pages of graphs of how he had tuned webpacks code splitting capabilities. The end result of all this work was actually a larger sum of file sizes - and a slower loading speed. But I guess those days / weeks of tuning shave off a few kB when they deploy minor changes.

The second talk was by one of the primary maintainers of webpack. It was completely incoherent. It was a jumble of things that "can be done with webpack" - not one good reason why. E.g. "You can extract CSS from your javascript files with this plugin" - what genius came up with the idea of inlining styles in a javascript bundle to begin with?

Re:Webpack 3: Official Release by fenomas on Tuesday June 20, 2017 @08:37AM (#14594089)
> what genius came up with the idea of inlining styles in a javascript bundle to begin with?

I do this in a project and it's terrific. The JS files in question are front-end components (for Vue.js in my case), and the point of having the styles inline is so that components can be a single file, styles can be prefixed to be local to that component, and so on. It's light-years easier to work with than trying to do something similar without a module bundler.

Re:Webpack 3: Official Release by nobleach on Tuesday June 20, 2017 @10:18AM (#14594797)
Because there are instances where one doesn't want to block rendering with large CSS file downloads? For above the fold content, inlining makes perfect sense.
Re:Webpack 3: Official Release by teknologist on Tuesday June 20, 2017 @08:56AM (#14594214)
> what genius came up with the idea of inlining styles in a javascript bundle to begin with?

All these, I guess... https://github.com/MicheleBertoli/css-in-js#features

Re:Webpack 3: Official Release by daviddumon on Tuesday June 20, 2017 @04:17AM (#14592916)
I second this recommandation. This book was really a good help setting up webpack for the first time.
Re:Webpack 3: Official Release by just-boris on Tuesday June 20, 2017 @04:05PM (#14598087)
> I tried bootstrapping it with `create-react-app` and ejecting, so I can modify webpack config

I am pretty much confident that everything worked well before you have made any modifications in the webpack config. So, the negative effects, that you are describing after, is a result of your efforts, but not anybody else.

And why did you want to eject in the first time? Most popular use-cases are already covered into create-react-app by default.

Re:Webpack 3: Official Release by teknologist on Tuesday June 20, 2017 @04:10AM (#14592894)
Would you mind posting an example of such a browserify call for someone who isn't too familiar?
Re:Webpack 3: Official Release by elmigranto on Tuesday June 20, 2017 @04:14AM (#14592910)
Here's my Makefile, which includes all the configuration: react, babel, etc. (I do not have any dotfiles in root except for linter). `watch` recompiles on changes and has sourcemaps. You can require any node modules and calls to `fs.readFileSync` will be replaced with `Buffer` objects.

    NODE_MODULES=../../node_modules
    NODE_BINARIES=${NODE_MODULES}/.bin
    
    BABEL_PRESETS=--presets [ es2017 react ]
    BABEL_PLUGINS=--plugins [ transform-object-rest-spread ]
    
    FLAGS= \
    	--transform [ babelify ${BABEL_PLUGINS} ${BABEL_PRESETS} ] \
    	--transform brfs \
    	--outfile ../../public/bundle.js \
    	entrypoint.js
    
    build:
    	${NODE_BINARIES}/browserify ${FLAGS}
    
    watch:
    	${NODE_BINARIES}/watchify --debug --verbose ${FLAGS}
What it doesn't have is any kind of automatic page reload or code swap and you can't `require` non-js files. There is also no minification for production build. I believe you can have those after couple of minutes on npm, but I haven't tried. Dependencies:

    yarn add --dev browserify watchify babelify babel-plugin-transform-object-rest-spread babel-preset-es2017 babel-preset-react brfs
Re:Webpack 3: Official Release by Yaggo on Tuesday June 20, 2017 @06:15AM (#14593352)
For minification you can use e.g. uglifyify transform. Envify also comes in handy.

I'm big fan of browserify & npm scripts, I love the simplicity.