Skip to content

Commit

Permalink
add:css modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cag2050 committed Dec 11, 2018
1 parent 88ebcc8 commit 36b3180
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 11 deletions.
6 changes: 5 additions & 1 deletion build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const config = require('../config')
// const ExtractTextPlugin = require('extract-text-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const packageConfig = require('../package.json')
const lodash = require('lodash')

exports.assetsPath = function (_path) {
const assetsSubDirectory = process.env.NODE_ENV === 'production'
Expand All @@ -19,7 +20,10 @@ exports.cssLoaders = function (options) {
const cssLoader = {
loader: 'css-loader',
options: {
sourceMap: options.sourceMap
sourceMap: options.sourceMap,
// https://vue-loader.vuejs.org/zh/migrating.html#css-modules
modules: true,
localIdentName: '[local]---[hash:base64:5]'
}
}

Expand Down
2 changes: 1 addition & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = {
* Source Maps
*/

productionSourceMap: true,
productionSourceMap: false,
// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',

Expand Down
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"build": "node build/build.js"
},
"dependencies": {
"lodash": "^4.17.11",
"vue": "^2.5.2",
"vue-router": "^3.0.1"
},
Expand Down
11 changes: 6 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<template>
<div id="app">
<img src="./assets/logo.png">
<div :class="$style.app">
路由列表:
<router-link to='/'>首页</router-link> |
<router-link to='/test'>test页面</router-link> |
<router-view/>
</div>
</template>
Expand All @@ -11,13 +13,12 @@ export default {
}
</script>

<style lang="stylus">
#app {
<style lang="stylus" module>
.app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
8 changes: 6 additions & 2 deletions src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'

Vue.use(Router)

Expand All @@ -10,7 +9,12 @@ export default new Router({
{
path: '/',
name: 'HelloWorld',
component: HelloWorld
component: () => import('@/components/HelloWorld.vue')
},
{
path: '/test',
name: '',
component: () => import('@/views/Test.vue')
}
]
})
21 changes: 21 additions & 0 deletions src/views/Test.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<div :class="$style.blueColor">
{{test}}
</div>
</template>

<script>
export default {
name: '',
data () {
return {
test: 'test页面'
}
}
}
</script>

<style lang="stylus" module>
.blueColor
color blue
</style>

0 comments on commit 36b3180

Please sign in to comment.