From 8578d17ef1900eac9ba4e6b21c00ad77bd24a21a Mon Sep 17 00:00:00 2001 From: luckyadam Date: Tue, 25 Jun 2019 17:31:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(taro-cli):=20=E8=B0=83=E6=95=B4=20rn=20?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/plugin.ts | 4 ++-- packages/taro-cli/src/rn.ts | 30 +++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/taro-cli/src/plugin.ts b/packages/taro-cli/src/plugin.ts index 6bcae14f9d2f..6417060322c2 100644 --- a/packages/taro-cli/src/plugin.ts +++ b/packages/taro-cli/src/plugin.ts @@ -35,7 +35,7 @@ import { import { buildDepComponents, buildSingleComponent, getComponentsNamedMap } from './mini/component' import { compileDepScripts, initCompileScripts } from './mini/compileScript' import { compileDepStyles, initCompileStyles } from './mini/compileStyle' -import { IBuildConfig } from './util/types' +import { IBuildOptions } from './util/types' const PLUGIN_ROOT = 'plugin/' const DOC_ROOT = 'doc/' @@ -45,7 +45,7 @@ const PLUGIN_MOCK_JSON = 'plugin-mock.json' let isCopyingFiles = {} -export async function build (appPath: string, { watch, platform }: IBuildConfig) { +export async function build (appPath: string, { watch, platform }: IBuildOptions) { switch (platform) { case BUILD_TYPES.WEAPP: buildWxPlugin(appPath, { watch }) diff --git a/packages/taro-cli/src/rn.ts b/packages/taro-cli/src/rn.ts index 158da7e2ebd6..c0a1b618d838 100644 --- a/packages/taro-cli/src/rn.ts +++ b/packages/taro-cli/src/rn.ts @@ -6,6 +6,7 @@ import * as chokidar from 'chokidar' import chalk from 'chalk' import * as _ from 'lodash' import * as klaw from 'klaw' +import { TogglableOptions, ICommonPlugin, IOption } from '@tarojs/taro/types/compile' import * as Util from './util' import CONFIG from './config' @@ -13,7 +14,7 @@ import * as StyleProcess from './rn/styleProcess' import { parseJSCode as transformJSCode } from './rn/transformJS' import { PROJECT_CONFIG, processTypeEnum, REG_STYLE, REG_SCRIPTS, REG_TYPESCRIPT, BUILD_TYPES } from './util/constants' import { convertToJDReact } from './jdreact/convert_to_jdreact' -import { IBuildConfig } from './util/types' +import { IBuildOptions } from './util/types' // import { Error } from 'tslint/lib/error' let isBuildingStyles = {} @@ -44,7 +45,13 @@ class Compiler { entryFilePath: string entryFileName: string entryBaseName: string - pluginsConfig + babel: TogglableOptions + csso: TogglableOptions + uglify: TogglableOptions + sass: IOption + less: IOption + stylus: IOption + plugins: ICommonPlugin[] rnConfig hasJDReactOutput: boolean babelConfig: any @@ -59,7 +66,13 @@ class Compiler { this.entryFilePath = Util.resolveScriptPath(path.join(this.sourceDir, CONFIG.ENTRY)) this.entryFileName = path.basename(this.entryFilePath) this.entryBaseName = path.basename(this.entryFilePath, path.extname(this.entryFileName)) - this.pluginsConfig = this.projectConfig.plugins || {} + this.babel = this.projectConfig.babel + this.csso = this.projectConfig.csso + this.uglify = this.projectConfig.uglify + this.plugins = this.projectConfig.plugins + this.sass = this.projectConfig.sass + this.stylus = this.projectConfig.stylus + this.less = this.projectConfig.less this.rnConfig = this.projectConfig.rn || {} this.babelConfig = this.projectConfig.plugins.babel // 用来配置 babel @@ -89,7 +102,14 @@ class Compiler { const filePath = path.join(p) const fileExt = path.extname(filePath) Util.printLog(processTypeEnum.COMPILE, _.camelCase(fileExt).toUpperCase(), filePath) - return StyleProcess.loadStyle({filePath, pluginsConfig: this.pluginsConfig}, this.appPath) + return StyleProcess.loadStyle({ + filePath, + pluginsConfig: { + sass: this.sass, + less: this.less, + stylus: this.stylus + } + }, this.appPath) })).then(resList => { // postcss return Promise.all(resList.map(item => { return StyleProcess.postCSS({...item as { css: string, filePath: string }, projectConfig: this.projectConfig}) @@ -345,7 +365,7 @@ function installDep (path: string) { export { Compiler } -export async function build (appPath: string, buildConfig: IBuildConfig) { +export async function build (appPath: string, buildConfig: IBuildOptions) { const { watch } = buildConfig process.env.TARO_ENV = BUILD_TYPES.RN await Util.checkCliAndFrameworkVersion(appPath, BUILD_TYPES.RN)