Skip to content

Commit 3f14c3e

Browse files
Merge pull request #74 from express-vue/feature/shrink_code
minifies code in the HTML
2 parents b204c72 + 8cf31e2 commit 3f14c3e

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"dependencies": {
6868
"babel-eslint": "^7.2.3",
6969
"babel-preset-es2015": "^6.24.1",
70+
"butternut": "^0.4.6",
7071
"camel-case": "^3.0.0",
7172
"clean-css": "^4.1.7",
7273
"dedupe": "^2.1.0",

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 = {

tests/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ const vueOptions = {
2121
}
2222

2323
const exampleHead = `<head>\n<title>Page Title</title>\n</head>`;
24-
const exampleScript = `<script>
25-
(function () {'use strict';var createApp = function () {return new Vue({mixins: [{methods: {hello: function hello() {
26-
console.log('Hello');
27-
},},},],data: function(){return {"title":"Express Vue","message":"Hello world","uuid":"farts"}},methods: {test: function test() {
28-
console.error('test');
29-
},},components: {uuid: {props: ["uuid"],data: function(){return {}},template: "<div><h2>Uuid: {{uuid ? uuid : 'no uuid'}}</h2></div>",},uuid2: {props: ["uuid2"],data: function(){return {}},template: "<div><h3>Uuid2: {{uuid2 ? uuid2 : 'no uuid'}}</h3></div>",},},template: "<div><h1>{{title}}</h1><p>Welcome to the {{title}} demo. Click a link:</p><input v-model=\\"message\\" placeholder=\\"edit me\\"><p>{{message}}</p><uuid :uuid=\\"uuid\\"></uuid><uuid2 :uuid2=\\"uuid2\\"></uuid2><button type=\\"button\\" name=\\"button\\" v-on:click=\\"this.hello\\">Test mixin</button> <button type=\\"button\\" name=\\"button\\" v-on:click=\\"this.test\\">Test method</button></div>",})};if (typeof module !== 'undefined' && module.exports) {module.exports = createApp} else {this.app = createApp()}}).call(this);app.$mount('#app');
30-
</script>`
24+
const exampleScript = `<script>(function(){"use strict";var u=function(){return new Vue({mixins:[{methods:{hello:function(){console.log('Hello')}}}],data:function(){return{"title":"Express Vue","message":"Hello world","uuid":"farts"}},methods:{test:function(){console.error('test')}},components:{uuid:{props:["uuid"],data:function(){return{}},template:"<div><h2>Uuid: {{uuid ? uuid : 'no uuid'}}</h2></div>"},uuid2:{props:["uuid2"],data:function(){return{}},template:"<div><h3>Uuid2: {{uuid2 ? uuid2 : 'no uuid'}}</h3></div>"}},template:"<div><h1>{{title}}</h1><p>Welcome to the {{title}} demo. Click a link:</p><input v-model=\\"message\\" placeholder=\\"edit me\\"><p>{{message}}</p><uuid :uuid=\\"uuid\\"></uuid><uuid2 :uuid2=\\"uuid2\\"></uuid2><button type=\\"button\\" name=\\"button\\" v-on:click=\\"this.hello\\">Test mixin</button> <button type=\\"button\\" name=\\"button\\" v-on:click=\\"this.test\\">Test method</button></div>"})};typeof module!=='undefined'&&module.exports?(module.exports=u):(this.app=u())}).call(this),app.$mount('#app')</script>`
3125

3226
test('renders App object', t => {
3327
const renderer = new ExpressVueRenderer(options);

0 commit comments

Comments
 (0)