@selfage/web_page_mapping
Install
npm install @selfage/web_page_mapping
Overview
Written in TypeScript and compiled to ES6 with inline source map & source. See @selfage/tsconfig for full compiler options. Provides message descriptors for parsing a JSON config file which contains the mapping from url paths to TypeScript files, which is designed specifically for single page applications (SPA).
Note that you do not need this package to write the JSON config. You only need it for reading and parsing it into a type-safe object.
Mapping config
An example named as web_page_mapping_config.json
can look like the following.
{
"pathsToTs": [{
"path": "/some_page",
"ts": "./simple_page",
"js": "./simple_page_bin"
}],
"notFoundTs": {
"path": "/some_not_found",
"ts": "./simple_not_found",
"ts": "./simple_not_found_bin"
},
"pathsToStaticDirectories": [{
"path": "/some_static",
"dir": "./simple_static"
}],
"sourceMapSupport": {
"path": "/some_source_map_support",
"js": "./browser-source-map-support"
}
}
It's essentially a WebPageMapping
object, which you can refer to web_page_mapping.json or its equivalent web_page_mapping.ts for detailed explanations of WebPageMapping
and each field of it.
Simply speaking, a url path is expecting to serve a web page with browserified JavaScript file from an entry TypeScript file. E.g., /some_page
is mapping to ./simple_page.ts
which should be compiled and browserified into ./some_page_bin.js
.
Parse the example config
To get the type-safe WebPageMapping
object from the config file, do the following.
import fs = require('fs');
import { parseMessage } from '@selfage/message/parser'; // Installed as the dependency.
import { WEB_PAGE_MAPPING } from '@selfage/web_page_mapping';
let jsonString = fs.readFileSync('web_page_mapping_config.json').toString();
let mapping = parseMessage(JSON.parse(jsonString), WEB_PAGE_MAPPING);
// Now `mapping` is of type `WebPageMapping`.