vue单页面模板说明文档(2)
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:
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"]Pick a different ESLint preset when generating the project, for example eslint-config-airbnb.
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-sassbecausesass-loaderdepends on it as a peer dependency.Using Pre-Processors inside Components
Once installed, you can use the pre-processors inside your
*.vuecomponents using thelangattribute 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
*.vuefiles 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 inbuild/webpack.base.conf.jsunder thevueblock:// 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.vuecomponent, 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
/staticand reference them directly inindex.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/assetsandstatic/. 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 byvue-html-loaderandcss-loaderto look for asset URLs. For example, in<img src="./logo.png">andbackground: url(./logo.png),"./logo.png"is a relative asset path and will be resolved by Webpack as a module dependency.Because
logo.pngis not JavaScript, when treated as a module dependency, we need to useurl-loaderandfile-loaderto 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.pngwill 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.pngwill be treated the same as the relative URLs and translated into./assets/logo.png.URLs prefixed with
~are treated as a module request, similar torequire('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 forassets, you need to use<img src="~assets/logo.png">to ensure that alias is respected.Root-relative URLs, e.g.
/assets/logo.pngare 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 byfile-loaderand 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 joiningbuild.assetsPublicPathandbuild.assetsSubDirectoryinconfig.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 changeassetSubDirectorytoassets, 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)的更多相关文章
- vue单页面模板说明文档(3)
Environment Variables Sometimes it is practical to have different config values according to the env ...
- vue单页面模板说明文档(1)
Introduction This boilerplate is targeted towards large, serious projects and assumes you are somewh ...
- vue render {} 对象 说明文档
Vue学习笔记进阶篇——Render函数 http://www.mamicode.com/info-detail-1906336.html 深入data object参数 有一件事要注意:正如在模板语 ...
- Vue 单文件元件 — vTabs
简书原文 这是我做了第二个单文件元件 第一个在这里vCheckBox 这次这个叫vTabs,用于操作标签页 演示DEMO 演示DEMO2 - 子组件模式及别名 演示DEMO3 - 极简模式 示例: h ...
- webpack入坑之旅(五)加载vue单文件组件
这是一系列文章,此系列所有的练习都存在了我的github仓库中vue-webpack,在本人有了新的理解与认识之后,会对文章有不定时的更正与更新.下面是目前完成的列表: webpack入坑之旅(一)不 ...
- SWFUpload 2.5.0版 官方说明文档 中文翻译版
原文地址:http://www.cnblogs.com/youring2/archive/2012/07/13/2590010.html#setFileUploadLimit SWFUpload v2 ...
- 《暗黑世界GM管理后台系统》部署+功能说明文档
http://www.9miao.com/product-10-1073.html <暗黑世界GM管理后台系统>部署+功能说明文档 <暗黑世界GM管理后台系统>部署+功能说明文 ...
- BasicExcel说明文档
BasicExcel说明文档 BasicExcel原始链接:http://www.codeproject.com/Articles/13852/BasicExcel-A-Class-to-Read-a ...
- 处理 Vue 单页面应用 SEO 的另一种思路
vue-meta-info 官方地址: monkeyWangs/vue-meta-info (设置vue 单页面meta info信息,如果需要单页面SEO,可以和 prerender-spa-plu ...
随机推荐
- June 14. 2018 Week 24th Thursday
Good friends, good books, and a sleepy conscience: this is the ideal life. 拥有益友.良书和一颗宁静的内心:这就是理想的生活. ...
- Java教程01-基础语法
目录 1. 基本概念 1.1. 环境变量 Path环境变量的作用->寻找命令 classpath变量的作用->寻找类文件 1.2. JDK里面有什么? 1.3. 什么是JRE? 2. Ja ...
- python 黏包现象及其解决方案
一.数据缓冲区 缓冲区(buffer),它是内存空间的一部分.也就是说,在内存空间中预留了一定的存储空间,这些存储空间用来缓冲输入或输出的数据,这部分预留的空间就叫做缓冲区,显然缓冲区是具有一定大小的 ...
- (转)Spring Boot(十七):使用 Spring Boot 上传文件
http://www.ityouknow.com/springboot/2018/01/12/spring-boot-upload-file.html 上传文件是互联网中常常应用的场景之一,最典型的情 ...
- JavaScript—Date对象详情
Date对象概述 javaScript 提供了 Date 类型来处理时间和日期.Date 对象内置一系列获取和设置日期时间信息的方法.(不是内置对象,需要自己new) javaScript 中的 Da ...
- ES5-ES6-ES7_async函数
async 函数概述 async/await应该是目前最简单的异步方案,ES7 中新增了 async/await 两个关键词. async 可以声明一个异步函数,此函数需要返回一个 Promise 对 ...
- 【NOI2018模拟】Yja
[NOI2018模拟]Yja Description 在平面上找\(n\)个点,要求这 \(n\)个点离原点的距离分别为 \(r1,r2,...,rn\) .最大化这\(n\) 个点构成的凸包面积,凸 ...
- BZOJ5197:[CERC2017]Gambling Guide(最短路,期望DP)
Description 给定一张n个点,m条双向边的无向图. 你要从1号点走到n号点.当你位于x点时,你需要花1元钱,等概率随机地买到与x相邻的一个点的票,只有通过票才能走到其它点. 每当完成一次交易 ...
- 008_Node中的require和import
一.js的对象的解构赋值 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuri ...
- element not interactable,这种提示表示元素当前在页面上不可见
1.出现element not interactable,发现这个元素在页面上不可见,需要拖动下拉框才能看到这个元素 2.这个时候需要让元素在页面上可见,才可操作