phenomejs / phenome

The ultimate cross-framework component compiler
http://phenomejs.org
MIT License
71 stars 8 forks source link

Compiler I/O #1

Closed bencompton closed 6 years ago

bencompton commented 6 years ago

This is a first attempt at a compiler I/O API, which is for most practical purposes the top-level API of this library. This is the piece that reads in source files, calls the compiler API for each file, and then outputs the compiled files. Here is what the current prototype API looks like (feel free to suggest alternate syntax):

import { compile } from 'universal-component'

compile({
  paths: ['./src/**/*.js', './src/**/*.jsx'],
  vue: {
    out: 'dist/vue/'
  },
  react: {
    out: 'dist/react'
  }
});

The above example is what a component library's build.js file might look like. In this example, it would compile all of the component library's universal components, and then output the compiled Vue and React files into separate Vue and React directories under the dist directory. The compiled output could then be published to NPM as either separate React and Vue libraries, or as a single unified library (e.g., import {Page} from 'framework7/react/ or import {Page} from 'framework7/vue/).

I created separate component-library and app directories in the test area. The build.js file now calls the compile-io API to compile the "component library" first, and it then calls rollup to compile the Vue and React apps. The Vue and React app components import the compiled universal component, but the import path is not as clean here as it would be when importing from a component library's NPM package.

This is just a simple prototype and is certainly not complete. Here are some ideas for the future that come to mind: