Coder Social home page Coder Social logo

Comments (6)

dpilafian avatar dpilafian commented on August 25, 2024 2

Here's a real example that I think does what you're asking to do.

It reads package.json into an object and then passes that into the fileInclude() function.

gulpfile.js

import { readFileSync } from 'fs';
...
const pkg = JSON.parse(readFileSync('./package.json'));
...
const webContext = {
   pkg:          pkg,
   released:     released,
   minorVersion: minorVersion,
   gzipSize:     '8 kb gzip',
   title:        pkg.description,  //default page title
   youTube:      linkInfo.youTube,
   jsFiddle:     linkInfo.jsFiddle
   };
...
         gulp.src(['website/static/**/*.html', 'website/root/**/*.html'])
            .pipe(fileInclude({ basepath: '@root', indent: true, context: webContext }))

Now you have access from the templates to everything in package.json.

See the full file at:
https://github.com/dnajs/dna.js/blob/master/gulpfile.js#L38

from gulp-file-include.

lacomparte avatar lacomparte commented on August 25, 2024 1

@dpilafian
thanks u :)
i'll try to your code.

from gulp-file-include.

dpilafian avatar dpilafian commented on August 25, 2024

A web page's URL is dependent on where the page is deployed and how the web server is configured, so the full URL is generally not known when the HTML is generated.

An example use case might help clarify what you're trying to accomplish.

If you actually know the URL ahead of time, you could just create a regular variable named @@urlRoot and set it just like any other regular variable. See the @@name and @@age examples in the Readme.md.

from gulp-file-include.

lacomparte avatar lacomparte commented on August 25, 2024

@dpilafian
thx for your comment.

i wanna configuration that global var @@some in package

ex)

// some config..
@@some = 'http://path';

// code
<img src="@@some/image.png">

// parsing
<img src="http://path/image.png">

from gulp-file-include.

dpilafian avatar dpilafian commented on August 25, 2024

You should be able to do that by setting the some variable in the @@include statement, like:

<!DOCTYPE html>
<html>
  <body>
  @@include("./var.html", { "some": "https://example.com/path" })
  </body>
</html>

from gulp-file-include.

lacomparte avatar lacomparte commented on August 25, 2024

@dpilafian
i know :)
but how could i configuration GLOBAL variable in npm package.

from gulp-file-include.

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.