1

I minified my JS file using grunt task runner.

I have a minified file with me but i dont know how to run my project using this minified JS file.

I first 'concat' and then 'uglify'. Now, i don't know how to run.

I am using require and backbone in my Javascript project.

Code: index.html

<!DOCTYPE HTML>
<html>
<head>
    <title>Minify POC </title>
</head>
<body>
<script src='main'>
</script>  

</body>
</html>

Minified JS file :

/*! Example 10-06-2014 */
var a=10,b=20,c=a+b;console.log("Addition of c ::"+c);

Original file

var a = 10;
var b = 20;
var c = a+ b;
console.log("Addition of c ::"+c);
Megha
  • 1,581
  • 2
  • 18
  • 33
  • 1
    Maybe you might wanna show some code or commands that demonstrate how you're trying to run them, that way we can help you easier? Guessing sucks, both for you as well as all the answerers. :D Hope this helps! – jamesmortensen Jun 10 '14 at 07:21
  • u run the same, the essential content didnt change – john Smith Jun 10 '14 at 07:21
  • 1
    For instance, how do you run them when they're *not* minified? – jamesmortensen Jun 10 '14 at 07:22
  • ya essential content is not change. But, in my src folder i replaced original file with one minified file. And i am getting below error :Uncaught Error: Script error for: main – Megha Jun 10 '14 at 07:23
  • Do I need to update to every HTML pages. As my contains so my HTML pages. – Megha Jun 10 '14 at 07:26

2 Answers2

0

You need an HTML file to point to the new script. Uglify to a different directory and put a copy of your HTML there, but swap out the script tags...

philwills
  • 985
  • 4
  • 8
0

A usual RequireJS entry point looks like this:

<script data-main="main" src="lib/require.js"></script>

Depending on how your HTML is served, you can add require config to point at the built version. For instance if your HTML is served dynamically, you can add a script block that's included in the page based on environment config:

<script>
    var require = {paths: {main: "path/to/built/main.js"}};
</script>
<script data-main="main" src="lib/require.js"></script>

Now, any reference to main will load the built JS, rather than the unbuilt one.

cmbuckley
  • 40,217
  • 9
  • 77
  • 91