export default () => ( <FE-Developer name='段宏'> <Wepiao> Frontend Infrastructure Team @2015 </Wepiao> <Weidian> Frontend Team @2015 </Weidian> <Qfpay> Frontend @2014 </Qfpay> </FE-Developer> )
head link(rel="stylesheet" href="reset.css") body div.content script(src="jquery.js") script(src="index.js")
CSS Preprocesser
LESS
Stylus
SASS
JS own problem
our coding style
RequireJS
SeaJS
CommonJS
ES6 import
CoffeeScript
TypeScript
JSX
CSS preprocesser
Compile to JS
JS Modules Implementation
CSS Minify
JS Uglify
Image Compression
Request Combination
...
Grunt
Gulp
Browserify
Webpack
Tasked based
Organized by file
Entry based
Dependency Graph
图片来自fouber
(2014)
transforming, bundling, or packaging just about any resource or asset
Compatibility (CommonJS, AMD, ES6...)
Code Splitting
Loaders & Plugins
Development Tools & Workflow
// webpack.config.js module.exports = { entry: './main.js', output: { filename: 'bundle.js' }{, module: { loaders: [{ test: /\.js?x$/, loader: 'babel-loader' }] }} }
There are many other static resources that need to be handled
// Ensure the stylesheet is loaded require('./bootstrap.css'); // get a URL or DataURI var myImage = document.createElement('img'); myImage.src = require('./myImage.jpg');
They are part of dependency graph
// CSS Preprocesser require('./style.less'); require('./anotherStyle.scss'); // Compile-to-JS Language var myModule = require('./myModule.coffee'); var myTypedModule = require('./myTypedModule.ts');
Universal Module System
var webpackConfig = { module: { loaders: [{ test: /\.scss$/, loaders: 'style!css!sass' }, { test: /\.(png|jpg|svg)$/, loader: 'url?limit=20480' //20k }] }} }
Deal with CSS problems
Inlining your images to DataURI
var config = { entry: ['webpack/hot/dev-server', './app/main.js'], module: { loaders: [{ test: /\.(js|jsx)$/, loaders: ['react-hot', 'babel'] }] }, plugins: [ //Enables Hot Modules Replacement new webpack.HotModuleReplacementPlugin(), ], };
split your codebase into “chunks” which are loaded on demand.
we have a good time with webpack
. ├── node_modules │ └── 61 modules ├── package.json ├── config.json ├── src │ ├── assets │ ├── components │ ├── pages │ └── scss ├── template.html ├── webpack.config.js └── webpack.config.production.js
. ├── node_modules │ └── 61 modules, dev 52 ├── config.json ├── template.html ├── webpack.config.js └── webpack.config.production.js
Too many Dependencies
Configuration still bleeding
➜ demo tree -L 2 . ├── mock.js ├── node_modules │ └── no dev modules ├── package.json ├── pepper.config.js ├── src │ ├── assets │ ├── components │ ├── pages │ └── scss └── template.html
npm install we-pepper -g
➜ $ pepper ? 选择要执行的任务: (Use arrow keys) ❯ 项目打包 开发调试 初始化新项目 (es5) 初始化新项目 (es6) 创建新页面 创建新组件 升级pepper
项目打包
pepper [test, pre, release]
开发调试
pepper start [-p PORT]
初始化新项目
pepper init proj_name
创建新页面
pepper page PAGE_NAME
创建新组件
pepper component COMPONENT_NAME
升级 Pepper
pepper ungrade
||
npm install we-pepper -g
About pepper.config.js
or
// CDN domain, or just leave it blank if not using "static": { "start" : "", // here use relative path "test" : "", "pre" : "http://static.wepiao.com/",// here use CDN domain "release" : "http://static.wepiao.com/" // here use CDN domain }, // API base entry // config `mock.js` for CROS solution "api": { "start" : "", // local api base entry "test" : "", "pre" : "http://wx.wepiao.com", // online api base entry "release" : "http://wx.wepiao.com" }
split out resource and api
// pepper start console.log(API, STATIC); // '', '' ... // pepper release console.log(API, STATIC); // 'http://wx/wepiao.com', 'http://static.wepiao.com/'
// third patry libs to bundle, // like react-router, fetch "vendor": ["react", "react-dom"],
// dir alias, could use globally, despite of CWD "alias": { "scss" : "scss", "wepiao" : "components", "assets" : "assets", "utils" : "utils" }
ignore the '../../..'
require('assets/path/to/image') import styles from 'scss/your/style/path' import API from 'utils/api'
About mock.js
module.exports = [{ path: /\/apis/, method: 'get', data: function(options) { return [{ // response data id: 1, first: '@FIRST', }, { id: 2, first: '@FIRST', }, { id: 3, first: '@FIRST', }] } }];
module.exports = [{ path: '/search', proxy: 'http://github.com', pathRewrite: { '^/search': '/search/users' } }];
Hey, don't be shy.