Code Monkey home page Code Monkey logo

Comments (3)

aMarCruz avatar aMarCruz commented on August 20, 2024 1

This must works (I don't test it):

Read the object at compile time and send it to jscc in the values property of the options.

import thing from '../my-thing.js';

const processedCode = jscc(code, {
  values: { _THING: thing }
  // now `thing` is visible at compile-time
})

If you are using a plugin, for example w/rollup, do that in your rollup.config.js

from jscc.

smth avatar smth commented on August 20, 2024 1

Yes, that was what I was looking for; and it works, thanks!

Note: comment should maybe say "now _THING is visible..."

from jscc.

aMarCruz avatar aMarCruz commented on August 20, 2024

@smth , you are trying to get a runtime value with a compile-time tool.

I mean, jscc runs in its own space at compile time and does not know anything about the values of variables in the code it processes.

It uses JavaScript to decide which code block to include or exclude, or which text to replace in the code, but treats these code as simple text, does not evaluate it.

This behavior is similar to that of the C preprocessor, but it may be a strange concept for the JS world. I will put a note in the Readme about it, when have the time :)

Closing the issue now, thanks for your feedback.

from jscc.

Related Issues (8)

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.