Coder Social home page Coder Social logo

robinvdvleuten / preact-cli-plugin-env-vars Goto Github PK

View Code? Open in Web Editor NEW
34.0 2.0 2.0 48 KB

๐Ÿ›  Consume variables in your environment with the Preact CLI.

Home Page: https://npm.im/preact-cli-plugin-env-vars

License: MIT License

JavaScript 100.00%
plugin preact preact-cli

preact-cli-plugin-env-vars's Introduction

preact-cli-plugin-env-vars

Consume variables in your environment with the Preact CLI.

NPM version Build Status

Installation

$ npm i -D preact-cli-plugin-env-vars

And include in your project by creating a preact.config.js:

import envVars from 'preact-cli-plugin-env-vars';

export default function (config, env, helpers) {
  envVars(config, env, helpers);
}

Usage

The plugin allows to use any environment variables prefixed with PREACT_APP_ to be used within your script:

console.log(process.env.PREACT_APP_SECRET_CODE);

The environment variables are embedded during the build time.

Adding development Environment Variables in .env

To define permanent environment variables, create a file called .env in the root of your project:

PREACT_APP_SECRET_CODE=abcdef

These variables will act as the defaults if the machine does not explicitly set them. Please refer to the dotenv documentation for more details.

License

MIT ยฉ Robin van der Vleuten

preact-cli-plugin-env-vars's People

Contributors

robinvdvleuten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

preact-cli-plugin-env-vars's Issues

not working with old version of preact

i have preact version 8.2.9 and it gives an error like this:

TypeError: Cannot read property 'compilation' of undefined

my preact.config.js looks like this:

export default (config, env, helpers) => {
  envVars(config, env, helpers);

  return compose(
    asyncPlugin,
    addEmotionPlugin,
    configRules
  )(config, env);
};

any workaround to make the dependency works with old versions of preact?

TypeError: Cannot match against 'undefined' or 'null'.

I've been using 1.1.0 for a few months without issue.

When I upgraded to 1.2.0 and updated preact.config.js as per the doc, I keep getting this error on build:

Error: Error at /{preact-dir}/preact.config.js:
TypeError: Cannot match against 'undefined' or 'null'.

I get this same error whether my preact.config.js is verbatim from the doc:

import envVars from 'preact-cli-plugin-env-vars';

export default function (config, env, helpers) {
  envVars(config, env, helpers);
}

.... or with my customizations that were in the previous working version:

const envVars = require('preact-cli-plugin-env-vars')
const preactCliSwPrecachePlugin = require('preact-cli-sw-precache')

export default function (config, env, helpers) {

  envVars(config, env, helpers)

  const precacheConfig = {
    staticFileGlobs: [
      'app/css/**.css',
      'app/**.html',
      'app/images/**.*',
      'app/js/**.js'
    ],
    stripPrefix: 'app/',
    runtimeCaching: [{
      urlPattern: /this\\.is\\.a\\.regex/,
      handler: 'networkFirst'
    }]
  };

  return preactCliSwPrecachePlugin(config, precacheConfig)

}

Everything works fine again when I revert to 1.1.0 and change preact.config.js back to the way it was.

Any ideas on what I'm doing wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.