How to use the @dcloudio/uni-cli-shared.removeExt function in @dcloudio/uni-cli-shared

To help you get started, we’ve selected a few @dcloudio/uni-cli-shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dcloudio / uni-app / packages / webpack-uni-mp-loader / lib / template.js View on Github external
module.exports = function (content) {
  if (process.env.UNI_USING_COMPONENTS) {
    return require('./template-new').call(this, content)
  }
  this.cacheable && this.cacheable()

  const realResourcePath = path.relative(process.env.UNI_INPUT_DIR, this.resourcePath)

  if (process.env.UNI_USING_COMPONENTS) {
    // 向 uni-template-compier 传递 emitFile
    const vueLoaderOptions = this.loaders[0]
    if (vueLoaderOptions.ident === 'vue-loader-options') {
      Object.assign(vueLoaderOptions.options.compilerOptions, {
        resourcePath: removeExt(realResourcePath) + templateExt,
        emitFile: this.emitFile
      })
    } else {
      throw new Error('vue-loader-options parse error')
    }
  } else {
    if (!content.trim()) {
      content = ''
    }

    cacheTemplate(realResourcePath, content)

    const query = qs.parse(this.resourceQuery.slice(1))

    const {
      id
github dcloudio / uni-app / packages / webpack-uni-mp-loader / lib / plugin / generate-component.js View on Github external
Object.keys(assets).forEach(name => {
      if (components.has(name.replace('.js', ''))) {
        const chunkName = name.replace('.js', '-create-component')

        let moduleId = ''
        if (name.indexOf('node-modules') === 0) {
          const modulePath = removeExt(restoreNodeModules(name))
          const resource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, '..', modulePath))
          const altResource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, modulePath))
          moduleId = findComponentModuleId(modules, concatenatedModules, resource, altResource)
        } else {
          const resource = removeExt(path.resolve(process.env.UNI_INPUT_DIR, name))
          moduleId = findComponentModuleId(modules, concatenatedModules, resource)
        }

        const origSource = assets[name].source()
        if (origSource.length !== `Component({})`.length) { // 不是空组件
          const globalVar = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'global'
          // 主要是为了解决支付宝旧版本, Component 方法只在组件 js 里有,需要挂在 my.defineComponent
          let beforeCode = ''
          if (process.env.UNI_PLATFORM === 'mp-alipay') {
            beforeCode = ';my.defineComponent || (my.defineComponent = Component);'
          }
github dcloudio / uni-app / packages / webpack-uni-mp-loader / lib / plugin / generate-component.js View on Github external
Object.keys(assets).forEach(name => {
      if (components.has(name.replace('.js', ''))) {
        const chunkName = name.replace('.js', '-create-component')

        let moduleId = ''
        if (name.indexOf('node-modules') === 0) {
          const modulePath = removeExt(restoreNodeModules(name))
          const resource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, '..', modulePath))
          const altResource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, modulePath))
          moduleId = findComponentModuleId(modules, concatenatedModules, resource, altResource)
        } else {
          const resource = removeExt(path.resolve(process.env.UNI_INPUT_DIR, name))
          moduleId = findComponentModuleId(modules, concatenatedModules, resource)
        }

        const origSource = assets[name].source()
        if (origSource.length !== `Component({})`.length) { // 不是空组件
          const globalVar = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'global'
          // 主要是为了解决支付宝旧版本, Component 方法只在组件 js 里有,需要挂在 my.defineComponent
          let beforeCode = ''
          if (process.env.UNI_PLATFORM === 'mp-alipay') {
            beforeCode = ';my.defineComponent || (my.defineComponent = Component);'
          }
          const source = beforeCode + origSource +
            `
;(${globalVar}["webpackJsonp"] = ${globalVar}["webpackJsonp"] || []).push([
    '${chunkName}',
    {
github dcloudio / uni-app / packages / webpack-uni-mp-loader / lib / template-new.js View on Github external
module.exports = function (content) {
  this.cacheable && this.cacheable()

  const vueLoaderOptions = this.loaders[0]
  if (vueLoaderOptions.ident === 'vue-loader-options') {
    const globalUsingComponents = getGlobalUsingComponents()
    const realResourcePath = path.relative(process.env.UNI_INPUT_DIR, this.resourcePath)
    const resourcePath = normalizeNodeModules(removeExt(realResourcePath) + templateExt)
    const wxComponents = getWXComponents(resourcePath.replace(path.extname(resourcePath), ''))

    const params = loaderUtils.parseQuery(this.resourceQuery)
    /* eslint-disable no-mixed-operators */
    const filterModules = JSON.parse(params && params['filter-modules'] || '{}')
    Object.assign(vueLoaderOptions.options.compilerOptions, {
      mp: {
        platform: process.env.UNI_PLATFORM
      },
      filterModules,
      filterTagName,
      resourcePath,
      emitFile: this.emitFile,
      wxComponents,
      getJsonFile,
      getShadowTemplate,
github dcloudio / uni-app / packages / vue-cli-plugin-uni / packages / webpack-uni-app-loader / using-components.js View on Github external
module.exports = function(content, map) {
  this.cacheable && this.cacheable()
  const resourcePath = removeExt(
    normalizePath(path.relative(process.env.UNI_INPUT_DIR, this.resourcePath))
  )
  content = content + getUsingComponentsCode(resourcePath)
  // TODO 自动导入 vue 组件(h5,小程序,app[vue,nvue])
  // 1. 需要 template-loader 解析出所有自定义组件()
  // 2. 根据自定义组件信息生成引用代码
  // 3. node-modules中的组件不提供自动导入
  return content
}
github dcloudio / uni-app / packages / webpack-uni-mp-loader / lib / plugin / generate-component.js View on Github external
module => {
      let moduleResource = module.resource
      if (
        !moduleResource ||
        (
          moduleResource.indexOf('.vue') === -1 &&
          moduleResource.indexOf('.nvue') === -1
        )
      ) {
        return
      }
      moduleResource = removeExt(module.resource)
      return moduleResource === resource || moduleResource === altResource
    }
  )
github dcloudio / uni-app / packages / webpack-uni-mp-loader / lib / shared.js View on Github external
cacheCompilerOptions (name, options = {}) {
    name = removeExt(name)
    compilerOptions[name] = Object.assign(compilerOptions[name] || {}, options)
  },
  cacheCompiledComponentTemplates (name, options) {
github dcloudio / uni-app / packages / webpack-uni-mp-loader / lib / shared.js View on Github external
cacheTemplate (name, content) {
    templates[removeExt(name)] = content
  },
  cacheCompilerOptions (name, options = {}) {