Now various mobile end terminal equipment rise, has exceeded the pc side, different devices will inevitably lead to the development of language is not unified, develop more and more difficult, such as making a game, you need to develop several different versions of Android version, IOS version, etc., very waste of human and material resources.
Big front of the times came into being, it appears precisely to solve these difficulties.
About ES6 building project
- Project build step
- New project folder (three blocks)
- app: front-end code (js, css, html template)
- js
- css
- views
- server: server code (server)
一个完整的项目必须要服务器提供接口和真实数据
express-generator脚手架
express -e .
- tasks: the auxiliary code (compiler front-end code and automation)
- util: placing common gulp automated scripts
args.js
(Write your own script command-line arguments)
- util: placing common gulp automated scripts
- app: front-end code (js, css, html template)
- Create the necessary configuration files
- package.json (npm install -y)
.babelrc
(Support es6 grammar)gulpfile.babel.js
(Because the syntax used in the project es6, so gulp startup file extensions need to be added.babel
)
- Handling command-line parameters (
args.js
custom parameters script)
- New project folder (three blocks)
Popular frameworks
- Libraries and frameworks
- Library: Small but no specific norms, based mainly in their own Code
- Frame: large and mainly in the skeleton code for people to write their own code in this framework, the need to comply with the regulatory framework established by
- MVC
- An idea, it is simply a way to make up the structure of the code
- The most critical point is to reduce the degree of coupling
- Easy to write and maintain the code
- To facilitate the development team
- Simplify the complexity of the overall code, organization code division module
- Agile thinking: greater than the configured agreement, a good agreement with each other as long as the team members will be able to quickly develop
- View
- Data-driven framework:
- View of a data driver, as long as the data is modified automatically update the view, the operation does not require DOM
- Data-driven framework:
- Task Automation
- grunt: After belongs to cascade operations, file operations more slowly
- gulp: file stream operation (stream), fast
- Compilation Tools
- babel: Compile ES6
- webpack: Modular project dependencies
JQuery
- Package entry function
- Jquery entry function may not be used, instead of using DOMContentLoaded
Modular Load
CommonJS specification
main idea
- It allows the module
require
to other modules to be loaded synchronously dependent method, and then byexports
ormodule.exports
derived needs to be exposed excuse1
2
3
4require("module");
require("../file.js");
exports.doStuff = function() {};
module.exports = someValue;
- It allows the module
Implementation
- Node.js server
- Browserify < Big column large front-end presentation tool / ul>
AMD
Asynchronous Module Definition
specificationmain idea
- Only one primary interface
define(id?, dependencies?, factory)
, it is to specify in the statement when the module all the dependencies dependencies, and also as a parameter passed to factory, do in advance for dependent modules, pre-reliance1
2
3
4define("module", ["dep1", "dep2"], function(d1, d2) {
return someExportedValue;
});
require(["module", "../file"], function(module, file) { });
- Only one primary interface
Implementation
- requireJS
CMD
Common Module Definition
specificationAnd AMD is very similar, try to keep it simple, and with Modules CommonJS Node.js and specifications to maintain a great deal of compatibility
1
2
3
4
5
6define(function(require, exports, module) {
var $ = require('jquery');
var Spinning = require('./spinning');
exports.doSomething = ...
module.exports = ...
})Implementation
- Sea.js
- Background node.js
- Dependence require and exports
- browserify
- Module loader, but you can only load js
- webpack
- Module Loader, all things are modules, including css, pictures, vue file, js etc.
- Modules are written separately, and finally packaged together
Webpack
- webpack configured correctly
process.env.NODE_ENV
1
2
3
4
5new webpack.DefinePlugin({
'process.env':{
'NODE_ENV':JSON.stringify('production')
}
})When you call the following command: indicates a production environment how to use webpack package (Linux environment)
NODE_ENV=production webpack --progress --colors