本質上來說,slue是gulp的一個實現,其底層API是完全一致的,原則上,gulp的所有插件都可以運行在slue上。不同的是,slue同時,也實現了對commonJs、es6模塊規範代碼的打包支持。
下面我們簡單介紹下slue對vue異步路由的支持。
假如你的路由是打包在app.js裡的,同時,你有一個“#/home”頁面,home頁面資源打包為home.js,那麼,你需要做以下事情:
1、sluepack.config.js配置
module.exports = {
entry: {
app: './src/app.js',
home: './src/pages/home/home.vue',
}
}
2、router.js
import Router from 'vue-router';
import homePage from '../pages/home';
export default new Router({
routes: [{
path: '/',
redirect: '/home'
}, {
path: '/home',
component: homePage
}]
});
3、src/pages/home/index.js
module.exports = function() {
return new Promise(function(resolve) {
// src/page/home/home.vue
require.async('./home', function(component) {
resolve(component);
});
});
};
閱讀更多 宋楚劍 的文章