Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal TypeScript support option added #797

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
be474b0
Added minimal possible configuration option for typescript to work
Jul 13, 2017
7cf08a6
TypeScript Vue typings filtered
Jul 13, 2017
5df5b7c
Merge branch 'master' into minimal-typescript-option
igogrek Jul 18, 2017
4fd29f8
Merge remote-tracking branch 'upstream/develop' into minimal-typescri…
Oct 9, 2017
c7ca1a5
TypeScript unit test support
Oct 9, 2017
109ead8
Cleanup
Oct 9, 2017
5d4857a
Merge remote-tracking branch 'upstream/master' into minimal-typescrip…
Oct 16, 2017
31ae428
Merge branch 'develop' into minimal-typescript-option
Oct 16, 2017
150752a
Added Vue.extend for latest TypeScript definitions
Oct 16, 2017
e66b836
Removed vue shims
Oct 16, 2017
222ba2e
Removed allowSyntheticDefaultImports
Oct 22, 2017
ebe7bfd
Added chai TS typings for the unit test
Nov 14, 2017
9f06a63
Merge branch 'develop' into minimal-typescript-option
Nov 14, 2017
257b542
Put back vue-shims for better IDE support
Nov 15, 2017
d587493
Merge branch 'develop' into minimal-typescript-option
Nov 20, 2017
5bc2b0b
Vue shims moved to root for Karma to work properly, Jest support added
Nov 20, 2017
a6869f2
Merge branch 'develop' into minimal-typescript-option
Dec 4, 2017
84d90b4
tsconfig fix for Jest
Dec 4, 2017
9cdc05a
Fixed empty lines for when no typescript selected
Dec 4, 2017
4fc2e12
Whitespace fix
Dec 4, 2017
c5b4755
Merge branch 'develop' into minimal-typescript-option
Dec 19, 2017
e121082
Fixes after develop merge
Dec 19, 2017
0bbcf97
Cleanup
Dec 19, 2017
5d403d9
Added vue extension for better IDE support
Dec 21, 2017
0d1633e
Merge branch 'develop' into minimal-typescript-option
Jan 11, 2018
1a43702
Merge branch 'develop' into minimal-typescript-option
Jan 24, 2018
faac147
Test fixes
Jan 24, 2018
2e54c2b
Another test fix
Jan 24, 2018
74a6af8
Merge branch 'develop' into minimal-typescript-option
Feb 12, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ module.exports = {
}
]
},
"typescript": {
"type": "confirm",
"message": "Use TypeScript as default language?",
"default": false
},
"router": {
"type": "confirm",
"message": "Install vue-router?"
Expand Down Expand Up @@ -86,7 +91,24 @@ module.exports = {
"test/unit/**/*": "unit",
"build/webpack.test.conf.js": "unit",
"test/e2e/**/*": "e2e",
"src/router/**/*": "router"
"src/router/**/*": "router",
"tsconfig.json": "typescript"
},
"completeMessage": "To get started:\n\n {{^inPlace}}cd {{destDirName}}\n {{/inPlace}}npm install\n npm run dev\n\nDocumentation can be found at https://vuejs-templates.github.io/webpack"
"completeMessage": "To get started:\n\n {{^inPlace}}cd {{destDirName}}\n {{/inPlace}}npm install\n npm run dev\n\nDocumentation can be found at https://vuejs-templates.github.io/webpack",
"metalsmith": function (metalsmith, opts, helpers) {
function renameJsSourcesToTs(files, metalsmith, done) {
// If typescript is enabled rename any .js files in src/ folder to .ts extension
if (metalsmith.metadata().typescript) {
Object.keys(files).forEach(filename => {
if (/^(src|test\\unit\\specs).*\.js$/.test(filename)) {
const renamed = filename.replace(/\.js$/, ".ts");
files[renamed] = files[filename]
delete files[filename]
}
})
}
done(null, files)
}
metalsmith.use(renameJsSourcesToTs)
}
};
3 changes: 2 additions & 1 deletion template/build/vue-loader.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ module.exports = {
source: 'src',
img: 'src',
image: 'xlink:href'
}
}{{#typescript}},
esModule: true{{/typescript}}
}
13 changes: 11 additions & 2 deletions template/build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function resolve (dir) {

module.exports = {
entry: {
app: './src/main.js'
app: './src/main.{{#typescript}}ts{{else}}js{{/typescript}}'
},
output: {
path: config.build.assetsRoot,
Expand All @@ -20,7 +20,7 @@ module.exports = {
: config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json'],
extensions: [{{#typescript}}'.ts', {{/typescript}}'.js', '.vue', '.json'],
alias: {
{{#if_eq build "standalone"}}
'vue$': 'vue/dist/vue.esm.js',
Expand All @@ -46,6 +46,15 @@ module.exports = {
loader: 'vue-loader',
options: vueLoaderConfig
},
{{#typescript}}
{
test: /\.ts$/,
loader: "ts-loader",
options: {
appendTsSuffixTo: [/\.vue$/]
}
},
{{/typescript}}
{
test: /\.js$/,
loader: 'babel-loader',
Expand Down
1 change: 1 addition & 0 deletions template/config/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

'use strict'
// Template version: 1.1.1
// see http://vuejs-templates.github.io/webpack for documentation.
Expand Down
5 changes: 5 additions & 0 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"connect-history-api-fallback": "^1.3.0",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
{{#typescript}}
"ts-loader": "^2.3.7",
"typescript": "^2.5.3",
"@types/mocha": "^2.2.43",
{{/typescript}}
{{#lint}}
"eslint": "^3.19.0",
"eslint-friendly-formatter": "^3.0.0",
Expand Down
8 changes: 5 additions & 3 deletions template/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
</div>
</template>

<script>
<script{{#typescript}} lang="ts"{{/typescript}}>
{{#typescript}}import Vue from 'vue'{{#if_eq lintConfig "airbnb"}};
{{/if_eq}}{{/typescript}}
{{#unless router}}
import HelloWorld from './components/HelloWorld'{{#if_eq lintConfig "airbnb"}};{{/if_eq}}

{{/unless}}
export default {
export default {{#typescript}}Vue.extend({{/typescript}}{
name: 'app'{{#router}}{{#if_eq lintConfig "airbnb"}},{{/if_eq}}{{else}},
components: {
HelloWorld{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
}{{#if_eq lintConfig "airbnb"}},{{/if_eq}}{{/router}}
}{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
}{{#typescript}}){{/typescript}}{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
</script>

<style>
Expand Down
8 changes: 5 additions & 3 deletions template/src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
</div>
</template>

<script>
export default {
<script{{#typescript}} lang="ts"{{/typescript}}>
{{#typescript}}import Vue from 'vue'{{#if_eq lintConfig "airbnb"}};{{/if_eq}}{{/typescript}}

export default {{#typescript}}Vue.extend({{/typescript}}{
name: 'HelloWorld',
data{{#unless_eq lintConfig "airbnb"}} {{/unless_eq}}() {
return {
msg: 'Welcome to Your Vue.js App'{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
}{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
}{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
}{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
}{{#typescript}}){{/typescript}}{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
Expand Down
16 changes: 16 additions & 0 deletions template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed anymore I presume

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, removed. Thanks.

"strict": true,
"lib": [
"dom",
"es5",
"es2015.promise"
]
},
"include": [
"./src/**/*.ts"
]
}