Angularjs respectively Requirejs do the files merge compressed those pits

Source: Internet
Author: User

Be careful! Angularjs Merge Requirejs Do file leave compressed those pits

Be careful! Angularjs merge Requirejs do files away from the compression of those pits , everyone is doing files away from compression time must pay attention to, fun users can refer to
The project is using the ANGULARJS framework, with Requirejs to do asynchronous module loading (AMD), is doing files away from compression, encountered some pits, some just done, but not white reason.

Those pits
1. The paths inside the build.js must be equated with the main.js inside.

This build.js is the r.js to use the settings file, and Main.js is Requirejs's main file. Is leaving the compression hour, Build.js file inside also need to write paths, and still with main.js same, I am very strange why can't identify main inside of the require.config paths, lest leave the time also will paths copy come (I tried build.js inside no paths, is Not to leave). (-_-!!! )

2. Some dependent libraries are necessary to write the whole thing about the road to do away.

In the project, I use a called layer of the third-party library (library thus Requirejs define write), a head only to do pioneering hour, is paths set up the road, the use of this library only need to use a short name (define depends on the hour). But is doing leave hour, unexpectedly hint file not exist (because indirectly take abbreviation to spell file place), cannot under can only modify this library use method, all apply to this library all write the whole absolutely about the road, this hour pioneering and do leave is not wrong.

3. After leaving the operation can be run, combined with compression will not.

This is the most moderated title, the most moderated title, and the most moderated title. The file is out of compression, the use of the file hour, angularjs operation is not individual, always report module initialization, Failed to instantiate module co sister on due to:error: [$injector: UNPR] Unknown Provider:e, to.

650) this.width=650; "title=" 24900.png "src=" http://s2.51cto.com/wyfs02/M00/7D/3A/wKiom1bipOCwJ1YnAAHECgMu_ Pe050.png "alt=" Wkiom1bipocwj1ynaahecgmu_pe050.png "/>

A very critical point is that no compression can be used, once compressed (with the default compression), the application will be error. In order to consider certain tools to be "crushed", some articles on the web are said to be necessary before how to write Angularjs cntroller, directive, etc., the use of the concept of the string.

CO sister Onmodule.controller ("Broswerctrl", ["$scope", "$sce", Function ($scope, $SCE) {

But my whole application is a concept, and there is no time to inject fault into it. At first, can not be under, you can only set Mangle:false, not mixed variable name, how to do, leaving the compressed file will be able to use the accurate!!!

PS: The complexity of the argument is that leaving the compression can be, variable name is not mixed (always feel strange), I think the title is temporarily without solution.

4. The second layer of require, do leave the hour, is not actually come in.

Metaphor is mian.js inside how to load module, is leaving the hour will see the second layer of require and not be left to.

Require (["Co Sister on"], function () {
Require (["angular", "LOGIN"], function (angular) {
//....
});
});

Then it is necessary to build.js add findnesteddependencies:true, then the minute will leave the second floor.

Leave the preparation

First, the placement of Nodejs

The file leaves the compression based on Nodejs, so that the Nodejs is placed first.

Second, download r.js

R.js unique Requirejs module notation about the file held away, compressed.

Complicated settings

Set file Best Write a build.js, the following:


({
BASEURL: ". /",
Paths: {
//...
},
Shim: {
//...
},
Optimize: "Uglify2",
Uglify2: {
Mangle:false//false non-promiscuous variable name
},
Findnesteddependencies:true,
Name: "Js/main",
Out: ". /js/main-built.js "
})
Here's how many key attributes:

BASEURL: The whole module (like JS) is absolutely all about paying this way.

Optimize: The way to optimize the script file, there are the previous 5 ways to take the value.

Uglify: (default) compressed with UGLIFYJS.

UGLIFY2: Compressed with UglifyJS2 (2.1.2+).

Closure: Using Google's closure Compiler complexity to optimize the situation of compressed files, is only optimizing the use of Java useful.

Closure.keeplines: As with the closure parameter, only the line break is preserved.

None: Do not compress.
Findnesteddependencies: Explore the Require () inside of the require may define invoke the dependency.

PS: Setting properties There are quite a few of them. When the file is set up, implement a call to leave the compression

Node R.js-o build.js
Summarize

Requirejs module of the left compression is still a bit complex, but encountered Angularjs, is the compression of some of the title, not found any better way.

The above is the detailed content of this article, I hope that the study of each person has helped.


Angularjs respectively Requirejs do the files merge compressed those pits

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.