Skip to content

Partial files for better modularization #5085

Closed
@kripod

Description

@kripod

Inspired by the @import function of SASS.

I would like to propose a mechanism for creating partial files, which are not compiled by default, but embedded into files which reference them. It's just like bundling, but with less hassle and in a more unified approach.

As a brief example, suppose that we have 4 files:

  • index.ts
  • user.ts
  • _auth.ts
  • _position.ts

The index.ts and user.ts files can reference contents of a partial file by using simple imports. For example, if we want index.ts to reference _auth.ts and _position.ts, use the following code in the non-partial index.ts file:

import auth = require('auth');
import position = require('position');

The content of partial files should be copied and instantly evaluated in their container file. For instance, whether we would also like to use the _position.ts partial file in user.ts, use an import just like above:

import position = require('position');

Although this may seem like a regular import, it's basically an include function which copies the partial file's full content at the place desired. That means, partial files should not be reused in multiple containers, but should be used for code organisation purposes. When both index.ts and user.ts are referenced in a HTML file, the content of _position.ts will be duplicated and inserted into the 2 containers separately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions