Coder Social home page Coder Social logo

Comments (9)

lucasbento avatar lucasbento commented on June 1, 2024 2

alright, cool, thank you @mrsteele!

from dotenv-webpack.

mrsteele avatar mrsteele commented on June 1, 2024 1

Feel free to simply remove the safe param. This would remove the safety checks since you just want to use the variables provided by your .env file.

from dotenv-webpack.

mrsteele avatar mrsteele commented on June 1, 2024

Just to make sure I understand, you have something similar to:

// webpack.config.js
const Dotenv = require('dotenv-webpack');
const { DefinePlugin } = require('webpack'); 

module.exports = {
  ...
  plugins: [
    new DefinePlugin({
        // ...
    }),
    new Dotenv({
      path: './.my.env', // if not simply .env
      safe: true // lets load the .env.example file as well
    })
  ]
  ...
};

Can you tell me exactly what error / unexpected behavior occurs with this?

from dotenv-webpack.

lucasbento avatar lucasbento commented on June 1, 2024

Yes, sorry I didn't include any examples, something like this:

new webpack.DefinePlugin({
  'process.env': {
    NODE_ENV: '"production"'
  }
}),
new dotEnv({
  path: './env',
  safe: './env',
}),

I use the same path for safe and path because I don't use a .env.example file.

from dotenv-webpack.

mrsteele avatar mrsteele commented on June 1, 2024

Okay, looking at your example, i'm betting the following is happening:

If you look at this line:

https://github.com/mrsteele/dotenv-webpack/blob/master/src/index.js#L51

You will see I am assigning a variable like you on process.env.

Since you just have the one, have you tried changing your DefinePlugin to use?:

new webpack.DefinePlugin({
  'process.env.NODE_ENV': "production"
}),
new dotEnv({
  path: './env',
  safe: './env',
}),

This should help in the definition phase.

from dotenv-webpack.

mrsteele avatar mrsteele commented on June 1, 2024

Although that wouldn't explain why it all worked as expected when you did one before the other... Are you sure it all worked when you changed the order?

from dotenv-webpack.

lucasbento avatar lucasbento commented on June 1, 2024

I'm gonna try what you just said, that does make sense.

Yes, it is running on production already. :)

from dotenv-webpack.

lucasbento avatar lucasbento commented on June 1, 2024

@mrsteele: it works in the way that you just said.

I guess webpack.DefinePlugin has an incremental way of defining new env vars.

from dotenv-webpack.

mrsteele avatar mrsteele commented on June 1, 2024

Yeah, sorry about the issues but if anything maybe a good idea to open an issue with the DefinePlugin with webpack.

from dotenv-webpack.

Related Issues (20)

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.