Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions packages/taro-cli/src/presets/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ export default (ctx: IPluginContext) => {
isProduction = process.env.NODE_ENV === 'production' || !isWatch
}

if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
console.log(chalk.yellowBright(`tips: 设置 NODE_ENV 为 production 可以开启压缩。
example:
Mac OS:
export NODE_ENV=production
taro build --type ${platform} --watch
Windows:
set NODE_ENV=production
taro build --type ${platform} --watch
`))
}

await ctx.applyPlugins('onBuildStart')
await ctx.applyPlugins({
name: platform,
Expand Down
5 changes: 4 additions & 1 deletion packages/taro-cli/src/presets/platforms/alipay.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IPluginContext } from '@tarojs/service'
import { recursiveReplaceObjectKeys } from '../../util'

import { recursiveReplaceObjectKeys, printDevelopmentTip } from '../../util'

export default (ctx: IPluginContext) => {
ctx.registerPlatform({
Expand All @@ -10,6 +11,8 @@ export default (ctx: IPluginContext) => {
const { npm, emptyDirectory } = ctx.helper
emptyDirectory(outputPath)

printDevelopmentTip('alipay')

// 准备 miniRunner 参数
const miniRunnerOpts = {
...config,
Expand Down
5 changes: 4 additions & 1 deletion packages/taro-cli/src/presets/platforms/jd.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { IPluginContext } from '@tarojs/service'

import { printDevelopmentTip } from '../../util'

export default (ctx: IPluginContext) => {
ctx.registerPlatform({
name: 'jd',
useConfigName: 'mini',
async fn ({ config }) {
const { appPath, nodeModulesPath, outputPath } = ctx.paths
const { npm, emptyDirectory } = ctx.helper

emptyDirectory(outputPath)

printDevelopmentTip('jd')

// 生成 project.config.json
ctx.generateProjectConfig({
srcConfigName: 'project.jd.json',
Expand Down
5 changes: 4 additions & 1 deletion packages/taro-cli/src/presets/platforms/qq.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { IPluginContext } from '@tarojs/service'

import { printDevelopmentTip } from '../../util'

export default (ctx: IPluginContext) => {
ctx.registerPlatform({
name: 'qq',
useConfigName: 'mini',
async fn ({ config }) {
const { appPath, nodeModulesPath, outputPath } = ctx.paths
const { npm, emptyDirectory } = ctx.helper

emptyDirectory(outputPath)

printDevelopmentTip('qq')

// 生成 project.config.json
ctx.generateProjectConfig({
srcConfigName: 'project.qq.json',
Expand Down
4 changes: 4 additions & 0 deletions packages/taro-cli/src/presets/platforms/swan.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { IPluginContext } from '@tarojs/service'

import { printDevelopmentTip } from '../../util'

export default (ctx: IPluginContext) => {
ctx.registerPlatform({
name: 'swan',
Expand All @@ -13,6 +15,8 @@ export default (ctx: IPluginContext) => {
// platform: config.platform
// })

printDevelopmentTip('swan')

// 生成 project.swan.json
ctx.generateProjectConfig({
srcConfigName: 'project.swan.json',
Expand Down
4 changes: 4 additions & 0 deletions packages/taro-cli/src/presets/platforms/tt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { IPluginContext } from '@tarojs/service'

import { printDevelopmentTip } from '../../util'

export default (ctx: IPluginContext) => {
ctx.registerPlatform({
name: 'tt',
Expand All @@ -9,6 +11,8 @@ export default (ctx: IPluginContext) => {
const { npm, emptyDirectory } = ctx.helper
emptyDirectory(outputPath)

printDevelopmentTip('tt')

// 生成 project.config.json
ctx.generateProjectConfig({
srcConfigName: 'project.tt.json',
Expand Down
4 changes: 4 additions & 0 deletions packages/taro-cli/src/presets/platforms/weapp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { IPluginContext } from '@tarojs/service'

import { printDevelopmentTip } from '../../util'

export default (ctx: IPluginContext) => {
ctx.registerPlatform({
name: 'weapp',
Expand All @@ -9,6 +11,8 @@ export default (ctx: IPluginContext) => {
const { npm, emptyDirectory } = ctx.helper
emptyDirectory(outputPath)

printDevelopmentTip('weapp')

// 生成 project.config.json
ctx.generateProjectConfig({
srcConfigName: 'project.config.json',
Expand Down
16 changes: 16 additions & 0 deletions packages/taro-cli/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs-extra'
import * as path from 'path'
import { isWindows, chalk } from '@tarojs/helper'

export function getRootPath (): string {
return path.resolve(__dirname, '../../')
Expand Down Expand Up @@ -90,3 +91,18 @@ export function recursiveReplaceObjectKeys (obj, keyMap) {
}
})
}

export function printDevelopmentTip (platform: string) {
if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
let exampleCommand
if (isWindows) {
exampleCommand = `$ set NODE_ENV=production && taro build --type ${platform} --watch`
} else {
exampleCommand = `$ NODE_ENV=production taro build --type ${platform} --watch`
}
console.log(chalk.yellowBright(`Tips: 预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
Example:
${exampleCommand}
`))
}
}
8 changes: 4 additions & 4 deletions packages/taro-loader/src/h5.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as webpack from 'webpack'
import { getOptions, stringifyRequest } from 'loader-utils'
import { AppConfig, PageConfig } from '@tarojs/taro'
import { AppConfig } from '@tarojs/taro'
import { join, dirname } from 'path'
import { frameworkMeta } from './utils'

function genResource (path: string, pages: Map<string, PageConfig>, loaderContext: webpack.loader.LoaderContext) {
function genResource (path: string, pages: Map<string, string>, loaderContext: webpack.loader.LoaderContext) {
const stringify = (s: string): string => stringifyRequest(loaderContext, s)
return `
Object.assign({
path: '${path}',
load: function() {
return import(${stringify(join(loaderContext.context, path))})
}
}, require('${pages.get(path)}').default || {}),
}, require(${stringify(pages.get(path)!)}).default || {}),
`
}

Expand All @@ -28,7 +28,7 @@ export default function (this: webpack.loader.LoaderContext) {
execBeforeCreateWebApp
} = frameworkMeta[options.framework]
const config: AppConfig = options.config
const pages: Map<string, PageConfig> = options.pages
const pages: Map<string, string> = options.pages
let tabBarCode = `var tabbarIconPath = []
var tabbarSelectedIconPath = []
`
Expand Down
8 changes: 6 additions & 2 deletions packages/taro-runtime/src/dsl/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ export function createPageConfig (component: any, pageName?: string, data?: Reco
}

// onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
if (component.onShareAppMessage || component.enableShareAppMessage) {
if (component.onShareAppMessage ||
component.prototype.onShareAppMessage ||
component.enableShareAppMessage) {
config.onShareAppMessage = function (options) {
const target = options.target
if (target != null) {
Expand All @@ -228,7 +230,9 @@ export function createPageConfig (component: any, pageName?: string, data?: Reco
return safeExecute(path, 'onShareAppMessage', options)
}
}
if (component.onShareTimeline || component.enableShareTimeline) {
if (component.onShareTimeline ||
component.prototype.onShareTimeline ||
component.enableShareTimeline) {
config.onShareTimeline = function () {
const path = getPath(id, this.options)
return safeExecute(path, 'onShareTimeline')
Expand Down