sintaxi/harp

Load NodeJS library for compilation

jkjustjoshing opened this issue · 3 comments

I'm writing a Harp app that includes some D3 charts. This is the only client-side JavaScript that's currently being run in the browser, and I'm looking for a way to compile the D3 SVG output at compile-time, so the end webpage doesn't require any JavaScript (and also doesn't require the user loading the D3 library).

I tried <% d3 = require('./path/to/d3.js') %> and <% d3 = partial('./path/to/d3.js') %> but neither of them worked.

Is there a way to currently do this? If not, is this a feature other developers might find useful?

I'm not entirely certain what you are asking for, but can you tell me how you are working with harp? For example are you using harp cli or a NPM dependency?

I'm using the Harp CLI, running harp compile. Inside my .ejs file, I want to utilize code from a 3rd party library. For a simple example, let's say that I'm doing in my .ejs file:

<% items.forEach(function (item) {
%>    <div><%= item %></div>    <%
}) %>

but I want to use lodash -

<% _.forEach(items, function (item) {
%>    <div><%= item %></div>    <%
}) %>

How can I include lodash.js into my .ejs file so I can use lodash?

(this is a contrived example - I want to use a library that provides more value than lodash)

@jkjustjoshing this isn't an operation that you should be using .ejs for because it's a view layer tool. See this answer/comments on stackoverflow for more details.
how can I use lodash with ejs