Skip to content

Commit b578bbd

Browse files
Merge branch 'release/0.6.9'
2 parents 7e57796 + 720c4c4 commit b578bbd

File tree

21 files changed

+239
-46
lines changed

21 files changed

+239
-46
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.

package-lock.json

Lines changed: 55 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "express-vue-renderer",
3-
"version": "0.6.8",
3+
"version": "0.6.9",
44
"description": "Rendering Engine for turning Vue files into Javascript Objects",
55
"homepage": "https://github.com/express-vue/express-vue-renderer",
66
"author": {
@@ -21,7 +21,8 @@
2121
],
2222
"ava": {
2323
"files": [
24-
"tests/**/*.js"
24+
"tests/**/*.js",
25+
"!tests/example/**/*.js"
2526
],
2627
"source": [
2728
"src/**/*.js",
@@ -50,8 +51,8 @@
5051
"scripts": {
5152
"release": "generate-release",
5253
"flow": "flow",
53-
"debug": "npm run build && node --inspect example/app.js",
54-
"start": "npm run build && node example/app.js",
54+
"debug": "npm run build && node --inspect tests/example/app.js",
55+
"start": "npm run build && node tests/example/app.js",
5556
"prepublish": "npm run build && nsp check",
5657
"pretest": "eslint . --fix",
5758
"test": "eslint src && nyc ava",
@@ -67,6 +68,7 @@
6768
"dependencies": {
6869
"babel-eslint": "^7.2.3",
6970
"babel-preset-es2015": "^6.24.1",
71+
"butternut": "^0.4.6",
7072
"camel-case": "^3.0.0",
7173
"clean-css": "^4.1.7",
7274
"dedupe": "^2.1.0",

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

src/parser/style.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ type StyleObjectType = {
1212

1313
function styleParser(styleObjectArray: StyleObjectType[]): Promise<string> {
1414
return new Promise((resolve) => {
15-
if (!styleObjectArray || styleObjectArray.length === 0) {
16-
resolve('');
17-
} else {
15+
let output = '';
16+
if (styleObjectArray && styleObjectArray.length > 0) {
1817
for (const styleObject of styleObjectArray) {
1918
if(styleObject.lang === 'scss' || styleObject.lang === 'less') {
2019
console.error('Sorry please only use plain CSS in your files for now');
2120
}
22-
const output = new CleanCSS({}).minify(styleObject.content);
23-
resolve(output.styles);
21+
output += new CleanCSS({}).minify(styleObject.content).styles;
2422
}
2523
}
24+
resolve(output);
2625
});
2726
}
2827

src/renderer/render.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
const Utils = require('../utils');
33
const Vue = require('vue');
44

5+
const butternut = require('butternut');
6+
const buttterNutOptions = {
7+
sourceMap: false
8+
};
9+
510
function createApp(script) {
611
return new Vue(script);
712
}
@@ -28,7 +33,10 @@ function renderedScript(script: Object, router): string {
2833
if (process.env.VUE_DEV) {
2934
debugToolsString = 'Vue.config.devtools = true;';
3035
}
31-
return `<script>\n(function () {'use strict';${routerString}var createApp = function () {return new Vue(${scriptString})};if (typeof module !== 'undefined' && module.exports) {module.exports = createApp} else {this.app = createApp()}}).call(this);${debugToolsString}app.$mount('#app');\n</script>`;
36+
const javaScriptString = `(function () {'use strict';${routerString}var createApp = function () {return new Vue(${scriptString})};if (typeof module !== 'undefined' && module.exports) {module.exports = createApp} else {this.app = createApp()}}).call(this);${debugToolsString}app.$mount('#app');`;
37+
const finalString = butternut.squash(javaScriptString, buttterNutOptions).code;
38+
39+
return `<script>${finalString}</script>`;
3240
}
3341

3442
type htmlUtilType = {

0 commit comments

Comments
 (0)