Skip to content

Commit

Permalink
feat(mini-runner): 增加 Taro 模块专有处理插件
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jan 7, 2020
1 parent 2ecfc68 commit 5be50b0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PARSE_AST_TYPE } from '../utils/constants'
export default class TaroSingleEntryDependency extends ModuleDependency {
name: string
miniType: PARSE_AST_TYPE
loc: any
constructor (request, name, loc, miniType) {
super(request)
this.name = name
Expand Down
6 changes: 2 additions & 4 deletions packages/taro-mini-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ export default function build (config: IBuildConfig) {
designWidth: config.designWidth,
deviceRatio: config.deviceRatio,
buildAdapter: config.buildAdapter,
constantsReplaceList: config.constantsReplaceList,
fileTypeMap: MiniPlugin.getTaroFileTypeMap()
constantsReplaceList: config.constantsReplaceList
}
}, {
loader: path.resolve(__dirname, './loaders/wxTransformerLoader'),
options: {
buildAdapter: config.buildAdapter,
fileTypeMap: MiniPlugin.getTaroFileTypeMap()
buildAdapter: config.buildAdapter
}
}]
},
Expand Down
36 changes: 4 additions & 32 deletions packages/taro-mini-runner/src/plugins/MiniPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as fs from 'fs-extra'

import wxTransformer from '@tarojs/transformer-wx'
import * as webpack from 'webpack'
import * as SingleEntryPlugin from 'webpack/lib/SingleEntryPlugin'
import * as SingleEntryDependency from 'webpack/lib/dependencies/SingleEntryDependency'
import * as FunctionModulePlugin from 'webpack/lib/FunctionModulePlugin'
import * as JsonpTemplatePlugin from 'webpack/lib/web/JsonpTemplatePlugin'
import * as NodeSourcePlugin from 'webpack/lib/node/NodeSourcePlugin'
Expand All @@ -22,7 +22,6 @@ import TaroSingleEntryDependency from '../dependencies/TaroSingleEntryDependency

import TaroLoadChunksPlugin from './TaroLoadChunksPlugin'
import TaroNormalModulesPlugin from './TaroNormalModulesPlugin'
import ResolverPlugin from './ResolverPlugin'

interface IMiniPluginOptions {
appEntry?: string,
Expand Down Expand Up @@ -143,7 +142,7 @@ export default class MiniPlugin {

apply (compiler: webpack.Compiler) {
this.context = compiler.context

this.appEntry = this.getAppEntry(compiler)
compiler.hooks.run.tapAsync(
PLUGIN_NAME,
this.tryAsync(async (compiler: webpack.Compiler) => {
Expand All @@ -152,15 +151,8 @@ export default class MiniPlugin {
)

compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation, { normalModuleFactory }) => {
compilation.dependencyFactories.set(SingleEntryDependency, normalModuleFactory)
compilation.dependencyFactories.set(TaroSingleEntryDependency, normalModuleFactory)
// compilation.hooks.afterOptimizeChunks.tap(PLUGIN_NAME, (modules) => {
// console.log(modules)
// // modules.forEach(mod => {
// // console.log(mod.name)
// // console.log(mod._source.source())
// // })
// // callback()
// })
})

compiler.hooks.emit.tapAsync(
Expand All @@ -170,26 +162,6 @@ export default class MiniPlugin {
})
)

// compiler.resolverFactory.hooks.resolver.for('normal').tap(PLUGIN_NAME, resolver => {
// console.log('sdsdsdsdsd')
// new ResolverPlugin('resolve', 'parsedResolve').apply(resolver)
// })
// compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, nmf => {
// nmf.hooks.afterResolve.tapAsync(PLUGIN_NAME, (result, callback) => {
// // console.log(result)
// if (result.resource.indexOf('node_modules') >= 0) {
// const issuerArr = result.resource.split(path.sep)
// const lastNodeModulesIndex = issuerArr.lastIndexOf('node_modules')
// const pkgName = result.resourceResolveData.descriptionFileData.name
// issuerArr.splice(lastNodeModulesIndex + 1, pkgName.split('/').length, pkgName.replace(/\//g, path.sep))
// const newIssuer = issuerArr.join(path.sep)
// result.userRequest = newIssuer
// result.resource = newIssuer
// }
// return callback(null, result)
// })
// })

new TaroLoadChunksPlugin({
commonChunks: this.options.commonChunks,
taroFileTypeMap
Expand All @@ -214,6 +186,7 @@ export default class MiniPlugin {
}
const appEntryPath = getEntryPath(entry)
this.sourceDir = path.dirname(appEntryPath)
compiler.options.entry = {}
return appEntryPath
}

Expand Down Expand Up @@ -493,7 +466,6 @@ export default class MiniPlugin {
}

run (compiler: webpack.Compiler) {
this.appEntry = this.getAppEntry(compiler)
this.getPages()
this.getComponents(this.pages, true)
this.addEntries(compiler)
Expand Down
28 changes: 0 additions & 28 deletions packages/taro-mini-runner/src/plugins/ResolverPlugin.ts

This file was deleted.

0 comments on commit 5be50b0

Please sign in to comment.