import * as webpack from 'webpack' ; import { getOptions , stringifyRequest } from 'loader-utils' ; import { normalizePath } from '@tarojs/helper' ; import * as path from 'path' ; export default function ( this ) { const options = getOptions ( this ) ; const stringify = ( s ) : string => stringifyRequest ( this , s ) ; const { isNeedRawLoader } = options . loaderMeta ; const raw = path . join ( __dirname , 'raw.js' ) ; const loaders = this . loaders ; const thisLoaderIndex = loaders . findIndex ( item => normalizePath ( item . path ) . indexOf ( '@tarojs/taro-loader/lib/component' ) >= 0 ) ; const componentPath = isNeedRawLoader ? `${ raw }!${ this . resourcePath }` : this . request . split ( '!' ) . slice ( thisLoaderIndex + 1 ) . join ( '!' ) ; const { globalObject } = this . _compilation . outputOptions ; const prerender = `
if (typeof PRERENDER !== 'undefined') {
  ${ globalObject }._prerender = inst
}` ; return `import { createComponentConfig } from '@tarojs/runtime'
import component from ${ stringify ( componentPath ) }
var inst = Component(createComponentConfig(component, '${ options . name }'))
${ options . prerender ? prerender : '' }
` ; }