squirrellyjs / squirrelly

Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺
https://squirrelly.js.org
MIT License
634 stars 83 forks source link

Improve tooling #121

Closed clitetailor closed 5 years ago

clitetailor commented 5 years ago

Summary

Changes in this PR:

Add files field to package.json

This way we can add lib and dist folder to .gitignore. If you wonder whether npm packaging works correctly, you can use npm pack to test.

Support commonjs

This includes changing the main field inside package.json and using gulp alongside rollup (you can use module field to support esm also).

While we can just build a umd file for multi-target platforms, commonjs is preferred for using in node because of the following reasons.

Also, we still need to keep umd format for the use with CDNs or directly include script tag in JS Bin or Codepen, etc.

This guildelines were examined from popular repositories like rxjs or babel and also from npm documentation and some other Medium articles.

Add @babel/register

This adds consistency improvement to source code by using esm in both src folder and test folder. You no longer need to use const something = require('something') in your source code.

Whenever you want to run an esm file directly via Node CLI, you can use node -r @babel/register <file> instead.

Add core-js and regenerator-runtime

@babel/register need this, this may also polyfill for old browser but whether this is good practice in node is unknown yet (this may polyfill old version of node but it may also increase the bundle size. notice that, the bundle size may not be a problem if the end-user use the same version of core-js).

Add .babelrc

For convenient when sharing configuration between editors and build tools.

Add .editorconfig

standard only runs when we build or we format project using command line. .editorconfig will add consistency between different editors and improve editing experience.

Use terser instead of uglifyjs

terser is more recommended for working with ES6+ and is more preferred over uglifyjs as i known.

clitetailor commented 5 years ago

Also i have one question, why don't we use let and const instead of var?

nebrelbug commented 5 years ago

Hi @clitetailor! Though I appreciate the contribution, I'd prefer to keep /dist viewable from GitHub, and I do want to keep Squirrelly with 0 dependencies.

I love your ideas about better bundling for module formats like ejs and cjs -- I'll try and make those changes soon.

I do like the idea of adding a .editorConfig and switching to Terser, though. Any chance you could create a pull request with only those 2 changes?

Thanks for the ideas!

nebrelbug commented 5 years ago

Also i have one question, why don't we use let and const instead of var?

For now, I want to keep Squirrelly completely ES5 compliant, and using Babel to transpile often leads to increased bundle size.

Thanks for the suggestion though!

clitetailor commented 5 years ago

Oh, terser already in the master branch. I will make another PR that update .editorconfig only. I will keep this branch in case you need a reference! 😃