1.0.8 • Published 5 years ago

node-to-browser v1.0.8

Weekly downloads
2
License
MIT
Repository
-
Last release
5 years ago

node-to-browser

MIT license pipeline status coverage report

Typescript transpile the import paths without based on any module resolver. So I wrote this node cli to convert all import path content found at {jsPath} folder to "{root}+{current import path}+{extension}". Also it is possible to replace content from import match using {replace} value.

The default configuration defined below:

module.exports = {
    root: "/",
    jsPath: "./dist",
    extension: ".js",
    replace: {
        regex: /\/src\//mg,
        value: "/dist/"
    }
};

You must use this command after tsc execution like below:

tsc && node-to-browser

Example

To convert all your import path from somethid like this "@my/module/dist/util" to "http://my.domain/js/node_modules/@my/module/dist/util.js", first you must create a configuration file at your project root named as "node.to.browser.js" with below content:

module.exports = {
    root: "http://my.domain/js/node_modules/",
    jsPath: "./my/js/files", // specify your javascript folder content path
    // extension: ".js" // by default this is already ".js" value
    replace: {
        regex: /\/mysources\//mg,
        value: "/build/"
    }
};

So when node-to-browser is executed will find all import path candidates to convert to desired format. If some match is found then is modified and saved.

So if you have this import definition:

import { Foo } from "@my/module/mysources/utils";
import { Foo } from "./common";

Before the node-to-browser execution yo will obtain this:

import { Foo } from "http://my.domain/js/node_modules/@my/module/build/utils.js";
import { Foo } from "./common.js";

The node-to-browser command execution output will show you a detailed result.

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago