Skip to content

Commit 202728d

Browse files
committed
v1.0.0
1 parent c492561 commit 202728d

File tree

13 files changed

+406
-24
lines changed

13 files changed

+406
-24
lines changed

Diff for: .eslintrc

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"globals": {
3+
4+
},
5+
"parserOptions": {
6+
"ecmaVersion": 6,
7+
"sourceType": "module",
8+
"ecmaFeatures": {
9+
"jsx": true
10+
}
11+
},
12+
"rules": {
13+
"strict": [0],
14+
"quotes": [0],
15+
"generator-star-spacing": [0]
16+
},
17+
"env": {
18+
"browser": true,
19+
"node": true,
20+
"commonjs": true,
21+
"es6": true
22+
}
23+
}

Diff for: .htmlhintrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"tagname-lowercase": false,
3+
"attr-lowercase": true,
4+
"attr-value-double-quotes": true,
5+
"doctype-first": true,
6+
"tag-pair": true,
7+
"spec-char-escape": true,
8+
"id-unique": true,
9+
"src-not-empty": true,
10+
"attr-no-duplication": true,
11+
"title-require": true
12+
}

Diff for: README.md

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
11
# fis3-parser-vue-component
22

3-
> 未完成
3+
> [FIS3](http://fis.baidu.com/) parser 阶段插件,用于在fis3中编译[Vue](http://vuejs.org.cn/)组件。
4+
5+
## 原理
6+
7+
参考[vue-loader](https://github.com/vuejs/vue-loader)源码,结合fis3的编译特性而编写,下面是parser阶段的主要过程:
8+
9+
1. 解析vue文件,找到其中的`style`,'template','script'标签。
10+
11+
2. 每一个`style`标签创建一个对应的虚拟文件,后缀为`lang`属性指定,默认`css`,你可以指定`less`或其它的后缀。对创建虚拟文件,一样会进行fis3的编译流程(属性`lang`的值决定该文件怎么编译),并加入当前文件的依赖。
12+
13+
3. `template`标签的内容为Vue组件的模板,`template`标签同样有`lang`属性,默认`html`,会进行html特性处理,模板的内容最终会输出到`module.exports.template`中。
14+
15+
4. `script`标签为文件最后输出的内容,这里不再提供`lang`属性,如果是coffe等非js文件,请在`fis-conf.js`中配置。
16+
17+
# 组件编写规范
18+
19+
`style`标签可以有多个,`template``script`标签只能有一个,具体请参考[vue 单文件组件](http://vuejs.org.cn/guide/application.html)
20+
21+
## 安装配置
22+
23+
安装:`npm install fis3-parser-vue-component --save-dev`
24+
25+
配置:
26+
```javascript:;
27+
// vue
28+
fis.match('src/**.vue', {
29+
isMod: true,
30+
rExt: 'js',
31+
useSameNameRequire: true,
32+
parser: [
33+
fis.plugin('vue-component', {
34+
// 暂时还没有自定义配置哦
35+
}),
36+
fis.plugin('babel-6.x', {
37+
presets: ['es2015-loose', 'react', 'stage-3']
38+
}),
39+
fis.plugin('translate-es3ify', null, 'append')
40+
]
41+
});
42+
```

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fis3-parser-vue-component",
3-
"version": "0.0.2",
3+
"version": "1.0.0",
44
"description": "A parser plugin for fis3 to parser vue component.",
55
"keywords": [
66
"fis3",

Diff for: test/fis-conf.js

+40-13
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,63 @@ fis.set('project.ignore', fis.get('project.ignore').concat(['output/**', 'DS_sto
1010
// https://github.com/fex-team/fis3-hook-commonjs (forwardDeclaration: true)
1111
fis.hook('commonjs', {
1212
extList: [
13-
'.js', '.coffee', '.es6', '.jsx',
13+
'.js', '.coffee', '.es6', '.jsx', '.vue',
1414
],
1515
umd2commonjs: true,
1616
ignoreDependencies: [
1717

1818
]
1919
});
2020

21-
// 模块文件,会进行require包装
22-
fis.match('/{node_modules,src}/**.{js,jsx}', {
23-
isMod: true,
24-
useSameNameRequire: true,
21+
// 用 less 解析
22+
fis.match('*.less', {
23+
rExt: 'css',
24+
parser: [fis.plugin('less-2.x')],
25+
postprocessor: fis.plugin('autoprefixer'),
2526
});
2627

2728
// vue
2829
fis.match('src/**.vue', {
30+
isMod: true,
2931
rExt: 'js',
3032
useSameNameRequire: true,
31-
parser: [parserVuePlugin]
33+
parser: [
34+
parserVuePlugin,
35+
fis.plugin('babel-6.x', {
36+
presets: ['es2015-loose', 'react', 'stage-3']
37+
}),
38+
fis.plugin('translate-es3ify', null, 'append')
39+
]
3240
});
3341

34-
fis.match('**', {
35-
release: '$&'
42+
fis.match('**.js', {
43+
isMod: true,
44+
rExt: 'js',
45+
useSameNameRequire: true
3646
});
3747

38-
// 用 less 解析
39-
fis.match('*.less', {
40-
rExt: 'css',
41-
parser: [fis.plugin('less-2.x')],
42-
postprocessor: fis.plugin('autoprefixer'),
48+
// 模块文件,会进行require包装
49+
fis.match('/src/**.js', {
50+
parser: [
51+
fis.plugin('babel-6.x', {
52+
presets: ['es2015-loose', 'react', 'stage-3']
53+
}),
54+
fis.plugin('translate-es3ify', null, 'append')
55+
]
56+
});
57+
58+
// no modules
59+
fis.match('/src/js/engine/**.js', {
60+
parser: null,
61+
isMod: false
62+
});
63+
64+
fis.match('/src/js/page/**.js', {
65+
isMod: false
66+
});
67+
68+
fis.match('/src/(**)', {
69+
release: '$1'
4370
});
4471

4572
fis.match('::package', {

Diff for: test/output/src/index.js

-2
This file was deleted.

Diff for: test/output/src/index_vue_style_0.less

-1
This file was deleted.

Diff for: test/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@
88
},
99
"author": "",
1010
"license": "ISC",
11-
"dependencies": {},
11+
"dependencies": {
12+
"vue": "^1.0.25"
13+
},
1214
"devDependencies": {
13-
"fis3-postpackager-loader": "^1.5.2"
15+
"babel-preset-es2015-loose": "^7.0.0",
16+
"babel-preset-react": "^6.5.0",
17+
"fis-parser-babel-6.x": "^1.0.0",
18+
"fis3-hook-commonjs": "^0.1.22",
19+
"fis3-hook-node_modules": "^2.2.3",
20+
"fis3-parser-less-2.x": "^0.1.4",
21+
"fis3-parser-translate-es3ify": "0.0.2",
22+
"fis3-postpackager-loader": "^1.5.2",
23+
"fis3-postprocessor-autoprefixer": "^1.0.0"
1424
}
1525
}

Diff for: test/src/component/index.vue

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11

22
<style lang="less">
3-
.a{}
3+
.index {
4+
p {
5+
line-height: 50px;
6+
text-align: center;
7+
background: rgb(240, 203, 210);
8+
border: 1px solid #ddd;
9+
}
10+
11+
img {
12+
display: block;
13+
width: 100%;
14+
margin-top: 20px;
15+
}
16+
}
417
</style>
518

619
<template>
7-
<div class="">
8-
20+
<div class="index">
21+
<p>fis3-parser-vue-component demo runing ~</p>
22+
<img src="../image/1.jpg" alt="" />
923
</div>
1024
</template>
1125

1226
<script>
13-
var a= 1;
27+
module.exports = {
28+
29+
}
1430
</script>

Diff for: test/src/html/index.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>fis3-parser-vue-component demo</title>
6+
</head>
7+
<body>
8+
<div class="app" id="app">
9+
<App></App>
10+
</div>
11+
<script src="../js/engine/mod.js" data-loader></script>
12+
<script src="../js/page/index.js"></script>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)