JpCapdevila / sapper-environment

15 stars 5 forks source link

Doesn't work on server side #2

Open KamranKhan-Dev opened 4 years ago

KamranKhan-Dev commented 4 years ago

I think it's worth pointing out in the documentation that this package doesn't work on the server side. It does work when you're running sapper dev, but not when you're running the Express or Polka servers through node __sapper__/build.

topazrn commented 3 years ago

To make it work server side, do this:

server: {
        input: config.server.input(),
    output: config.server.output(),
    plugins: [
        replace({
            ...sapperEnv(),
            'process.browser': false,
            'process.env.NODE_ENV': JSON.stringify(mode)
        }),

Make sure that your env keys starts with SAPPER_APP like this SAPPER_APP_DB_HOST=localhost

kwiat1990 commented 3 years ago

@topazrn it doesn't seem to be working. An env variable, which does work in the client, stays undefined on the server.

topazrn commented 3 years ago

Hmm, weird. It works for me though. In multiple projects. Here's my rollup.config.js file in case you missed something. rollup.config.js.txt

kwiat1990 commented 3 years ago

@topazrn it sadly doesn't work for me. My rollup.config.js looks similar and the sapper-environment is installed as dependency.

kwiat1990 commented 3 years ago

@topazrn should it also work for node scripts, which can run separately?