Skip to content

Commit

Permalink
feat(taro-mini-runner): 优化文件生成
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Dec 26, 2019
1 parent fc02833 commit 970a494
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions packages/taro-mini-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ import * as webpack from 'webpack'
import { IBuildConfig } from './utils/types'
import { printBuildError, bindProdLogger } from './utils/logHelper'
import MiniPlugin, { Targets } from './plugins/MiniPlugin'
import { MINI_APP_FILES } from './utils/constants'
import { MINI_APP_FILES, BUILD_TYPES } from './utils/constants'

const extensions = ['.ts', '.tsx', '.js', '.jsx']

const globalObjectMap = {
[BUILD_TYPES.WEAPP]: 'wx',
[BUILD_TYPES.ALIPAY]: 'my',
[BUILD_TYPES.SWAN]: 'swan',
[BUILD_TYPES.QQ]: 'qq',
[BUILD_TYPES.TT]: 'tt'
}

export default function build (config: IBuildConfig) {
const compilePlugins = config.plugins
const { babel } = compilePlugins
Expand All @@ -18,7 +26,8 @@ export default function build (config: IBuildConfig) {
output: {
filename: '[name].js',
publicPath: '/',
path: config.outputDir,
path: config.outputDir,
globalObject: globalObjectMap[config.buildAdapter]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx']
Expand Down
4 changes: 2 additions & 2 deletions packages/taro-mini-runner/src/plugins/MiniPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import wxTransformer from '@tarojs/transformer-wx'
import * as webpack from 'webpack'
import * as SingleEntryPlugin from 'webpack/lib/SingleEntryPlugin'
import * as FunctionModulePlugin from 'webpack/lib/FunctionModulePlugin'
import * as JsonpTemplatePlugin from 'webpack/lib/web/JsonpTemplatePlugin'
import * as NodeSourcePlugin from 'webpack/lib/node/NodeSourcePlugin'
import * as LoaderTargetPlugin from 'webpack/lib/LoaderTargetPlugin'
import * as VirtualModulePlugin from 'virtual-module-webpack-plugin'
Expand All @@ -17,7 +18,6 @@ import { Config as IConfig } from '@tarojs/taro'
import { REG_TYPESCRIPT, BUILD_TYPES, PARSE_AST_TYPE, MINI_APP_FILES } from '../utils/constants'
import { traverseObjectNode, resolveScriptPath, buildUsingComponents } from '../utils'

import TaroTemplatePlugin from './TaroTemplatePlugin'
import TaroLoadChunksPlugin from './TaroLoadChunksPlugin'

interface IMiniPluginOptions {
Expand All @@ -44,7 +44,7 @@ const taroFileTypeMap: ITaroFileInfo = {}
export const createTarget = function createTarget (name) {
return (compiler: webpack.compiler.Compiler) => {
const { options } = compiler
new TaroTemplatePlugin().apply(compiler)
new JsonpTemplatePlugin().apply(compiler)
new FunctionModulePlugin(options.output).apply(compiler)
new NodeSourcePlugin(options.node).apply(compiler)
new LoaderTargetPlugin('web').apply(compiler)
Expand Down

0 comments on commit 970a494

Please sign in to comment.