Single Page App

A single page application (SPA) is a website or web application that dynamically rewrites a current web page with new data from a web server, instead of the default method of a web browser loading entire new pages. Ink is capable of creating reactive SPAs using Webpack and TypeScript. First install the following Ink packages. npm install --save-dev @stackpress/ink @stackpress/ink-loader Then, install the following TypeScript packages. npm install --save-dev @types/node ts-loader ts-node typescript Then, install the following Webpack packages. npm install --save-dev html-webpack-plugin webpack-dev-server webpack webpack-cli Next create the following files and directories.
src/client.ts src/app.ink index.html webpack.config.js tsconfig.json package.json
src
app.ink client.ts index.html package.json tsconfig.json webpack.config.js
const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { // https://webpack.js.org/concepts/entry-points/#multi-page-application entry: { index: './src/client.ts' }, output: { path: path.resolve(__dirname, './dist'), filename: '[name].bundle.js', }, module: { rules: [ { test: /.ink$/, use: { loader: '@stackpress/ink-loader', options: { minify: false } }, exclude: /node_modules/, }, { test: /.ts$/, use: 'ts-loader', exclude: /node_modules/, }, ], }, resolve: { extensions: ['.js', '.ts', '.ink'], }, // https://webpack.js.org/configuration/dev-server/ devServer: { port: 8080 }, plugins: [ new HtmlWebpackPlugin({ title: 'Ink', template: "index.html", }) ] };
To test the SPA and see the results, run the following command in terminal. npm run dev