diff --git a/src/models/defaults.js b/src/models/defaults.js
index 414b0da..4f75286 100644
--- a/src/models/defaults.js
+++ b/src/models/defaults.js
@@ -17,10 +17,15 @@ class Defaults {
options: Object;
vue: Object;
data: Object;
+ style: string;
constructor(options: Object = {}) {
this.options = options;
this.layout = new Layout.Layout(options.layout);
+ if (options.style) {
+ this.style = options.style;
+ }
+
if (options.rootPath) {
this.rootPath = path.resolve(options.rootPath);
}
diff --git a/src/parser/component.js b/src/parser/component.js
index 06e9491..e3dd849 100644
--- a/src/parser/component.js
+++ b/src/parser/component.js
@@ -3,7 +3,6 @@
const fs = require('fs');
const camelCase = require('camel-case');
const compiler = require('vue-template-compiler');
-const CleanCSS = require('clean-css');
const styleParser = require('./style');
const htmlParser = require('./html');
const scriptParser = require('./script');
@@ -28,13 +27,14 @@ function componentParser(templatePath: string, defaults: Object, type: string, C
let error = `Could Not Find Component, I was expecting it to live here \n${templatePath} \nBut I couldn't find it there, ¯\\_(ツ)_/¯\n\n`;
reject(error);
} else {
- parseContent(content, templatePath, defaults, type, Cache).then(contentObject => {
+ parseContent(content, templatePath, defaults, type, Cache)
+ .then(contentObject => {
// set the cache for the component
- Cache.set(templatePath, contentObject);
- resolve(contentObject);
- }).catch(error => {
- reject(error);
- });
+ Cache.set(templatePath, contentObject);
+ resolve(contentObject);
+ }).catch(error => {
+ reject(error);
+ });
}
});
}
@@ -66,11 +66,10 @@ function parseContent(content: string, templatePath: string, defaults: Object, t
Promise.all(promiseArray).then(resultsArray => {
const template = resultsArray[0];
const script = resultsArray[1];
- let style = '';
- if (resultsArray[2]) {
- style = resultsArray[2];
+ if (defaults.style === undefined) {
+ defaults.style = resultsArray[2];
} else {
- style = new CleanCSS({}).minify(resultsArray[1].styles ? resultsArray[1].styles : '').styles;
+ defaults.style += resultsArray[2];
}
script.template = template;
@@ -79,7 +78,7 @@ function parseContent(content: string, templatePath: string, defaults: Object, t
template: template,
parsedContent: parsedContent,
type: type,
- style: style,
+ style: defaults.style,
name: camelCase(templateName),
script: script
};
diff --git a/src/utils/require.js b/src/utils/require.js
index 9809e4c..6e1c5d5 100644
--- a/src/utils/require.js
+++ b/src/utils/require.js
@@ -22,10 +22,11 @@ class Options {
}
}
-function getVueObject(componentPath: string, rootPath: string, vueComponentFileMatch: string, Cache: Object): Promise < {rendered:Object, match: string} > {
+function getVueObject(componentPath: string, rootPath: string, vueComponentFileMatch: string, Cache: Object, Options: Options): Promise < {rendered:Object, match: string} > {
const GlobalOptions = new Models.Defaults({
rootPath: rootPath,
- component: componentPath
+ component: componentPath,
+ style: Options.defaults.style || ''
});
return new Promise((resolve, reject) => {
Utils.setupComponent(componentPath, GlobalOptions, Cache)
@@ -34,6 +35,12 @@ function getVueObject(componentPath: string, rootPath: string, vueComponentFileM
if (!rendered) {
reject(new Error('Renderer Error'));
} else {
+ if (Options.defaults.style) {
+ Options.defaults.style += rendered.layout.style;
+ } else {
+ Options.defaults.style = rendered.layout.style;
+ }
+
resolve({
rendered: rendered,
match: vueComponentFileMatch
@@ -99,7 +106,7 @@ function requireFromString(code: string, filename: string = '', optsObj: Object
//this is because its easier to do string replace later
const vueComponentFile = vueComponentFileMatch.match(options.vueFileRegex);
if (vueComponentFile && vueComponentFile.length > 0) {
- promiseArray.push(getVueObject(vueComponentFile[0], options.rootPath, vueComponentFileMatch, Cache));
+ promiseArray.push(getVueObject(vueComponentFile[0], options.rootPath, vueComponentFileMatch, Cache, options));
}
}
Promise.all(promiseArray)
diff --git a/tests/example/components/inner.vue b/tests/example/components/inner.vue
index 80b547b..36d6f35 100644
--- a/tests/example/components/inner.vue
+++ b/tests/example/components/inner.vue
@@ -1,6 +1,6 @@
Inner Text Inner Text