Skip to content

Commit 3223810

Browse files
author
Patrick Housley
committed
Restructuring with Vue Files
- Restructured all the components to house the template and style inside a Vue file. - This allows the use of the vue-loader in place of the vue-template-loader. - this allows the use of jest-vue-preprocessor instead of a custom wrote preprocessor.
1 parent 6359120 commit 3223810

33 files changed

+723
-292
lines changed
+4-18
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
declare module '*.scss' {
2-
import Vue = require('vue')
3-
interface Template {
4-
<V extends Vue>(options: Vue.ComponentOptions<V>): Vue.ComponentOptions<V>
5-
<V extends typeof Vue>(component: V): V
6-
}
7-
const template: Template
8-
export = template
9-
}
10-
11-
declare module '*.html' {
12-
import Vue = require('vue')
13-
interface Template {
14-
<V extends Vue>(options: Vue.ComponentOptions<V>): Vue.ComponentOptions<V>
15-
<V extends typeof Vue>(component: V): V
16-
}
17-
const template: Template
18-
export = template
1+
declare module "*.vue" {
2+
import Vue from "vue";
3+
const template: Vue.ComponentOptions;
4+
export default template;
195
}

package-lock.json

+602-46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@
3535
"devDependencies": {
3636
"@types/jest": "20.0.2",
3737
"autoprefixer": "7.1.1",
38+
"babel": "6.23.0",
39+
"babel-preset-env": "1.6.0",
40+
"babel-preset-es2015": "6.24.1",
3841
"clean-webpack-plugin": "0.1.16",
3942
"css-loader": "0.28.4",
4043
"cssnano": "3.10.0",
44+
"html-loader": "0.4.5",
4145
"html-webpack-plugin": "2.29.0",
4246
"husky": "0.14.2",
4347
"jest": "20.0.4",
48+
"jest-vue-preprocessor": "1.0.1",
4449
"json-loader": "0.5.4",
4550
"lint-staged": "4.0.0",
4651
"node-sass": "4.5.3",
@@ -50,12 +55,12 @@
5055
"stats-webpack-plugin": "0.6.1",
5156
"style-loader": "0.18.2",
5257
"stylefmt": "6.0.0",
58+
"ts-jest": "20.0.6",
5359
"ts-loader": "2.2.1",
5460
"tslib": "1.7.1",
5561
"tslint": "5.4.3",
5662
"typescript": "2.4.1",
57-
"vue-template-compiler": "2.3.4",
58-
"vue-template-loader": "0.3.1",
63+
"vue-loader": "13.0.0",
5964
"webpack": "3.0.0",
6065
"webpack-dev-server": "2.5.0",
6166
"webpack-merge": "4.1.0"
@@ -101,7 +106,9 @@
101106
"setupTestFrameworkScriptFile": "<rootDir>/src/setup-jest.ts",
102107
"testRegex": "\\.spec\\.(ts|js)$",
103108
"transform": {
104-
".ts": "<rootDir>/src/test-lib/utils/vue-preprocessor.js"
109+
".js$": "<rootDir>/node_modules/babel-jest",
110+
".vue$": "<rootDir>/node_modules/jest-vue-preprocessor",
111+
".ts$": "<rootDir>/node_modules/ts-jest/preprocessor"
105112
}
106113
}
107114
}

src/basic-app/additional-info/additional-info.component.scss

Whitespace-only changes.

src/basic-app/additional-info/additional-info.component.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Vue, Component, injectable } from 'src/lib/vue.barrel';
2-
import * as Template from './additional-info.component.html?style=./additional-info.component.scss';
2+
import template from 'src/basic-app/additional-info/additional-info.component.vue';
33

4-
@Template
54
@Component({
6-
name: 'additional-info'
5+
...template,
6+
...{
7+
name: 'additional-info'
8+
}
79
})
810
@injectable()
911
export class AdditionalInfoComponent extends Vue {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
<template>
12
<div>
23
<div>Application Name: {{name}}</div>
34
<div>Application Version: {{version}}</div>
4-
</div>
5+
</div>
6+
</template>
7+
8+
<style lang="sass" scoped>
9+
10+
</style>

src/basic-app/app/app.component.html

-5
This file was deleted.

src/basic-app/app/app.component.scss

-3
This file was deleted.

src/basic-app/app/app.component.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Vue, VueClass, Component, Inject, Registry, Container, injectable } from 'src/lib/vue.barrel';
2-
import * as Template from './app.component.html?style=./app.component.scss';
2+
import template from 'src/basic-app/app/app.component.vue';
33

4-
@Template
5-
@Component
4+
@Component(template)
65
@injectable()
76
export class AppComponent extends Vue {
87
@Inject()

src/basic-app/app/app.component.vue

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<div>
3+
<h1>Vue Test</h1>
4+
<h3>{{ message }}</h3>
5+
<additional-info></additional-info>
6+
</div>
7+
</template>
8+
9+
<style lang="scss" scoped>
10+
h3 {
11+
background: red;
12+
}
13+
</style>

src/basic-app/goodby-app/goodby-app.component.html

-5
This file was deleted.

src/basic-app/goodby-app/goodby-app.component.scss

-3
This file was deleted.

src/basic-app/goodby-app/goodby-app.component.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Vue, VueClass, Component, Inject, Registry, Container, injectable } from 'src/lib/vue.barrel';
2-
import * as Template from './goodby-app.component.html?style=./goodby-app.component.scss';
2+
import template from 'src/basic-app/goodby-app/goodby-app.component.vue';
33

4-
@Template
5-
@Component
4+
@Component(template)
65
@injectable()
76
export class GoodbyAppComponent extends Vue {
87
@Inject()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<div>
3+
<h1>Vue Test</h1>
4+
<h3>{{ message }}</h3>
5+
<additional-info></additional-info>
6+
</div>
7+
</template>
8+
9+
<style lang="scss" scoped>
10+
h3 {
11+
background: red;
12+
}
13+
</style>

src/lib/vue.barrel.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export interface Registry {
66
[name: string]: symbol;
77
}
88

9+
// import Vue from 'vue';
910
import VueRouter from 'vue-router';
1011
export {
12+
// Vue,
1113
VueRouter
1214
};

src/test-lib/mocks/vue.mock.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as Vue from 'vue';
2-
1+
/* tslint:disable:no-require-imports */
32
/**
43
* When building a Vue app with Webpack, we must import Vue using
54
* the syntax `import Vue from 'vue'` or the application will fail
@@ -8,6 +7,10 @@ import * as Vue from 'vue';
87
* corrects that by overriding the import of vue to provide the correct
98
* import value.
109
*/
11-
jest.mock('vue', () => {
12-
return { default: Vue };
13-
});
10+
jest.setMock('vue', (() => {
11+
const Vue = require('vue');
12+
return {
13+
default: Vue,
14+
Vue
15+
};
16+
})());

src/test-lib/utils/vue-preprocessor.js

-150
This file was deleted.

src/time-tracker-app/app/app.component.scss

Whitespace-only changes.
+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Vue, Component, injectable } from 'src/lib/vue.barrel';
2-
import * as Template from './app.component.html?style=./app.component.scss';
2+
import template from 'src/time-tracker-app/app/app.component.vue';
33

4-
@Template
5-
@Component
4+
@Component(template)
65
@injectable()
76
export class AppComponent extends Vue {
87
}

src/time-tracker-app/app/app.component.html src/time-tracker-app/app/app.component.vue

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<template>
12
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--no-desktop-drawer-button">
23
<header class="mdl-layout__header">
34
<div class="mdl-layout__header-row">
@@ -35,3 +36,9 @@
3536
</div>
3637
</main>
3738
</div>
39+
</template>
40+
41+
<style lang="scss" scoped>
42+
43+
</style>
44+

src/time-tracker-app/home/home.component.scss

-3
This file was deleted.
+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Vue, Component, injectable } from 'src/lib/vue.barrel';
2-
import * as Template from './home.component.html?style=./home.component.scss';
2+
import template from 'src/time-tracker-app/home/home.component.vue';
33

4-
@Template
5-
@Component
4+
@Component(template)
65
@injectable()
76
export class HomeComponent extends Vue {
87
}

0 commit comments

Comments
 (0)