Skip to content

Commit

Permalink
add TSX support
Browse files Browse the repository at this point in the history
  • Loading branch information
everettmorgan committed Dec 6, 2021
1 parent 1f2e575 commit c215cba
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 34 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
"no-unsafe-optional-chaining": "off",
"no-useless-backreference": "off",
"default-case-last": "off",
"no-nonoctal-decimal-escape": "off"
"no-nonoctal-decimal-escape": "off",
"import/extensions": "off",
"class-methods-use-this": "off",
"import/no-unresolved": "off"
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
My ideal starting point for Vue projects. (continuously updating)

## Features

- Vue 3 + Typescript: initialized as a Vue 3 project with Typescript support. (also support js)
- ESLint (AirBnB): comes with the AirBnB eslint ruleset for vscode & Vue compiler.
- Class Components: write your Vue components using the new class component.
- TSX + Class Components: write your Vue components using the new class component and TSX.
- Built-in Cypress E2E Testing: out-of-the-box Cypress with support for Vue 3 + Typescript.
- Github Workflow: out-of-the-box Github workflow that runs e2e tests under src/

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@types/mocha": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"@vue/babel-plugin-jsx": "^1.1.1",
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-typescript": "~4.5.0",
Expand Down Expand Up @@ -66,7 +67,10 @@
"no-unsafe-optional-chaining": "off",
"no-useless-backreference": "off",
"default-case-last": "off",
"no-nonoctal-decimal-escape": "off"
"no-nonoctal-decimal-escape": "off",
"import/extensions": "off",
"class-methods-use-this": "off",
"import/no-unresolved": "off"
}
},
"browserslist": [
Expand Down
18 changes: 6 additions & 12 deletions src/App.vue → src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<template>
<Foo/>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component';
import Foo from './components/Foo.vue';
import Foo from './components/Foo';

@Options({
components: {
Expand All @@ -13,12 +8,11 @@ import Foo from './components/Foo.vue';
})

class App extends Vue {
render() {
return (
<Foo/>
);
}
}

export default App;
</script>

<style>
</style>
Empty file added src/components/Foo.css
Empty file.
22 changes: 10 additions & 12 deletions src/components/Foo.vue → src/components/Foo.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<template>
<div>
<button @click.stop="onClick">clicked: {{ count }}</button>
</div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component';
import './Foo.css';

@Options({
props: {
Expand All @@ -19,11 +13,15 @@ class Foo extends Vue {
onClick() {
this.count += 1;
}

render() {
return (
<div>
<button onClick={this.onClick}>clicked: {this.count}</button>
</div>
);
}
}

export default Foo;
</script>

<style scoped>
</style>
export { Foo };
4 changes: 4 additions & 0 deletions src/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.css' {
const classes: { [key: string]: string };
export = classes;
}
19 changes: 19 additions & 0 deletions src/jsx.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable */

import Vue, {VNode} from "vue";

declare global {
namespace JSX {
interface Element extends VNode {}

interface ElementClass extends Vue {}

interface ElementAttributesProperty {
$props: {};
}

interface IntrinsicElements {
[elemName: string]: any;
}
}
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createApp } from 'vue';
import App from './App.vue';
import App from './App.js';

createApp(App).mount('#app');
4 changes: 1 addition & 3 deletions src/tests/Foo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
no-undef,
no-unused-vars,
prefer-arrow-callback,
import/no-unresolved,
import/extensions,
import/no-extraneous-dependencies,
func-names
*/

import { mount } from '@cypress/vue';
import Foo from '../components/Foo.vue';
import Foo from '../components/Foo';

describe('Test', () => {
it('renders a message', () => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
, "cypress/integration/Foo.spec.ts" ],
],
"exclude": [
"node_modules"
]
Expand Down
13 changes: 12 additions & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
// module.exports = {};
module.exports = {
configureWebpack: {
module: {
rules: [
{
test: /\*.css$/,
use: ['vue-style-loader', 'css-loader'],
},
],
},
},
};
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-transform-on/-/babel-helper-vue-transform-on-1.0.2.tgz#9b9c691cd06fc855221a2475c3cc831d774bc7dc"
integrity sha512-hz4R8tS5jMn8lDq6iD+yWL6XNB699pGIVLk7WSJnn1dbpjaazsjZQkieJoRX6gW5zpYSCFqQ7jUquPNY65tQYA==

"@vue/babel-plugin-jsx@^1.0.3":
"@vue/babel-plugin-jsx@^1.0.3", "@vue/babel-plugin-jsx@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@vue/babel-plugin-jsx/-/babel-plugin-jsx-1.1.1.tgz#0c5bac27880d23f89894cd036a37b55ef61ddfc1"
integrity sha512-j2uVfZjnB5+zkcbc/zsOc0fSNGCMMjaEXP52wdwdIfn0qjFfEYpYZBFKFg+HHnQeJCVrjOeO0YxgaL7DMrym9w==
Expand Down

0 comments on commit c215cba

Please sign in to comment.