Skip to content

Add typescript support #50

Open
Open

Description

@frank-orellana

I added typescript support to one of my projects, I believe it should not be that hard to add it out of the box in the templates, so you can use .ts files or add the lang="ts" to the scripts in .vue files, while still supporting all old js files. This is what I did to add the support:

  1. add ts-loader and typescript to package.json: npm i typescript ts-loader --save-dev
  2. add ts and tsx extensions to webpack.config.js:
    extensions: ['.ts', '.tsx', '.js', '.vue', '.json'],
  1. Add ts-loader config to webpack.config.js
module: {
rules: [
  ...
  {
	test: /\.tsx?$/,
	loader: 'ts-loader',
	options: { appendTsSuffixTo: [/\.vue$/] }
  },
  {
	test: /\.vue$/,
	use: 'vue-loader',
  },
  ...
  1. Add tsconfig.json file:
{
    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "moduleResolution": "node"
    }
}
  1. Optional: Add the @babel/plugin-transform-runtime plugin to the babel.config.js file to support async and await keywords in js, I believe this plugin was there before but not sure why it was removed. If this is not added, it would be better to change the target in the previous tsconfig.json file to es5 instead of esnext.
  plugins: [
    'transform-vue-jsx',
    '@babel/plugin-transform-runtime',
    '@babel/plugin-syntax-dynamic-import',
  ]

Also related to this syntax, the oldest version of chrome and webview to support this, is the 55, so maybe when you are ready to drop support for android < 5.0 then this should be the minimum accepted in the browserlist. For the web, I would say chrome 55 should already be the minimum. Firefox 52 and Samsung 6.2 are also reasonable minimums.

I did these for a vue project, but I think it should work for other templates too.

Activity

  1. peterlevel1 commented on Apr 29, 2020

    @peterlevel1

    It would be nice if providing some demos on a git repo, others would give it a try and help the author to do some testing work.

  2. D-Marc1 commented on Apr 3, 2021

    @D-Marc1

    @nolimits4web Any chance TypeScript support be could be added to F7 cli? Seems like something that's really missing from it.

  3. ThalesC commented on Jul 25, 2022

    @ThalesC

    Any chance TypeScript support will be added to F7? Or am I missing something?

  4. Fdavidtr commented on May 5, 2024

    @Fdavidtr

    I was looking for the same =/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions