Giter VIP home page Giter VIP logo

Comments (7)

gopal-virtual avatar gopal-virtual commented on April 28, 2024 6

@ivanjeremic Any argument in the command line is converted to a key-value pair. So it will look something like

{
    "process.env.NODE_ENV": `"production"`
}

If you are struggling to set this up, use a starter-template instead.

from esbuild.

iamursky avatar iamursky commented on April 28, 2024 1

Solved by wrapping production in single quotes:

npx esbuild index.jsx --bundle --minify --outfile=out.min.js --define:process.env.NODE_ENV='production'

from esbuild.

iamursky avatar iamursky commented on April 28, 2024

When wrapping define in brackets as in the react example, the error is:

npx esbuild index.jsx --bundle --minify --outfile=out.min.js '--define:process.env.NODE_ENV="production"'
error: Use --outdir instead of --outfile when there are multiple entry points

And when not wrapping:

npx esbuild index.jsx --bundle --minify --outfile=out.min.js --define:process.env.NODE_ENV="production"
error: Invalid define: --define:process.env.NODE_ENV=production

OS: Windows x64
esbuild: [email protected]

from esbuild.

evanw avatar evanw commented on April 28, 2024

What shell is this? cmd.exe? WSL? Cygwin? Something else?

from esbuild.

iamursky avatar iamursky commented on April 28, 2024

I'm using cmder, it's using ConEmu under the hood.

package.json also need to be updated:

"scripts": {
    "build": "npm run build:prod",
    "build:dev": "esbuild src/index.jsx --bundle --define:process.env.NODE_ENV='development' --outfile=bundle.js",
    "build:prod": "esbuild src/index.jsx --bundle --define:process.env.NODE_ENV='production' --minify --outfile=bundle.min.js"
  }

from esbuild.

ivanjeremic avatar ivanjeremic commented on April 28, 2024

How would this look like when using a JavaScript config file?

require("esbuild")
 .build({
   entryPoints: ["app.jsx"],
   bundle: true,
   inject: ["./react-shim.js"],
   outfile: "out.js",
   define: process.env.NODE_ENV = "production",
 })
 .catch(() => process.exit(1));

from esbuild.

ivanjeremic avatar ivanjeremic commented on April 28, 2024

@ivanjeremic Any argument in the command line is converted to a key-value pair. So it will look something like

{
    "process.env.NODE_ENV": `"production"`
}

If you are struggling to set this up, use a starter-template instead.

I try to setup esbuild for using a react component library, specifically there is one hook I want to make public on NPM and since rollup and webpack are not so my taste I wanted to learn esbuild and use it for that npm package(react hook), Can esbuild be used for this?

from esbuild.

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.