@hyext/compile
v1.0.61
Published
A compiler for hyminapp, it can compile any files to any where by strategy you use.
Downloads
26
Readme
hyext-compile
A compiler for hyminapp, it can compile any files to any where by strategy you use.
Installation
npm install --save-dev @hyext/compileModules
compile.feature
transformCss2Js(code), transform the css code to js code, return transformed codetransformStylesheet(code), replace jsx className to Styleheet, return transformed code
compile.strategy it is internal strategy used by Compiler
transformStylea strategy for miniapp code to rn code, if you want design own strategy, you should follow as appoint
interface BeProcessFile = {
contents: Buffer,
}
// process file of special ext
function compileProcessFn(file: BeProcessFile, filePath:String) {
return new Promise((resolve) => {
let code = file.contents.toString()
let processedCode = transform(code) // the transform fn of you design
file.contents = Buffer.from(processedCode)
resolve(file)
})
}
interface ProcssStrategy = {
fileExtName:(js|jsx|css|...): fn
}
const strategy:ProcssStrategy = { js: compileProcessFn }- compile.Compiler The constructor of compiler, it can compile file from local to other place, and offer hot replace.
- constructor(type, compileStrategy)
typestring, the type of compilercompileStrategyobject, the compilestrategy
- instance
compiler.assets(from, to)the files be processed from raw place to other placefromfile path (absolute)tofile path (absolute or relative)
compiler.watch()watch raw files change, and imediately compile to distination, you should call it after call compiler.assets.compiler.compile(file, filePath)compile single file, and return modified file obj
- constructor(type, compileStrategy)
interface ProcessFile = {
contents: Buffer,
}
compiler.compile(file: ProcessFile, filePath: String): ProcessFile