Skip to content

Commit 8b564dc

Browse files
authored
Merge pull request #75 from express-vue/feature/fix_component_styles
Feature/fix component styles
2 parents 3f14c3e + 97f4f21 commit 8b564dc

File tree

15 files changed

+37
-109
lines changed

15 files changed

+37
-109
lines changed

.vscode/launch.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
// Hover to view descriptions of existing attributes.
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
6-
"configurations": [{
6+
"configurations": [
7+
8+
{
79
"name": "Attach to Process",
810
"type": "node",
911
"request": "attach",
1012
"port": 9229,
1113
"protocol": "inspector",
12-
"restart": true
14+
"restart": true,
15+
"outFiles": ["${workspaceRoot}/lib"],
16+
"sourceMaps": true
1317
},
1418
{
1519
"type": "node",

example/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var exampleMixin = {
1515
};
1616

1717
const options = {
18-
rootPath: path.join(__dirname, '/vueFiles'),
18+
rootPath: path.join(__dirname, ''),
1919
vue: {
2020
head: {
2121
meta: [{
@@ -66,7 +66,7 @@ app.get('/', (req, res) => {
6666
]
6767
}
6868
}
69-
res.renderVue('main/main.vue', data, vueOptions)
69+
res.renderVue('main.vue', data, vueOptions)
7070
});
7171

7272
app.listen(3000);

example/components/uuid.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<template>
22
<div>
33
<inner></inner>
4-
<h2>Uuid: {{uuid ? uuid : 'no uuid'}}</h2>
4+
<h2 class="test">Uuid: {{uuid ? uuid : 'no uuid'}}</h2>
55
</div>
66
</template>
77

88
<script>
9-
import inner from '../components/inner.vue';
9+
import inner from './components/inner.vue';
1010
export default {
1111
props: ['uuid'],
1212
data: function () {

example/components/uuid2.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<h3>Uuid2: {{uuid2 ? uuid2 : 'no uuid'}}</h3>
3+
<h3 class="red">Uuid2: {{uuid2 ? uuid2 : 'no uuid'}}</h3>
44
</div>
55
</template>
66

@@ -14,7 +14,7 @@ export default {
1414
</script>
1515

1616
<style lang="css">
17-
.test {
18-
color: blue;
17+
.red {
18+
color: yellowgreen;
1919
}
2020
</style>
File renamed without changes.

example/vueFiles/components/uuid.vue

Lines changed: 0 additions & 20 deletions
This file was deleted.

example/vueFiles/components/uuid2.vue

Lines changed: 0 additions & 20 deletions
This file was deleted.

example/vueFiles/main/main.vue

Lines changed: 0 additions & 37 deletions
This file was deleted.

example/vueFiles/mixins/exampleMixin.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/parser/component.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const fs = require('fs');
44
const camelCase = require('camel-case');
55
const compiler = require('vue-template-compiler');
6+
const CleanCSS = require('clean-css');
67
const styleParser = require('./style');
78
const htmlParser = require('./html');
89
const scriptParser = require('./script');
@@ -16,6 +17,7 @@ function componentParser(templatePath: string, defaults: Object, type: string, C
1617
scriptParser(cachedComponentContentObject.parsedContent.script, defaults, type, Cache).then(parsedScriptObject => {
1718
cachedComponentContentObject.script = parsedScriptObject;
1819
cachedComponentContentObject.script.template = cachedComponentContentObject.template;
20+
cachedComponentContentObject.styles = parsedScriptObject.styles;
1921
resolve(cachedComponentContentObject);
2022
}).catch(error => {
2123
reject(error);
@@ -64,7 +66,12 @@ function parseContent(content: string, templatePath: string, defaults: Object, t
6466
Promise.all(promiseArray).then(resultsArray => {
6567
const template = resultsArray[0];
6668
const script = resultsArray[1];
67-
const style = resultsArray[2];
69+
let style = '';
70+
if (resultsArray[2]) {
71+
style = resultsArray[2];
72+
} else {
73+
style = new CleanCSS({}).minify(resultsArray[1].styles ? resultsArray[1].styles : '').styles;
74+
}
6875

6976
script.template = template;
7077

0 commit comments

Comments
 (0)