npm i -D webpack-bundle-analyzer babel-plugin-component image-webpack-loader babel-plugin-lodash lodash-webpack-plugin compression-webpack-plugin
babel.config.js
可以使用 component plugin,藉此達到只引入需要的組件來減小體積vue.config.js
可以使用 lodash-webpack-plugin
,優化 lodash 打包資源
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
// ...
configureWebpack: {
plugins: [
// 分析打包資源
new BundleAnalyzerPlugin(),
],
},
}
將 element-ui
引入檔元件化,便可以只引入需要的組件來減小體積
module.exports = {
// ...
plugins: [
// ...
[
'component',
{
libraryName: 'element-ui',
styleLibraryName: 'theme-chalk',
},
],
],
};
//...
import {
Breadcrumb,
BreadcrumbItem,
Loading,
// 其餘會使用到的 element-ui 元件 ...
} from 'element-ui';
// ...
Vue.use(Breadcrumb);
Vue.use(BreadcrumbItem);
// 其餘會使用到的 element-ui 元件 ...
Vue.prototype.$loading = Loading.service;
// ...
module.exports = {
// ...
chainWebpack: config => {
// 壓縮圖片
config.module
.rule('images')
.test(/\.(png|jpg|jpeg|gif|svg|svgz)$/i)
.use('image-webpack-loader')
.loader('image-webpack-loader')
.options({
// jpeg
mozjpeg: { progressive: true, quality: 30 },
// png
optipng: { enabled: false },
// png
pngquant: { quality: [0.65, 0.9], speed: 4 },
// svg
gifsicle: { interlaced: false },
// jpg & png into webp
webp: { quality: 75 },
})
.end();
},
}
const CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
// ...
configureWebpack: {
plugins: [
new CompressionPlugin({
test: /\.(js|css|svg|otf)$/,
filename: '[path][base].gz',
threshold: 10240,
}),
],
},
}
const LodashWebpackPlugin = require('lodash-webpack-plugin');
module.exports = {
// ...
configureWebpack: {
plugins: [
// ...
// lodash 按需打包
new LodashWebpackPlugin({
'collections': true,
}),
],
},
}
module.exports = {
// ...
plugins: [
[ 'lodash' ],
],
};
module.exports = {
// ...
chainWebpack: config => {
// 指定引入 jquery 的檔案路徑
config.resolve.alias
.set('jquery', 'jquery/dist/jquery.slim.min.js');
},
// ...
}
某些較大的檔案使用 lazyload 方式引入
不宜過度使用,避免請求過多而變慢導致反效果
// ...
import LoginPage from '../views/ds_auth/LoginPage.vue';
// 其餘較小的檔案 ...
Vue.use(VueRouter);
const routes = [
{
path: '/',
name: 'Index',
component: () => import(/* webpackChunkName: "index" */ '../views/global/Index.vue'),
},
{
path: '/loginPage',
name: 'LoginPage',
component: LoginPage,
},
// ...
];
// ...
建立 Line bot channel 登入 Line 開發人員網站 新建 provider (公司、品牌等的群組,可邀請多位成員,底下包含多個 channel) 新建 channel (Line 應用程式,目前有 登入、訊息、語音助理、區塊鏈 四種功能) channel 不可包含 Line 字樣 App types 選擇 Messaging API 選填可先跳過
Nov 8, 2020前言 名詞解釋 SPA (Single Page Application): 使用前端框架 (Angular、React、Vue) 產生的單頁應用網頁 所有頁面內容都是透過 Client 端的 JavaScript 產生出來的,Server 端固定輸出同個檔案 SEO (Search Engine Optimization):
Nov 8, 2020or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up