Skip to content

Commit 7af297c

Browse files
author
QRaimbault
committed
📝 Readme about assets
1 parent 4b41ae4 commit 7af297c

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ A lightweight Vue.js starter.
2929
- [API](#api)
3030
- [Vuex](#vuex)
3131
- [Style](#style)
32+
- [Assets](#assets)
33+
- [Imported assets](#imported-assets)
34+
- [Static assets](#static-assets)
3235
- [Single file components](#single-file-components)
3336
- [Views](#views)
3437
- [Components](#components)
@@ -144,6 +147,32 @@ You should import styles in the `<script>` tag in each component.
144147

145148
You can also put style in the `<style>` tag in each component, scoped or not, the style injection works the same way using scss files or `<style>` tag.
146149

150+
## Assets
151+
152+
### Imported assets
153+
154+
Assets (images, fonts...) used directly in views (Like logo... etc) should be placed in src/assets (`@Asset`) and imported like a JavaScript module and used like a variable. Example:
155+
156+
```js
157+
import logo from "@/images/logo.png";
158+
```
159+
160+
You can also import it in scss using webpack resolved path or relative path as usual. Example:
161+
162+
```scss
163+
.bg-image {
164+
background-image: url('@Asset/images/background.png');
165+
}
166+
// OR
167+
.bg-image {
168+
background-image: url('../../assets/images/background.png');
169+
}
170+
```
171+
172+
### Static assets
173+
174+
Assets used directyle in `static/index.html` like favicon for example should be placed in `static/assets` and will be copied on build in the `dist/assets` directory.
175+
147176
## Single file components
148177

149178
This starter uses [Single File Components](https://vuejs.org/v2/guide/single-file-components.html) structure, which is more suitable for large project but doesn't make it harder for small apps.
@@ -166,6 +195,8 @@ Webpack allows to put some aliases in the webpack config, so you can have shorte
166195
- `@ComponentStyle` pointing to `src/scss/components`
167196
- `@View` pointing to `src/views`
168197
- `@ViewStyle` pointing to `src/scss/views`
198+
- `@Asset` pointing to `src/assets`
199+
- `@` pointing to `src`
169200

170201
An example usage of these aliases is to get the API helper from a view/component:
171202

jsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"@View/*": ["src/views/*"],
1010
"@ViewStyle/*": ["src/scss/views/*"],
1111
"@ComponentStyle/*": ["src/scss/components/*"],
12+
"@Asset/*": ["src/assets/*"],
1213
"@/*": ["src/*"]
1314
}
1415
}

src/assets/.gitignore

Whitespace-only changes.

webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const config = {
9696
"@View": path.resolve(__dirname, "src/views/"),
9797
"@ViewStyle": path.resolve(__dirname, "src/scss/views/"),
9898
"@ComponentStyle": path.resolve(__dirname, "src/scss/components/"),
99+
"@Asset": path.resolve(__dirname, "src/assets/"),
99100
"@": path.resolve(__dirname, "src/"),
100101
}
101102
}

0 commit comments

Comments
 (0)