Comments (6)
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.
@dpilafian
thanks u :)
i'll try to your code.
from gulp-file-include.
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.
@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.
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.
@dpilafian
i know :)
but how could i configuration GLOBAL variable in npm package.
from gulp-file-include.
Related Issues (20)
- Postfix
- Support recursive include? HOT 1
- Multiline in variable and json error HOT 1
- Can I use different styles for different source files?
- More error info
- How to loop array of objects if it is inside array of objects in the same JSON file?
- Filters documentation
- Is not difined in IF statement HOT 2
- Question: Extension support in vscode
- Include with part of the JSON HOT 1
- nested for loop, inner variable is not defined HOT 1
- Can html page files be generated in batches? HOT 1
- @@webRoot documentation HOT 4
- Invalid character error HOT 1
- Build only the files that will be changed
- Detect which file have an error
- Fix : invalid characters in JSON5 HOT 2
- json not work in loop HOT 1
- Pass variables to child include
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gulp-file-include.