build - Compile a directory tree of separate apps (one entry point each), using CommonJS modules and ES6 modules -


i writing couch app. output of build process must directory tree of self contained js files, so:

 dist ├── _attachments │   ├── logo.jpg │   └── splash.jpg ├── lists │   └── sitemap.js ├── shows │   ├── article.js │   ├── home.js │   └── dashboard.js ├── views │   ├── recent │   │   └── map.js │   ├── featured │   │   └── map.js │   └── stats │       └── map.js │       └── reduce.js 

each output js file complete app, imported modules inlined. each input file separate entry point, require / import modules top level lib directory (and node_modules or course). resulting dist directory deployed couch erica (alternatives suggestions welcome).

so far, have tried following:

  • compile babel (es7 yay!), using broccoli. produces es5 modules commonjs require statements; further build step necessary inline imported modules.
  • browserify , uglify command line. looks designed produce single output file.
  • in makefile, uglify each input separately , send output matching directory path under dist. work in progress, not ideal solution.

so, go makefiles. beautiful in exotic way, stick modern / js based build process - broccoli or gulp (or whatever). suggestions?

update

i see webpack can build multiple output files multiple entry points. can preserve input directory structure?

makefiles is. doubt work on linux dev machine. don't if publishing other people use.

what build standalone app each design doc in src tree. show docs, use react render pages in isomorphic style, weigh in @ several megabytes.

in order couchdb able execute 1 of these apps, output js must evaluate global function declaration implements relevant part of couchdb api. that, build standalone umd module, attaches output global object, if 1 exists. 1 not exist in couchdb, prepend declaration, , append expression evaluates function exported our module:

echo 'global={};' > $(build_dir)/$*.js $(build_cmd) --standalone func $(src_dir)/$*.js >> $(build_dir)/$*.js echo 'global.func;' >> $(build_dir)/$*.js 

here's whole file:

src_dir=src build_dir=build  src := $(shell find $(src_dir) -type f -print)  js := $(filter %.js, $(src:src/%=%)) static := $(filter-out $(js), $(src:src/%=%))  build_cmd=browserify -t babelify -g [ uglifyify -c -m ] build_dev_flags=--watch  all: dist  # deploy local couchdb using erica # todo: browser reload install: $(addprefix $(build_dir)/, $(js)) copy     cd $(build_dir) && erica push couchra -v  copy: $(addprefix $(build_dir)/, $(static))  # transpile js ./src ./build $(build_dir)/%.js: $(src_dir)/%.js     mkdir -p $(dir $(build_dir)/$*)     echo 'global={};' > $(build_dir)/$*.js     $(build_cmd) --standalone func $(src_dir)/$*.js >> $(build_dir)/$*.js     echo 'global.func;' >> $(build_dir)/$*.js  # copy static files ./src ./build $(static:%=$(build_dir)/%): $(static:%=$(src_dir)/%) $(build_dir)     mkdir -p $(dir $@)     cp $(@:$(build_dir)/%=$(src_dir)/%) $@  $(build_dir):     mkdir -p $(build_dir)  clean:     rm -rf $(build_dir)  .phony: clean dist 

it @ point, convert plain shell scripts , npm run them.

areas improvement:

  • exclude commonly used libs build, , use couchdb's commonjs functionality include them. should more halve size of design documents, , allow couch avoid bunch of disk reading when loading design doc handle request.
  • move rendering code out of show functions, , update filters. way, html views can created once per update, instead of on every write. each doc contain few rendered versions of in renderedviews member. show , list functions return or concatenate , return static markup, eliminate react app's execution time response time of server side rendered pages.

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -