diff --git a/.eslintrc.js b/.eslintrc.js index 93240c8..122358c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,22 +1,28 @@ -/* eslint-disable quote-props */ module.exports = { + root: true, env: { browser: true, es2020: true, + node: true, }, extends: [ 'plugin:vue/essential', + '@vue/standard', + '@vue/typescript/recommended', 'standard', ], + parser: 'vue-eslint-parser', parserOptions: { - ecmaVersion: 12, - sourceType: 'module', + parser: '@typescript-eslint/parser', }, - plugins: [ - 'vue', - ], + // parserOptions: { + // ecmaVersion: 2020, + // }, rules: { - 'semi': [2, 'always'], + 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', + 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', + + 'semi': ['error', 'never'], 'space-before-function-paren': 'off', 'one-var': 'off', 'quotes': 'off', @@ -36,5 +42,15 @@ module.exports = { 'object-property-newline': 'off', 'eqeqeq': 'warn', 'no-multiple-empty-lines': 'off', + + '@typescript-eslint/ban-ts-comment': 'warn', + // '@typescript-eslint/ban-ts-comment': ['warn', { + // 'ts-ignore': 'allow-with-description', + // }], + // 'vue/valid-template-root': 'off', + 'vue/no-multiple-template-root': 'off', + + 'no-empty-function': 'off', + '@typescript-eslint/no-empty-function': ['off'], }, -}; +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..51858bf --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "volar.tsPlugin": true +} \ No newline at end of file diff --git a/api-extractor.json b/api-extractor.json new file mode 100644 index 0000000..3f6626c --- /dev/null +++ b/api-extractor.json @@ -0,0 +1,13 @@ +{ + "mainEntryPointFilePath": "./types/export.d.ts", + "apiReport": { + "enabled": true + }, + "docModel": { + "enabled": true + }, + "dtsRollup": { + "enabled": true, + "publicTrimmedFilePath": "./dist/trois.d.ts" + } +} diff --git a/index.html b/index.html index 883edf9..0626100 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,6 @@
- + diff --git a/package.json b/package.json index c63b380..c7bfce0 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,43 @@ "version": "0.2.3", "scripts": { "dev": "vite", - "build": "vite build", + "build": "vue-tsc --noEmit && vite build", "rollup": "rollup -c" }, "devDependencies": { + "@microsoft/api-extractor": "^7.14.0", "@rollup/plugin-buble": "^0.21.3", "@rollup/plugin-replace": "^2.3.3", + "@types/three": "^0.127.1", + "@typescript-eslint/eslint-plugin": "^4.22.0", + "@typescript-eslint/parser": "^4.22.0", "@vitejs/plugin-vue": "^1.2.1", "@vue/compiler-sfc": "^3.0.11", + "@vue/eslint-config-standard": "^5.1.2", + "@vue/eslint-config-typescript": "^7.0.0", "cannon": "^0.6.2", "eslint": "^7.7.0", - "eslint-config-airbnb-base": "^14.2.0", - "eslint-config-standard": "^14.1.1", "eslint-plugin-import": "^2.22.0", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^4.2.1", "eslint-plugin-standard": "^4.0.1", - "eslint-plugin-vue": "^6.2.2", + "eslint-plugin-vue": "^7.9.0", "gsap": "^3.5.1", "rollup-plugin-terser": "^7.0.2", + "rollup-plugin-typescript2": "^0.30.0", "rollup-plugin-vue": "^6.0.0-beta.11", "stats.js": "0.17.0", "three": "^0.127", + "tslib": "^2.2.0", + "typescript": "^4.1.5", "vite": "^2.1.5", - "vue": "^3.0.11" + "vue": "^3.0.11", + "vue-eslint-parser": "^7.6.0", + "vue-tsc": "^0.0.25" }, "main": "build/trois.js", "module": "build/trois.module.js", + "typings": "build/trois.d.ts", "repository": { "type": "git", "url": "git+https://github.com/troisjs/trois.git" diff --git a/rollup.config.js b/rollup.config.js index 21992d0..e585f48 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,10 +1,14 @@ -// import commonjs from '@rollup/plugin-commonjs'; -import vue from 'rollup-plugin-vue'; -// import buble from '@rollup/plugin-buble'; -import { terser } from "rollup-plugin-terser"; -import replace from '@rollup/plugin-replace'; +import path from 'path' +import vue from 'rollup-plugin-vue' +import typescript from 'rollup-plugin-typescript2' +import replace from '@rollup/plugin-replace' +import { terser } from "rollup-plugin-terser" + +// ensure TS checks only once for each build +let hasTSChecked = false + +const input = 'src/export.ts' -const input = 'src/export.js'; const external = [ 'three', 'three/examples/jsm/controls/OrbitControls.js', @@ -27,86 +31,51 @@ const external = [ 'three/examples/jsm/shaders/FXAAShader.js', 'three/examples/jsm/webxr/VRButton.js', 'vue', -]; +] const cdnReplaces = { 'from \'vue\'': 'from \'https://unpkg.com/vue@3.0.11/dist/vue.esm-browser.prod.js\'', 'from \'three\'': 'from \'https://unpkg.com/three@0.127.0/build/three.module.js\'', 'from \'three/examples': 'from \'https://unpkg.com/three@0.127.0/examples', delimiters: ['', ''], -}; +} -const plugins = [ - vue(), - // buble({ - // transforms: { asyncAwait: false, forOf: false }, - // objectAssign: 'Object.assign', - // }), -]; +function createConfig(format, output, plugins = []) { + const tsPlugin = typescript({ + check: false, // !hasTSChecked, + cacheRoot: path.resolve(__dirname, 'node_modules/.tscache'), + tsconfigOverride: { + compilerOptions: { + sourceMap: false, // !hasTSChecked, + declaration: false, // !hasTSChecked, + declarationMap: false, // !hasTSChecked, + }, + include: [input], + }, + }) + hasTSChecked = true + + return { + input, + external, + output: { + format, + ...output, + // exports: 'named', + sourcemap: true, + }, + plugins: [ + tsPlugin, + vue(), + ...plugins, + ], + } +} export default [ - { - input, - external, - output: { - format: 'es', - exports: 'named', - file: 'build/trois.module.cdn.js', - sourcemap: true, - }, - plugins: [ - replace(cdnReplaces), - ...plugins, - ], - }, - { - input, - external, - output: { - format: 'es', - exports: 'named', - file: 'build/trois.module.cdn.min.js', - sourcemap: true, - }, - plugins: [ - replace(cdnReplaces), - ...plugins, - terser(), - ], - }, - { - input, - external, - output: { - format: 'es', - exports: 'named', - file: 'build/trois.module.js', - sourcemap: true, - }, - plugins, - }, - { - input, - external, - output: { - format: 'es', - exports: 'named', - file: 'build/trois.module.min.js', - sourcemap: true, - }, - plugins: [ - ...plugins, - terser(), - ], - }, - { - input, - external, - output: { - format: 'cjs', - file: 'build/trois.js', - sourcemap: false, - }, - plugins, - }, -]; + createConfig('es', { file: 'build/trois.module.cdn.js' }, [replace(cdnReplaces)]), + createConfig('es', { file: 'build/trois.module.cdn.min.js' }, [replace(cdnReplaces), terser()]), + createConfig('es', { file: 'build/trois.module.js' }), + createConfig('es', { file: 'build/trois.module.min.js' }, [terser()]), + createConfig('cjs', { file: 'build/trois.js' }), +] diff --git a/src/App.vue b/src/App.vue index 42d743e..82b591f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,25 +1,37 @@ -