# environment-switch-loader

> Replace the file to be exported.

Latest version **0.1.3** (published 2017-10-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install environment-switch-loader
pnpm add environment-switch-loader
yarn add environment-switch-loader
bun add environment-switch-loader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2017-10-18 |
| First published | 2017-10-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | sumin-seed |
| Keywords | angular-cli, replace, file, webpack, loader, environment, switch |

## Links

- npm: https://www.npmjs.com/package/environment-switch-loader
- Repository: https://github.com/SuminSEED/environment-switch-loader
- Homepage: https://github.com/SuminSEED/environment-switch-loader#readme
- Issues: https://github.com/SuminSEED/environment-switch-loader/issues
- npm.io page: https://npm.io/package/environment-switch-loader

## Dependencies (1)

- [loader-utils](https://npm.io/package/loader-utils.md) ^1.1.0

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 0.1.3 (latest) — 2017-10-18
- 0.1.2 — 2017-10-18
- 0.1.1 — 2017-10-17
- 0.1.0 — 2017-10-17
- 0.0.9 — 2017-10-16
- 0.0.8 — 2017-10-16
- 0.0.7 — 2017-10-16
- 0.0.6 — 2017-10-16
- 0.0.5 — 2017-10-15
- 0.0.3 — 2017-10-15
- 0.0.2 — 2017-10-15
- 0.0.1 — 2017-10-15

## README

# Environment Switch Loader

Replace the file to be exported.

## Install

```bash
npm install --save-dev environment-switch-loader
```

## Usage

```js
{
    test: /\.js$/,
    use: [
        {
            loader: 'environment-switch-loader',
            options: {
                env: process.env.NODE_ENV,
                environmentSource: './src/environments/environment.js',
                environments: {
                    'prodction': './src/environments/environment.prod.js'
                }
            }
        }
    ]
}

{
    test: /\.js$/,
    use: [
        {
            loader: 'environment-switch-loader',
            options: {
                env: process.env.NODE_ENV,
                environmentSource: './src/environments/environment.js',
                environments: function(env, environmentSource, resourcePath) {
                    return `./src/environments/environment.${env}.js`;
                }
            }
        }
    ]
}

var environment = require('environments/environment');
```

### Be careful when using ts-loader.

In order to prevent ts-loader from rebuilding dependencies, the transpileOnly flag needs to be set to true.

This invalidates type checking by ts-loader.

But you guys are supplemented by editor, right?

```js
{
    test: /\.ts$/,
    use: [
        {
            loader: "ts-loader",
            options: {
                transpileOnly: true
            }
        },
        {
            loader: 'environment-switch-loader',
            options: {
                env: process.env.NODE_ENV,
                environmentSource: './src/environments/environment.ts',
                environments: {
                    'prodction': './src/environments/environment.prod.ts'
                }
            }
        }
    ]
}

{
    test: /\.ts$/,
    use: [
        {
            loader: "ts-loader",
            options: {
                transpileOnly: true
            }
        },
        {
            loader: 'environment-switch-loader',
            options: {
                env: process.env.NODE_ENV,
                environmentSource: './src/environments/environment.ts',
                environments: function(env, environmentSource, resourcePath) {
                    return `./src/environments/environment.${env}.ts`;
                }
            }
        }
    ]
}

import { environment } from 'environments/environment';
```

---
_Source: https://npm.io/package/environment-switch-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
