added typescript

This commit is contained in:
vishnuraghavb 2021-04-14 15:15:18 +05:30
parent 5899821d21
commit 8189d481e6
7 changed files with 120 additions and 380 deletions

View file

@ -1,10 +0,0 @@
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"~/*": ["app/*"],
"@/*": ["app/*"]
}
},
"include": ["app/**/*"]
}

95
package-lock.json generated
View file

@ -22,9 +22,12 @@
},
"devDependencies": {
"@nativescript/android": "8.0.0",
"@nativescript/types": "^8.0.0",
"@nativescript/webpack": "beta",
"@types/node": "^14.14.37",
"nativescript-vue-template-compiler": "~2.9.0",
"sass": "^1.32.8"
"sass": "^1.32.8",
"typescript": "^4.2.4"
}
},
"node_modules/@babel/code-frame": {
@ -408,6 +411,28 @@
"sprintf-js": "^1.1.1"
}
},
"node_modules/@nativescript/types": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@nativescript/types/-/types-8.0.0.tgz",
"integrity": "sha512-xfVLHZ4L0T7/Y4v+BBmH+GBvYRqYtasi8YaG4QV5oZPLKu2sBGjQkhME3ghx/FTh+0QRwMbSU8FJKkyK35rR3A==",
"dev": true,
"dependencies": {
"@nativescript/types-android": "8.0.0",
"@nativescript/types-ios": "8.0.0"
}
},
"node_modules/@nativescript/types-android": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@nativescript/types-android/-/types-android-8.0.0.tgz",
"integrity": "sha512-4b/RHhXjX/KLLNLiuCCOWNFnXhK5/3+mGkO/eXJbY1DbCDol4Fv8hbpRHridrhwihZAvqE0rVi5RlLFCtS2TBg==",
"dev": true
},
"node_modules/@nativescript/types-ios": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@nativescript/types-ios/-/types-ios-8.0.0.tgz",
"integrity": "sha512-QarxaXGN+T+33kDC+FtIY1b3xgHHfJODtXqbTQJxxV4HPiCx8dEDTT746xkQtH8j1F/92Q3oY4h0B5HhJS0QvQ==",
"dev": true
},
"node_modules/@nativescript/webpack": {
"version": "5.0.0-beta.6",
"resolved": "https://registry.npmjs.org/@nativescript/webpack/-/webpack-5.0.0-beta.6.tgz",
@ -1818,9 +1843,9 @@
"dev": true
},
"node_modules/electron-to-chromium": {
"version": "1.3.713",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.713.tgz",
"integrity": "sha512-HWgkyX4xTHmxcWWlvv7a87RHSINEcpKYZmDMxkUlHcY+CJcfx7xEfBHuXVsO1rzyYs1WQJ7EgDp2CoErakBIow==",
"version": "1.3.715",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.715.tgz",
"integrity": "sha512-VCWxo9RqTYhcCsHtG+l0TEOS6H5QmO1JyVCQB9nv8fllmAzj1VcCYH3qBCXP75/En6FeoepefnogLPE+5W7OiQ==",
"dev": true
},
"node_modules/emoji-regex": {
@ -2583,9 +2608,9 @@
}
},
"node_modules/javascript-stringify": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/javascript-stringify/-/javascript-stringify-2.0.1.tgz",
"integrity": "sha512-yV+gqbd5vaOYjqlbk16EG89xB5udgjqQF3C5FAORDg4f/IS1Yc5ERCv5e/57yBcfJYw05V5JyIXabhwb75Xxow==",
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/javascript-stringify/-/javascript-stringify-2.1.0.tgz",
"integrity": "sha512-JVAfqNPTvNq3sB/VHQJAFxN/sPgKnsKrCwyRt15zwNCdrMMJDdcEOdubuy+DuJYYdm0ox1J4uzEuYKkN+9yhVg==",
"dev": true
},
"node_modules/jest-worker": {
@ -2966,7 +2991,8 @@
"node_modules/nativescript-vue": {
"version": "2.9.0",
"resolved": "https://registry.npmjs.org/nativescript-vue/-/nativescript-vue-2.9.0.tgz",
"integrity": "sha512-bu7ifi/953805c6dwEsiPgkPadEdsCqAZVgqe0ir7kBpdEkiodVuDtEb8F8n9c36ka8zqWw9GBx+STCe19hg2Q=="
"integrity": "sha512-bu7ifi/953805c6dwEsiPgkPadEdsCqAZVgqe0ir7kBpdEkiodVuDtEb8F8n9c36ka8zqWw9GBx+STCe19hg2Q==",
"license": "MIT"
},
"node_modules/nativescript-vue-template-compiler": {
"version": "2.9.0",
@ -4228,6 +4254,19 @@
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.0.3.tgz",
"integrity": "sha512-uZtkfKblCEQtZKBF6EBXVZeQNl82yqtDQdv+eck8u7tdPxjLu2/lp5/uPW+um2tpuxINHWy3GhiccY7QgEaVHQ=="
},
"node_modules/typescript": {
"version": "4.2.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.4.tgz",
"integrity": "sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=4.2.0"
}
},
"node_modules/uniq": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz",
@ -5111,6 +5150,28 @@
"sprintf-js": "^1.1.1"
}
},
"@nativescript/types": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@nativescript/types/-/types-8.0.0.tgz",
"integrity": "sha512-xfVLHZ4L0T7/Y4v+BBmH+GBvYRqYtasi8YaG4QV5oZPLKu2sBGjQkhME3ghx/FTh+0QRwMbSU8FJKkyK35rR3A==",
"dev": true,
"requires": {
"@nativescript/types-android": "8.0.0",
"@nativescript/types-ios": "8.0.0"
}
},
"@nativescript/types-android": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@nativescript/types-android/-/types-android-8.0.0.tgz",
"integrity": "sha512-4b/RHhXjX/KLLNLiuCCOWNFnXhK5/3+mGkO/eXJbY1DbCDol4Fv8hbpRHridrhwihZAvqE0rVi5RlLFCtS2TBg==",
"dev": true
},
"@nativescript/types-ios": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@nativescript/types-ios/-/types-ios-8.0.0.tgz",
"integrity": "sha512-QarxaXGN+T+33kDC+FtIY1b3xgHHfJODtXqbTQJxxV4HPiCx8dEDTT746xkQtH8j1F/92Q3oY4h0B5HhJS0QvQ==",
"dev": true
},
"@nativescript/webpack": {
"version": "5.0.0-beta.6",
"resolved": "https://registry.npmjs.org/@nativescript/webpack/-/webpack-5.0.0-beta.6.tgz",
@ -6174,9 +6235,9 @@
"dev": true
},
"electron-to-chromium": {
"version": "1.3.713",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.713.tgz",
"integrity": "sha512-HWgkyX4xTHmxcWWlvv7a87RHSINEcpKYZmDMxkUlHcY+CJcfx7xEfBHuXVsO1rzyYs1WQJ7EgDp2CoErakBIow==",
"version": "1.3.715",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.715.tgz",
"integrity": "sha512-VCWxo9RqTYhcCsHtG+l0TEOS6H5QmO1JyVCQB9nv8fllmAzj1VcCYH3qBCXP75/En6FeoepefnogLPE+5W7OiQ==",
"dev": true
},
"emoji-regex": {
@ -6751,9 +6812,9 @@
"dev": true
},
"javascript-stringify": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/javascript-stringify/-/javascript-stringify-2.0.1.tgz",
"integrity": "sha512-yV+gqbd5vaOYjqlbk16EG89xB5udgjqQF3C5FAORDg4f/IS1Yc5ERCv5e/57yBcfJYw05V5JyIXabhwb75Xxow==",
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/javascript-stringify/-/javascript-stringify-2.1.0.tgz",
"integrity": "sha512-JVAfqNPTvNq3sB/VHQJAFxN/sPgKnsKrCwyRt15zwNCdrMMJDdcEOdubuy+DuJYYdm0ox1J4uzEuYKkN+9yhVg==",
"dev": true
},
"jest-worker": {
@ -7963,6 +8024,12 @@
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.0.3.tgz",
"integrity": "sha512-uZtkfKblCEQtZKBF6EBXVZeQNl82yqtDQdv+eck8u7tdPxjLu2/lp5/uPW+um2tpuxINHWy3GhiccY7QgEaVHQ=="
},
"typescript": {
"version": "4.2.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.4.tgz",
"integrity": "sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==",
"dev": true
},
"uniq": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz",

View file

@ -31,8 +31,11 @@
},
"devDependencies": {
"@nativescript/android": "8.0.0",
"@nativescript/types": "^8.0.0",
"@nativescript/webpack": "beta",
"@types/node": "^14.14.37",
"nativescript-vue-template-compiler": "~2.9.0",
"sass": "^1.32.8"
"sass": "^1.32.8",
"typescript": "^4.2.4"
}
}

25
tsconfig.json Normal file
View file

@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es2017",
"module": "esnext",
"moduleResolution": "node",
"lib": ["dom", "es2017"],
"sourceMap": true,
"noEmitHelpers": true,
"importHelpers": true,
"baseUrl": ".",
"paths": {
"~/*": ["app/*"],
"@/*": ["app/*"]
},
"typeRoots": ["types"],
"types": ["node"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true
},
"include": ["app", "types"],
"exclude": ["node_modules", "platforms"]
}

1
types/references.d.ts vendored Normal file
View file

@ -0,0 +1 @@
/// <reference path="../node_modules/@nativescript/types/index.d.ts" />

4
types/shims.vue.d.ts vendored Normal file
View file

@ -0,0 +1,4 @@
declare module '*.vue' {
import Vue from 'vue'
export default Vue
}

View file

@ -1,357 +1,7 @@
const { join, relative, resolve, sep } = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const TerserPlugin = require('terser-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const NsVueTemplateCompiler = require('nativescript-vue-template-compiler');
const nsWebpack = require('@nativescript/webpack');
const nativescriptTarget = require('@nativescript/webpack/nativescript-target');
const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin');
const hashSalt = Date.now().toString();
const webpack = require('@nativescript/webpack')
const TerserPlugin = require('terser-webpack-plugin')
module.exports = (env) => {
const platform = env && ((env.android && 'android') || (env.ios && 'ios') || env.platform);
if (!platform) {
throw new Error('You need to provide a target platform!');
}
const platforms = ['ios', 'android'];
const projectRoot = __dirname;
if (env.platform) {
platforms.push(env.platform);
}
// Default destination inside platforms/<platform>/...
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
const {
// The 'appPath' and 'appResourcesPath' values are fetched from
// the nsconfig.json configuration file.
appPath = 'app',
appResourcesPath = 'app/App_Resources',
// You can provide the following flags when running 'tns run android|ios'
snapshot, // --env.snapshot
production, // --env.production
report, // --env.report
hmr, // --env.hmr
sourceMap, // --env.sourceMap
hiddenSourceMap, // --env.hiddenSourceMap
unitTesting, // --env.unitTesting
testing, // --env.testing
verbose, // --env.verbose
ci, // --env.ci
snapshotInDocker, // --env.snapshotInDocker
skipSnapshotTools, // --env.skipSnapshotTools
compileSnapshot, // --env.compileSnapshot
appComponents = [],
entries = {},
} = env;
const useLibs = compileSnapshot;
const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap;
const externals = nsWebpack.getConvertedExternals(env.externals);
const mode = production ? 'production' : 'development';
const appFullPath = resolve(projectRoot, appPath);
const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot });
let coreModulesPackageName = 'tns-core-modules';
const alias = env.alias || {};
alias['~/package.json'] = resolve(projectRoot, 'package.json');
alias['~'] = appFullPath;
alias['@'] = appFullPath;
alias['vue'] = 'nativescript-vue';
if (hasRootLevelScopedModules) {
coreModulesPackageName = '@nativescript/core';
alias['tns-core-modules'] = coreModulesPackageName;
}
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] };
const entryModule = nsWebpack.getEntryModule(appFullPath, platform);
const entryPath = `.${sep}${entryModule}`;
Object.assign(entries, { bundle: entryPath }, entries);
const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some((e) => e.indexOf('@nativescript') > -1);
if (platform === 'ios' && !areCoreModulesExternal && !testing) {
entries['tns_modules/inspector_modules'] = '@nativescript/core/inspector_modules';
}
console.log(`Bundling application for entryPath ${entryPath}...`);
let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
const itemsToClean = [`${dist}/**/*`];
if (platform === 'android') {
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`);
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`);
}
// Add your custom Activities, Services and other android app components here.
appComponents.push('@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity');
nsWebpack.processAppComponents(appComponents, platform);
const config = {
mode: mode,
context: appFullPath,
externals,
watchOptions: {
ignored: [
appResourcesFullPath,
// Don't watch hidden files
'**/.*',
],
},
target: nativescriptTarget,
// target: nativeScriptVueTarget,
entry: entries,
output: {
pathinfo: false,
path: dist,
sourceMapFilename,
libraryTarget: 'commonjs2',
filename: '[name].js',
globalObject: 'global',
hashSalt,
},
resolve: {
extensions: ['.vue', '.ts', '.js', '.scss', '.css'],
// Resolve {N} system modules from @nativescript/core
modules: [resolve(__dirname, `node_modules/${coreModulesPackageName}`), resolve(__dirname, 'node_modules'), `node_modules/${coreModulesPackageName}`, 'node_modules'],
alias,
// resolve symlinks to symlinked modules
symlinks: true,
},
resolveLoader: {
// don't resolve symlinks to symlinked loaders
symlinks: false,
},
node: {
// Disable node shims that conflict with NativeScript
http: false,
timers: false,
setImmediate: false,
fs: 'empty',
__dirname: false,
},
devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none',
optimization: {
runtimeChunk: 'single',
noEmitOnErrors: true,
splitChunks: {
cacheGroups: {
vendor: {
name: 'vendor',
chunks: 'all',
test: (module) => {
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName);
},
enforce: true,
},
},
},
minimize: Boolean(production),
minimizer: [
new TerserPlugin({
parallel: true,
cache: !ci,
sourceMap: isAnySourceMapEnabled,
terserOptions: {
output: {
comments: false,
semicolons: !isAnySourceMapEnabled,
},
compress: {
// The Android SBG has problems parsing the output
// when these options are enabled
collapse_vars: platform !== 'android',
sequences: platform !== 'android',
// For v8 Compatibility
keep_infinity: true, // for V8
reduce_funcs: false, // for V8
// custom
drop_console: production,
drop_debugger: true,
global_defs: {
__UGLIFIED__: true,
},
},
keep_fnames: true,
// Required for Element Level CSS, Observable Events, & Android Frame
keep_classnames: true,
},
}),
],
},
module: {
rules: [
{
include: [join(appFullPath, entryPath + '.js'), join(appFullPath, entryPath + '.ts')],
use: [
// Require all Android app components
platform === 'android' && {
loader: '@nativescript/webpack/helpers/android-app-components-loader',
options: { modules: appComponents },
},
{
loader: '@nativescript/webpack/bundle-config-loader',
options: {
registerPages: true, // applicable only for non-angular apps
loadCss: !snapshot, // load the application css if in debug mode
unitTesting,
appFullPath,
projectRoot,
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform),
},
},
].filter((loader) => Boolean(loader)),
},
{
test: /[\/|\\]app\.css$/,
use: [
'@nativescript/webpack/helpers/style-hot-loader',
{
loader: '@nativescript/webpack/helpers/css2json-loader',
options: { useForImports: true },
},
],
},
{
test: /[\/|\\]app\.scss$/,
use: [
'@nativescript/webpack/helpers/style-hot-loader',
{
loader: '@nativescript/webpack/helpers/css2json-loader',
options: { useForImports: true },
},
'sass-loader',
],
},
{
test: /\.css$/,
exclude: /[\/|\\]app\.css$/,
use: ['@nativescript/webpack/helpers/style-hot-loader', '@nativescript/webpack/helpers/apply-css-loader.js', { loader: 'css-loader', options: { url: false } }],
},
{
test: /\.scss$/,
exclude: /[\/|\\]app\.scss$/,
use: ['@nativescript/webpack/helpers/style-hot-loader', '@nativescript/webpack/helpers/apply-css-loader.js', { loader: 'css-loader', options: { url: false } }, 'sass-loader'],
},
{
test: /\.js$/,
loader: 'babel-loader',
},
{
test: /\.ts$/,
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
allowTsInNodeModules: true,
compilerOptions: {
declaration: false,
},
getCustomTransformers: (program) => ({
before: [require('@nativescript/webpack/transformers/ns-transform-native-classes').default],
}),
},
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
compiler: NsVueTemplateCompiler,
},
},
],
},
plugins: [
// ... Vue Loader plugin omitted
// make sure to include the plugin!
new VueLoaderPlugin(),
// Define useful constants like TNS_WEBPACK
new webpack.DefinePlugin({
'global.TNS_WEBPACK': 'true',
'global.isAndroid': platform === 'android',
'global.isIOS': platform === 'ios',
TNS_ENV: JSON.stringify(mode),
process: 'global.process',
}),
// Remove all files from the out dir.
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: itemsToClean,
verbose: !!verbose,
}),
// Copy assets
new CopyWebpackPlugin([{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore),
new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'),
// For instructions on how to set up workers with webpack
// check out https://github.com/nativescript/worker-loader
new NativeScriptWorkerPlugin(),
new nsWebpack.PlatformFSPlugin({
platform,
platforms,
}),
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
new nsWebpack.WatchStateLoggerPlugin(),
],
};
if (unitTesting) {
config.module.rules.push(
{
test: /-page\.js$/,
use: '@nativescript/webpack/helpers/script-hot-loader',
},
{
test: /\.(html|xml)$/,
use: '@nativescript/webpack/helpers/markup-hot-loader',
},
{ test: /\.(html|xml)$/, use: '@nativescript/webpack/helpers/xml-namespace-loader' }
);
}
if (report) {
// Generate report files for bundles content
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
generateStatsFile: true,
reportFilename: resolve(projectRoot, 'report', `report.html`),
statsFilename: resolve(projectRoot, 'report', `stats.json`),
})
);
}
if (snapshot) {
config.plugins.push(
new nsWebpack.NativeScriptSnapshotPlugin({
chunk: 'vendor',
requireModules: ['@nativescript/core/bundle-entry-points'],
projectRoot,
webpackConfig: config,
snapshotInDocker,
skipSnapshotTools,
useLibs,
})
);
}
if (hmr) {
config.plugins.push(new webpack.HotModuleReplacementPlugin());
}
return config;
};
webpack.init(env)
return webpack.resolveConfig()
}