GVKun编程网logo

webpack.base.conf配置中resolve.extensions和resolve.alias用法(webpack resolve.alias)

15

在本文中,我们将为您详细介绍webpack.base.conf配置中resolve.extensions和resolve.alias用法的相关知识,并且为您解答关于webpackresolve.ali

在本文中,我们将为您详细介绍webpack.base.conf配置中resolve.extensions和resolve.alias用法的相关知识,并且为您解答关于webpack resolve.alias的疑问,此外,我们还会提供一些关于.net – Control.ResolveUrl与Control.ResolveClientUrl对比VirtualPathUtility.ToAbsolute、.OpenApiExtensionResolver'' that could not be found.、android-contentresolver – ContentResolver用法、Atom js-hyperclick 支持自定义路径(webpack resolve alias)的有用信息。

本文目录一览:

webpack.base.conf配置中resolve.extensions和resolve.alias用法(webpack resolve.alias)

webpack.base.conf配置中resolve.extensions和resolve.alias用法(webpack resolve.alias)

const path = require(''path'')
function resolve (dir) {
  return path.join(__dirname, ''..'', dir)
}
module.exports = {
  resolve: {
    extensions: [''.js'', ''.vue'', ''.json''],
    alias: {
      ''vue$'': ''vue/dist/vue.esm.js'',
      ''@'': resolve(''src''),
    }
  },
}

1. resolve.extensions 

在webpack.base.conf.js中,我们可以看到resolve配置,其中的extengsions是一个数组,如下所示:

extensions: [''.js'', ''.vue'', ''.json''],

  通过这样的配置,我们在组件中过着路由中应用组件时,就可以更为方便的应用,比如:

import Hello from ''@components/Hello'';

  即Hello.vue这个组件我们不需要添加.vue后缀就可以引用到了,如果不用extensions, 我们就必须要用@components/Hello.vue来引入这个文件。 

2. resolve.alias

在组件之间相互引用时,可能是下面这样的:

import Hello from ''../src.components/Hello'';

  其中的路径是相对于当前页面的。 但是如果嵌套等更为复杂,那么写起来会比较麻烦。但是如果我们通过这样的配置:

复制代码
resolve: {
    extensions: [''.js'', ''.vue'', ''.json''],
    alias: {
      ''vue$'': ''vue/dist/vue.esm.js'',
      ''@pages'': path.join(__dirname, "..", "src", "pages"),
      "@components": path.join(__dirname, "..", "src", "components"),
      // 注意: 静态资源通过src,不能这么设置。
      // "@assets": path.join(__dirname, "..", "src", "assets"),
    }
复制代码

  其中vue$表示引入vue,就可以像下面这么写:

import Vue from ''vue''

  另外,对于@pages和@components我们就可以直接引用了,而省去了一大堆的复杂应用,另外通过@可以消除歧义。如下所示:

import Hello from ''@components/Hello'';
import App from ''@pages/App''

  值得注意的时: 在webpack.config.js中我们不能使用../ 以及./这种形式的路径方式,而是通过 path.join 和 __dirname 这种形式来表示路径,否则会报错。

  另外: 在组件中,我们会引用一些静态文件,即static下的文件, 这时我们就不能用 alias 下的配置了,而必须使用一般的配置方式。

 

vue路径优化之resolve       https://www.cnblogs.com/zhuzhenwei918/p/6870322.html

 

.net – Control.ResolveUrl与Control.ResolveClientUrl对比VirtualPathUtility.ToAbsolute

.net – Control.ResolveUrl与Control.ResolveClientUrl对比VirtualPathUtility.ToAbsolute

在解析以波浪号(〜)开头的路径时,是否有任何有益的方法来使用其中一种方法?

一般来说,什么是更好的做法,你应该在你的html中发送相对路径或绝对路径?

解决方法

ResolveUrl和ResolveClientUrl之间的区别是ResolveClientUrl返回相对于当前页面的路径,ResolveUrl返回相对于站点根目录的路径:

http://www.andornot.com/blog/post/ResolveUrl-vs-ResolveClientUrl.aspx

我建议使用绝对路径。

编辑:Rick Strahl发表了一个很好的文章

Edit2:删除了关于缓存的位。不添加到答案,可能不一定准确。

http://west-wind.com/weblog/posts/132081.aspx

.OpenApiExtensionResolver'' that could not be found.

.OpenApiExtensionResolver'' that could not be found.

启动失败,错误信息:,

Parameter 0 of constructor in com.simshine.config.SwaggerConfiguration required a bean of type ''com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver'' that could not be found.

Action:

Consider defining a bean of type ''com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver'' in your configuration.

 

配置文件:

import com.fasterxml.classmate.TypeResolver;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import com.simshine.model.configuration.SwaggerModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.WildcardType;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import static springfox.documentation.schema.AlternateTypeRules.newRule;

@Configuration
//@EnableSwagger2WebMvc
@EnableSwagger2
@EnableKnife4j
/**
 * @ClassName Swagger2Config
 * @Author htz
 * @Description swagger2配置
 * @Data 2019-04-09
 * @Version 1.0.0
 **/
public class SwaggerConfiguration {
    private final OpenApiExtensionResolver openApiExtensionResolver;

    @Autowired
    public SwaggerConfiguration(OpenApiExtensionResolver openApiExtensionResolver) {
        this.openApiExtensionResolver = openApiExtensionResolver;
    }

    @Autowired
    private TypeResolver typeResolver;
    @Autowired
    SwaggerModel swaggerModel;
    private static final String FLAG_TOKEN = "flagToken";
    private static final String UID = "uid";

    /**
     * 全局设置Content Type,默认是application/json
     *  此处我给的空,避免文档上给默认值
     * 如果想只针对某个方法,则注释掉改语句,在特定的方法加上下面信息
     * @ApiOperation(consumes="application/x-www-form-urlencoded")
     */
    private static final HashSet<String> CONSUMES = new HashSet<>();
    static {
        CONSUMES.add("   ");
    }


    @Bean
    public Docket petInnerApi() {
        return this.getDocket("face-app-api","com.simshine.controller.faceapi.app");
    }

    private Docket getDocket(String groupName,String basePackage){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName(groupName)
                .enable(swaggerModel.isEnable())
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/")
                .directModelSubstitute(LocalDate.class, String.class)
                .genericModelSubstitutes(ResponseEntity.class)
                .alternateTypeRules(
                        newRule(typeResolver.resolve(DeferredResult.class,
                                typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
                                typeResolver.resolve(WildcardType.class)))
                .useDefaultResponseMessages(false)
                .securitySchemes(securitySchemes())
                .consumes(SwaggerConfiguration.CONSUMES)
                .securityContexts(securityContexts())
                .extensions(openApiExtensionResolver.buildSettingExtensions());
    }









    private ApiInfo apiInfo() {
        Contact contact = new Contact("htz","http://.qq.com/r/",");
        return new ApiInfoBuilder()
                .title("接口文档")
                .description("响应码")
                .version("2.0.0")
                .contact(contact)
                .termsOfServiceUrl("www.luuka.fun")
                .build();
    }

    private List<SecurityScheme> securitySchemes() {
        List<SecurityScheme> apiKeys = new ArrayList<>();
        apiKeys.add(new ApiKey(FLAG_TOKEN, "token", "header"));
        apiKeys.add(new ApiKey(UID,"UUid","header"));
        return apiKeys;
    }

    private List<SecurityContext> securityContexts() {
        List<SecurityContext> securityContexts = new ArrayList<>();
        securityContexts.add(SecurityContext.builder()
                .securityReferences(defaultAuth1())
                .forPaths(PathSelectors.regex("^(?!auth).*$")).build());
        return securityContexts;
    }

    private List<SecurityReference> defaultAuth1() {
        AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
        AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
        authorizationScopes[0] = authorizationScope;
        List<SecurityReference> securityReferences = new ArrayList<>();
        securityReferences.add(new SecurityReference(FLAG_TOKEN, authorizationScopes));
        securityReferences.add(new SecurityReference(UID, authorizationScopes));
        return securityReferences;
    }

    @Bean
    UiConfiguration uiConfig() {
        return UiConfigurationBuilder.builder()
                .deepLinking(true)
                .displayOperationId(false)
                .defaultModelsExpandDepth(1)
                .defaultModelExpandDepth(1)
                .defaultModelRendering(ModelRendering.EXAMPLE)
                .displayRequestDuration(true)
                .docExpansion(DocExpansion.NONE)
                .filter(false)
                .maxDisplayedTags(null)
                .operationsSorter(OperationsSorter.ALPHA)
                .showExtensions(false)
                .tagsSorter(TagsSorter.ALPHA)
                .supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS)
                .validatorUrl(null)
                .build();
    }



相关jar 版本

<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger2</artifactId>
   <version>3.0.0</version>
</dependency>


<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger-ui</artifactId>
   <version>3.0.0</version>
</dependency>


<!--整合Knife4j-->
<!-- https://mvnrepository.com/artifact/com.github.xiaoymin/knife4j-spring-boot-starter -->
<dependency>
   <groupId>com.github.xiaoymin</groupId>
   <artifactId>knife4j-spring-boot-starter</artifactId>
   <version>3.0.2</version>
</dependency>
}

 

 

 

 

android-contentresolver – ContentResolver用法

android-contentresolver – ContentResolver用法

我是andriod domain的新手,正处于学习阶段.我有几个问题:

我们每个应用程序都有单个ContentResolver对象吗?
它是单身对象吗?
谁管理这个对象生命周期?
如果它是单例,它如何处理查询ContentProvider的多个请求?

解决方法

来自Alex Lockwood的博客 –
http://www.androiddesignpatterns.com/2012/06/content-resolvers-and-content-providers.html

What is the Content Resolver?

The Content Resolver is the single,global instance in your
application that provides access to your (and other applications’)
content providers. The Content Resolver behaves exactly as its name
implies: it accepts requests from clients,and resolves these requests
by directing them to the content provider with a distinct authority.
To do this,the Content Resolver stores a mapping from authorities to
Content Providers. This design is important,as it allows a simple and
secure means of accessing other applications’ Content Providers.

The Content Resolver includes the CRUD (create,read,update,delete)
methods corresponding to the abstract methods (insert,delete,query,
update) in the Content Provider class. The Content Resolver does not
kNow the implementation of the Content Providers it is interacting
with (nor does it need to kNow); each method is passed an URI that
specifies the Content Provider to interact with.

What is a Content Provider?

Whereas the Content Resolver provides an abstraction from the
application’s Content Providers,Content Providers provides an
abstraction from the underlying data source (i.e. a sqlite database).
They provide mechanisms for defining data security (i.e. by enforcing
read/write permissions) and offer a standard interface that connects
data in one process with code running in another process.

Content Providers provide an interface for publishing and consuming
data,based around a simple URI addressing model using the content://
schema. They enable you to decouble your application layers from the
underlying data layers,making your application data-source agnostic
by abstracting the underlying data source.

The Life of a Query

So what exactly is the step-by-step process behind a simple query? As
described above,when you query data from your database via the
content provider,you don’t communicate with the provider directly.
Instead,you use the Content Resolver object to communicate with the
provider. The specific sequence of events that occurs when a query is
made is given below:

  • A call to getContentResolver().query(Uri,String,String) is made. The call invokes the Content Resolver’s query
    method,not the ContentProvider's.

  • When the query method is invoked,the Content Resolver parses the uri argument and extracts its authority.

  • The Content Resolver directs the request to the content provider registered with the (unique) authority. This is done by calling the
    Content Provider’s query method.

  • When the Content Provider's query method is invoked,the query is performed and a Cursor is returned (or an exception is thrown). The resulting behavior depends entirely on the Content Provider’s implementation.

Atom js-hyperclick 支持自定义路径(webpack resolve alias)

Atom js-hyperclick 支持自定义路径(webpack resolve alias)

为毛要单独写这个东西

不得不说 hyperclick 是的了不起的插件,提供了一系列的 Provider 让插件的作者们能够执行文件跳转,不过这个包并不限定语言,只是提供了最底层的一些封装,所以就有了 js-hyperclick 这个好东西。

好东西虽然是好东西,但是在我们开发前端项目的时候我们经常会通过 webpack 的 resolve.alias 配置来定义一些幺蛾子的变量(比如 Vue 项目中,就老喜欢使用 @ 这幺蛾子变量来替代 ./src 目录路径),然鹅……不行的是,js-hyperclick 的作者 AsaAyers 却明确的表示,将不会对这种幺蛾子变量提供支持(参见 issue#58)。

所以,我 fork 了作者的项目,并做了一些改造,使其能够支持额外的文件扩展和自定义路径别名,有兴趣的也可以来 py 一发,PeckZeg/js-hyperclick

食用指北

总的来说,你需要在 bash 中执行这么些骚操作

apm install hyperclick
apm install https://github.com/PeckZeg/js-hyperclick.git

# Vue 工程的支持
apm install vue-hyperclick

在项目的根目录下创建 .js-hyperclick.js 文件,并往里面塞入类似如下的内容:

module.exports = {
    extensions: [''.js'', ''.jsx'', ''.vue'', ''.json''],
    alias: {
        ''@'': ''./src'',
    },
};

关于webpack.base.conf配置中resolve.extensions和resolve.alias用法webpack resolve.alias的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于.net – Control.ResolveUrl与Control.ResolveClientUrl对比VirtualPathUtility.ToAbsolute、.OpenApiExtensionResolver'' that could not be found.、android-contentresolver – ContentResolver用法、Atom js-hyperclick 支持自定义路径(webpack resolve alias)的相关信息,请在本站寻找。

本文标签: