jquery / jquery/requirejs-memfiles

Not copying to build directory

Open
#1 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Hi there,

Thanks for creating this library.

I just tried to get this working and encountered a problem - not sure if it's memfiles or if its just how rjs works.

Given the example in the Readme (which works when the file doesn't have any dependencies):

var fs = require( "js" );
var requirejs = require( "requirejs-memfiles" );

var files = {
  "main.js": fs.readFileSync( "./main.js" ),
  ...
}

requirejs.setFiles( files, function( done ) {
  requirejs.optimize({
    appDir: ".",
    baseUrl: ".",
    dir: "dist",
    modules: [{
        name: "output",
        include: "main",
        create: true
    }]
  }, function() {
    var output = files[ "dist/output.js" ];
    ...
    done();

  }, function( error ) {
    // handle error
    ...
    done();

  });
});

Now, if we set main.js content to look like the following so it has a dependency to another module:


define("Main", ["require", "exports", "ModuleA"], function (require, exports, moduleA) {
    "use strict";

    
});

And then you include this additional file:

var moduleAContents = "define(\"ModuleA\", [\"require\", \"exports\"], function (require, exports) {\r\n    \"use strict\";\r\n});";

var files = {
  "main.js": fs.readFileSync( "./main.js" ),
   "ModuleA.js": moduleAContents,
}

Now, during the optimisation, the rjs optimiser requests a file from the in memory files on the path: dist/ModuleA.js . This file doesn't exist.

Rjs doesn't appear to copy the ModuleA file from its original location, to the build directory, and then it requests it from the build directory location - and it isn't there.

If I change the "modules" config to list each module independently -like this:

modules: [{
        name: "Main",
           },{
        name: "ModuleC",
           }]


When I do that, rjs now copies each of the files to the built location, and optimisation succeeds.

In the case that I wish to optimise a single file, that has dependencies, i'm not sure the best way to do this using memfiles at the moment due to this issue.

Any pointers greatly appreciated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the README example and the requirejs.setFiles() path described in the report. Reproduce optimization with main.js depending on ModuleA.js and inspect why the optimizer requests dist/ModuleA.js without copying it. Done means the single-module optimization succeeds with in-memory dependencies and the relevant behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.