1

I have an app built with Node-Gulp-Webpack.

I have an external JavaScript file external.js that is not local to my app, but I want to be able to require it in my app. This file is on a path for which there is an environment variable named MY_PATH.

How can I include this external.js as-is in my build without making a Node module out of it?

So far, this does not work and doesn't return a useful error message:

var external = require(process.env.MY_PATH + '/external.js');
3
  • Are you require'ing this external file into a client side file, or in your nodejs app? Commented Jun 30, 2015 at 22:59
  • Is process.env.MY_PATH being resolved correctly? What is the output of console.log(process.env.MY_PATH)? Commented Jul 1, 2015 at 16:10
  • I created a env variable called MY_PATH set to a path and used require(process.env.MY_PATH) and it worked using the node REPL, it didn't work at first because I had to open a new cmd prompt. Commented Jul 1, 2015 at 16:16

1 Answer 1

1

Use gulp-remote-src, the example:

var gulp = require('gulp');
var uglify = require('gulp-uglify');
var remoteSrc = require('gulp-remote-src');

gulp.task('remote', function() { 
    remoteSrc(['app.js', 'jquery.js'], {
        base: 'http://myapps.com/assets/',
    })
    .pipe(uglify())
    .pipe(gulp.dest('./dist/'));
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.