3 ms·
Curious how you run apps when developing. Do you run "npm run-script watchify" and "npm run-script server" in two separate terminals? I always found watchify to
by lobster_johnson 12y ago
Curious how you run apps when developing. Do you run "npm run-script watchify" and "npm run-script server" in two separate terminals? I always found watchify to be an odd way to go about building assets.
In my company we use Staticr [1], a way to express generated asset bundles (Browserify, SASS or anything else) using JS.
You basically declare the endpoints; e.g.:
var endpoints = {
"/js/app.js": function() {
return browserify("app.js", {...})
.transform(babelify())
.bundle();
},
"/css/app.css": // ... similar with node-sass
};
In server.js or whatever, you simply include a check for the environment and mount the endpoints like so:
if (process.env.NODE_ENV === 'development') {
var serve = require('staticr/serve');
app.use(serve(endpoints));
}
Now whenever someone requests /js/app.js, it will be automatically built on the fly using Browserify. To speed things up (a lot!) we have a small module that keeps Browserify's cache in memory, which I can show you if you're interested.
Then, in production, you simply include the following as part of your deployment script:
staticr endpoints.js public/
It will take each endpoint, generate the output, and write the file to public/. This assumes you have a docroot, or your Node.js app has a static middleware, at public/.
Of course, Webpack gives you a more extensive toolset, but Staticr is a lot simpler.
I'm curious, do you need es5-shim when you have Babel (ie., "babel/polyfill") which uses core.js, which I believe installs most of what is needed? Actually Babel only requires "core.js/shim"; for ES5 you might need to require "core-js/es5". But it would probably be better to use one polyfill library instead of several.
[1] https://github.com/bjoerge/staticr https://github.com/bjoerge/staticr