Skip to content

Commit a23d03e

Browse files
committed
pref: add test rule and examples
1 parent 8159827 commit a23d03e

24 files changed

+12057
-45
lines changed

.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tsconfig.json
2+
typings
3+
src/
4+
example/
5+
test/
6+
.vscode/

__examples__/vue2/.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
5+
# local env files
6+
.env.local
7+
.env.*.local
8+
9+
# Log files
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Editor directories and files
15+
.idea
16+
.vscode
17+
*.suo
18+
*.ntvs*
19+
*.njsproj
20+
*.sln
21+
*.sw?

__examples__/vue2/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# vue2
2+
3+
## Project setup
4+
5+
```
6+
yarn install
7+
```
8+
9+
### Compiles and hot-reloads for development
10+
11+
```
12+
yarn run serve
13+
```
14+
15+
### Compiles and minifies for production
16+
17+
```
18+
yarn run build
19+
```
20+
21+
### Run your tests
22+
23+
```
24+
yarn run test
25+
```
26+
27+
### Lints and fixes files
28+
29+
```
30+
yarn run lint
31+
```
32+
33+
### Customize configuration
34+
35+
See [Configuration Reference](https://cli.vuejs.org/config/).

__examples__/vue2/babel.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const plugin = require('../../dist/index')
2+
3+
module.exports = {
4+
presets: ['@vue/app'],
5+
plugins: [plugin]
6+
}

__examples__/vue2/package.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "vue2",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"serve": "vue-cli-service serve",
7+
"build": "vue-cli-service build",
8+
"lint": "vue-cli-service lint"
9+
},
10+
"dependencies": {
11+
"core-js": "^2.6.5",
12+
"vue": "^2.6.10"
13+
},
14+
"devDependencies": {
15+
"@vue/cli-plugin-babel": "^3.11.0",
16+
"@vue/cli-plugin-eslint": "^3.11.0",
17+
"@vue/cli-service": "^3.11.0",
18+
"babel-eslint": "^10.0.1",
19+
"eslint": "^5.16.0",
20+
"eslint-plugin-vue": "^5.0.0",
21+
"node-sass": "^4.12.0",
22+
"sass-loader": "^8.0.0",
23+
"scoped-css-loader": "^1.0.0",
24+
"vue-template-compiler": "^2.6.10"
25+
},
26+
"eslintConfig": {
27+
"root": true,
28+
"env": {
29+
"node": true
30+
},
31+
"extends": [
32+
"plugin:vue/essential",
33+
"eslint:recommended"
34+
],
35+
"rules": {},
36+
"parserOptions": {
37+
"parser": "babel-eslint"
38+
}
39+
},
40+
"postcss": {
41+
"plugins": {
42+
"autoprefixer": {}
43+
}
44+
},
45+
"browserslist": [
46+
"> 1%",
47+
"last 2 versions"
48+
]
49+
}

__examples__/vue2/public/favicon.ico

4.19 KB
Binary file not shown.

__examples__/vue2/public/index.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
8+
<title>vue2</title>
9+
</head>
10+
<body>
11+
<noscript>
12+
<strong>We're sorry but vue2 doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
13+
</noscript>
14+
<div id="app"></div>
15+
<!-- built files will be auto injected -->
16+
</body>
17+
</html>

__examples__/vue2/src/App.vue

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<template>
2+
<div id="app">
3+
<img alt="Vue logo" src="./assets/logo.png" />
4+
<HelloWorld msg="Welcome to Your Vue.js App" />
5+
<TestComp :list="links"></TestComp>
6+
</div>
7+
</template>
8+
9+
<script>
10+
import HelloWorld from './components/HelloWorld.vue'
11+
import TestComp from './components/TestComp'
12+
13+
export default {
14+
name: 'app',
15+
components: {
16+
HelloWorld,
17+
TestComp
18+
},
19+
data() {
20+
return {
21+
links: [
22+
{
23+
label: 'babel-plugin-vue-jsx-scoped-css',
24+
link:
25+
'https://github.com/Mrminfive/babel-plugin-vue-jsx-scoped-css'
26+
}
27+
]
28+
}
29+
}
30+
}
31+
</script>
32+
33+
<style>
34+
#app {
35+
font-family: 'Avenir', Helvetica, Arial, sans-serif;
36+
-webkit-font-smoothing: antialiased;
37+
-moz-osx-font-smoothing: grayscale;
38+
text-align: center;
39+
color: #2c3e50;
40+
margin-top: 60px;
41+
}
42+
</style>

__examples__/vue2/src/assets/logo.png

6.69 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<template>
2+
<div class="hello">
3+
<h1>{{ msg }}</h1>
4+
<p>
5+
For a guide and recipes on how to configure / customize this project,
6+
<br />check out the
7+
<a
8+
href="https://cli.vuejs.org"
9+
target="_blank"
10+
rel="noopener"
11+
>vue-cli documentation</a>.
12+
</p>
13+
<h3>Installed CLI Plugins</h3>
14+
<ul>
15+
<li>
16+
<a
17+
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel"
18+
target="_blank"
19+
rel="noopener"
20+
>babel</a>
21+
</li>
22+
<li>
23+
<a
24+
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint"
25+
target="_blank"
26+
rel="noopener"
27+
>eslint</a>
28+
</li>
29+
</ul>
30+
<h3>Essential Links</h3>
31+
<ul>
32+
<li>
33+
<a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a>
34+
</li>
35+
<li>
36+
<a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a>
37+
</li>
38+
<li>
39+
<a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a>
40+
</li>
41+
<li>
42+
<a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a>
43+
</li>
44+
<li>
45+
<a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a>
46+
</li>
47+
</ul>
48+
<h3>Ecosystem</h3>
49+
<ul>
50+
<li>
51+
<a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a>
52+
</li>
53+
<li>
54+
<a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a>
55+
</li>
56+
<li>
57+
<a
58+
href="https://github.com/vuejs/vue-devtools#vue-devtools"
59+
target="_blank"
60+
rel="noopener"
61+
>vue-devtools</a>
62+
</li>
63+
<li>
64+
<a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a>
65+
</li>
66+
<li>
67+
<a
68+
href="https://github.com/vuejs/awesome-vue"
69+
target="_blank"
70+
rel="noopener"
71+
>awesome-vue</a>
72+
</li>
73+
</ul>
74+
</div>
75+
</template>
76+
77+
<script>
78+
export default {
79+
name: 'HelloWorld',
80+
props: {
81+
msg: String
82+
}
83+
}
84+
</script>
85+
86+
<!-- Add "scoped" attribute to limit CSS to this component only -->
87+
<style scoped>
88+
h3 {
89+
margin: 40px 0 0;
90+
}
91+
ul {
92+
list-style-type: none;
93+
padding: 0;
94+
}
95+
li {
96+
display: inline-block;
97+
margin: 0 10px;
98+
}
99+
a {
100+
color: #42b983;
101+
}
102+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import './index.scoped.scss'
2+
import Vue from 'vue'
3+
4+
export default Vue.extend({
5+
name: 'test-comp',
6+
7+
functional: true,
8+
9+
props: {
10+
list: {
11+
type: Array,
12+
default: () => []
13+
}
14+
},
15+
16+
render(h, { props }) {
17+
return (
18+
<nav class='test-comp'>
19+
<h3 class='test-comp__title'>JSX Scoped Css</h3>
20+
<ul class='test-comp__links'>
21+
{props.list.map((item) => (
22+
<li class='test-comp__link'>
23+
<a href={item.link}>{item.label}</a>
24+
</li>
25+
))}
26+
</ul>
27+
</nav>
28+
)
29+
}
30+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.test-comp {
2+
&__title {
3+
margin: 40px 0 0;
4+
}
5+
6+
&__links {
7+
}
8+
9+
&__link {
10+
a {
11+
color: #42b983;
12+
}
13+
}
14+
}

__examples__/vue2/src/main.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Vue from 'vue'
2+
import App from './App.vue'
3+
4+
Vue.config.productionTip = false
5+
6+
new Vue({
7+
render: (h) => h(App)
8+
}).$mount('#app')

__examples__/vue2/vue.config.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
chainWebpack: (config) => {
3+
/**
4+
* 增加 css 作用域 loader 处理
5+
*/
6+
const baseRule = config.module.rule('scss')
7+
;[
8+
(baseRule.oneOf('modules').resourceQuery(/module/),
9+
baseRule.oneOf('normal'))
10+
].forEach((rule) => {
11+
rule.use('scoped-css-loader')
12+
.loader('scoped-css-loader')
13+
.before('sass-loader')
14+
})
15+
}
16+
}

0 commit comments

Comments
 (0)