Linter Configuration

This boilerplate uses ESLint as the linter, and uses the Standard preset with some small customizations.

If you are not happy with the default linting rules, you have several options:

  1. Overwrite individual rules in .eslintrc.js. For example, you can add the following rule to enforce semicolons instead of omitting them:

    // .eslintrc.js
    "semi": [, "always"]
  2. Pick a different ESLint preset when generating the project, for example eslint-config-airbnb.

  3. Pick "none" for ESLint preset when generating the project and define your own rules. See ESLint documentation for more details.

    Pre-Processors

    This boilerplate has pre-configured CSS extraction for most popular CSS pre-processors including LESS, SASS, Stylus, and PostCSS. To use a pre-processor, all you need to do is installing the appropriate webpack loader for it. For example, to use SASS:

    npm install sass-loader node-sass --save-dev

    Note you also need to install node-sass because sass-loader depends on it as a peer dependency.

    Using Pre-Processors inside Components

    Once installed, you can use the pre-processors inside your *.vue components using the lang attribute on <style> tags:

    <style lang="scss">
    /* write SASS! */
    </style>

    A note on SASS syntax

    • lang="scss" corresponds to the CSS-superset syntax (with curly braces and semicolons).
    • lang="sass" corresponds to the indentation-based syntax.

    PostCSS

    Styles in *.vue files are piped through PostCSS by default, so you don't need to use a specific loader for it. You can simply add PostCSS plugins you want to use in build/webpack.base.conf.js under the vue block:

    // build/webpack.base.conf.js
    module.exports = {
    // ...
    vue: {
    postcss: [/* your plugins */]
    }
    }

    See vue-loader's related documentation for more details.

    Standalone CSS Files

    To ensure consistent extraction and processing, it is recommended to import global, standalone style files from your root App.vue component, for example:

    <!-- App.vue -->
    <style src="./styles/global.less" lang="less"></style>

    Note you should probably only do this for the styles written by yourself for your application. For existing libraries e.g. Bootstrap or Semantic UI, you can place them inside /static and reference them directly in index.html. This avoids extra build time and also is better for browser caching. (See Static Asset Handling)

    Handling Static Assets

    You will notice in the project structure we have two directories for static assets: src/assets and static/. What is the difference between them?

    Webpacked Assets

    To answer this question, we first need to understand how Webpack deals with static assets. In *.vuecomponents, all your templates and CSS are parsed by vue-html-loader and css-loader to look for asset URLs. For example, in <img src="./logo.png"> and background: url(./logo.png)"./logo.png" is a relative asset path and will be resolved by Webpack as a module dependency.

    Because logo.png is not JavaScript, when treated as a module dependency, we need to use url-loader and file-loader to process it. This boilerplate has already configured these loaders for you, so you basically get features such as filename fingerprinting and conditional base64 inlining for free, while being able to use relative/module paths without worrying about deployment.

    Since these assets may be inlined/copied/renamed during build, they are essentially part of your source code. This is why it is recommended to place Webpack-processed static assets inside /src, along side other source files. In fact, you don't even have to put them all in /src/assets: you can organize them based on the module/component using them. For example, you can put each component in its own directory, with its static assets right next to it.

    Asset Resolving Rules

    • Relative URLs, e.g. ./assets/logo.png will be interpreted as a module dependency. They will be replaced with an auto-generated URL based on your Webpack output configuration.

    • Non-prefixed URLs, e.g. assets/logo.png will be treated the same as the relative URLs and translated into ./assets/logo.png.

    • URLs prefixed with ~ are treated as a module request, similar to require('some-module/image.png'). You need to use this prefix if you want to leverage Webpack's module resolving configurations. For example if you have a resolve alias for assets, you need to use <img src="~assets/logo.png"> to ensure that alias is respected.

    • Root-relative URLs, e.g. /assets/logo.png are not processed at all.

    Getting Asset Paths in JavaScript

    In order for Webpack to return the correct asset paths, you need to use require('./relative/path/to/file.jpg'), which will get processed by file-loader and returns the resolved URL. For example:

    computed: {
    background () {
    return require('./bgs/' + this.id + '.jpg')
    }
    }

    Note the above example will include every image under ./bgs/ in the final build. This is because Webpack cannot guess which of them will be used at runtime, so it includes them all.

    "Real" Static Assets

    In comparison, files in static/ are not processed by Webpack at all: they are directly copied to their final destination as-is, with the same filename. You must reference these files using absolute paths, which is determined by joining build.assetsPublicPath and build.assetsSubDirectory in config.js.

    As an example, with the following default values:

    // config/index.js
    module.exports = {
    // ...
    build: {
    assetsPublicPath: '/',
    assetsSubDirectory: 'static'
    }
    }

    Any file placed in static/ should be referenced using the absolute URL /static/[filename]. If you change assetSubDirectory to assets, then these URLs will need to be changed to /assets/[filename].

    We will learn more about the config file in the section about backend integration.

vue单页面模板说明文档(2)的更多相关文章

  1. vue单页面模板说明文档(3)

    Environment Variables Sometimes it is practical to have different config values according to the env ...

  2. vue单页面模板说明文档(1)

    Introduction This boilerplate is targeted towards large, serious projects and assumes you are somewh ...

  3. vue render {} 对象 说明文档

    Vue学习笔记进阶篇——Render函数 http://www.mamicode.com/info-detail-1906336.html 深入data object参数 有一件事要注意:正如在模板语 ...

  4. Vue 单文件元件 — vTabs

    简书原文 这是我做了第二个单文件元件 第一个在这里vCheckBox 这次这个叫vTabs,用于操作标签页 演示DEMO 演示DEMO2 - 子组件模式及别名 演示DEMO3 - 极简模式 示例: h ...

  5. webpack入坑之旅(五)加载vue单文件组件

    这是一系列文章,此系列所有的练习都存在了我的github仓库中vue-webpack,在本人有了新的理解与认识之后,会对文章有不定时的更正与更新.下面是目前完成的列表: webpack入坑之旅(一)不 ...

  6. SWFUpload 2.5.0版 官方说明文档 中文翻译版

    原文地址:http://www.cnblogs.com/youring2/archive/2012/07/13/2590010.html#setFileUploadLimit SWFUpload v2 ...

  7. 《暗黑世界GM管理后台系统》部署+功能说明文档

    http://www.9miao.com/product-10-1073.html <暗黑世界GM管理后台系统>部署+功能说明文档 <暗黑世界GM管理后台系统>部署+功能说明文 ...

  8. BasicExcel说明文档

    BasicExcel说明文档 BasicExcel原始链接:http://www.codeproject.com/Articles/13852/BasicExcel-A-Class-to-Read-a ...

  9. 处理 Vue 单页面应用 SEO 的另一种思路

    vue-meta-info 官方地址: monkeyWangs/vue-meta-info (设置vue 单页面meta info信息,如果需要单页面SEO,可以和 prerender-spa-plu ...

随机推荐

  1. jsp 或 php 等view之中使用javascript简单处理的使用技巧

    前端人员在jsp,php等后台mvc之的coding之时,前端人员常常需要一些少量的数据处理,直接使用js的方法无疑是开销最小的.使用的方法 使用在标签之中嵌套script标签,使用document. ...

  2. ArcMap2Sld:一个将MXD中图层配图样式转换为OGC的SLD文件的开源工具

    在一个项目中,用户采用GeoServer做为GIS服务器(原因嘛当然是免费能省钱,经过验证可能还会在性能和稳定性等表现力也有优越性),但是手上收集的数据都是ESRI格式的,这倒不打紧,因为GeoSer ...

  3. ES5-ES6-ES7_字符串扩展—模板字符串

    includes(), startsWith(), endsWith() 传统上,JavaScript只有indexOf方法,可以用来确定一个字符串是否包含在另一个字符串中.ES6又提供了三种新方法 ...

  4. Java面试知识点之设计模式(一)

    前言:关于设计模式,在框架中用的比较多.在平常接触最为频繁的估计是单例模式了,因此笔者在此对设计模式相关知识点进行总结. 1.设计模式的种类 总体来说,设计模式分为3大类总共23种: 1)创建型模式, ...

  5. Spring Cloud构建微服务架构:服务网关(路由配置)【Dalston版】

    转载:http://blog.didispace.com/spring-cloud-starter-dalston-6-2/ 原创  2017-08-26  翟永超  Spring Cloud 被围观 ...

  6. I/O 机制的介绍(Linux 中直接 I/O 机制的介绍)

    IO连接的建立方式 1.缓存IO.流式IO: 2.映射IO.块式IO: 3.直接IO. IO的方式: 同步.异步.定时刷新: MMAP与内核空间 mmap使用共享用户空间与内核空间实现: 直接 I/O ...

  7. [ZJOI2018]胖

    嘟嘟嘟 都说这题是送分题,但我怎么就不觉得的呢. 看来我还是太弱了啊-- 大体思路就是对于每一个设计方案,答案就是每一个关键点能更新的点的数量之和. 关键在于怎么求一个关键点能更新那些点. 首先这些点 ...

  8. 【转】实践HTTP206状态:部分内容和范围请求

    原文:http://www.cyberciti.biz/cloud-computing/http-status-code-206-commad-line-test/ HTTP 2xx范围内的状态码表明 ...

  9. Linux:Day4(上) 文件管理、管道

    文件管理:cp.mv.rm 复制命令:cp cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION] ...

  10. 关于alter database datafile offline和alter database datafile offline drop 的区别

    转: https://blog.csdn.net/killvoon/article/details/46913183 -----------------------2015-07-16-------- ...