Andrew Thomson
Andrew Thomson

Reputation: 4810

Use requirejs to build project to single file and then optimize it (creating source map)

I'm looking to use Requirejs (v2.1.8) to create a source map of my minified/optimized project.

I've been able to successfully do this by adding the following variables to my build file:

However, this creates a map and source file for every single JS file that makes up my application. What i am looking to do is to use Requirejs to combine all my JS source files into a single file (without optimising) and then to optimise this resulting file and to create a source map for it.

This will therefore leave me with three files:

  1. The optimized JS (for use in production).
  2. A JS file which includes all my JS source files in a human readable format.
  3. The mapping file which can be used to map 1 and 2 together.

I understand that support for source maps in Requirejs is in the experimental stage. I was wondering if anybody knew of a option to tell the compiler to do what i've described above?

If not, does anybody know how to use the Requirejs compiler to optimise a single JS file (which has already been built using Requirejs but with the optimize setting set to none) which also creates a source map at the same time?

Upvotes: 1

Views: 482

Answers (1)

Andrew Thomson
Andrew Thomson

Reputation: 4810

It seems that i have misunderstood what requirejs does when it optimizes and creates source maps.

It turns out requirejs creates a map and source file for every single JS file in your project as well as a source map for the optimized JS file (typically called main.js). If you're only after a source map for the main.js file then you can delete all the others.

Hope this helps somebody else!

Upvotes: 1

Related Questions