Skip to content

Commit

Permalink
feat(taro-cli): 调整 rn 编译配置
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Dec 31, 2019
1 parent 0b47af5 commit 8578d17
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/taro-cli/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand All @@ -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 })
Expand Down
30 changes: 25 additions & 5 deletions packages/taro-cli/src/rn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ 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'
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 = {}
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8578d17

Please sign in to comment.