Skip to content

Commit 57971f8

Browse files
committed
chore: add size-limit
1 parent 14ac4df commit 57971f8

File tree

3 files changed

+77
-50
lines changed

3 files changed

+77
-50
lines changed

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"build:playground": "webpack --env.prod",
2424
"build:e2e": "webpack --env.prod --config e2e/webpack.config.js",
2525
"dev:e2e": "webpack-dev-server --mode=development --config e2e/webpack.config.js",
26+
"size": "size-limit",
2627
"lint": "prettier -c --parser typescript \"{src,__tests__,e2e}/**/*.[jt]s?(x)\"",
2728
"lint:fix": "yarn run lint --write",
2829
"test:types": "tsc --build tsconfig.json",
@@ -43,6 +44,11 @@
4344
"prettier --parser=typescript --write"
4445
]
4546
},
47+
"size-limit": [
48+
{
49+
"path": "size-checks/appWithWebRouter.js"
50+
}
51+
],
4652
"peerDependencies": {
4753
"vue": "^3.0.0-beta.3"
4854
},
@@ -53,6 +59,7 @@
5359
"@rollup/plugin-commonjs": "^11.1.0",
5460
"@rollup/plugin-node-resolve": "^7.1.3",
5561
"@rollup/plugin-replace": "^2.3.2",
62+
"@size-limit/preset-small-lib": "^4.4.5",
5663
"@types/jest": "^25.1.3",
5764
"@types/jsdom": "^16.2.1",
5865
"@types/webpack": "^4.41.12",
@@ -79,6 +86,7 @@
7986
"rollup-plugin-typescript2": "^0.27.0",
8087
"selenium-server": "^3.141.59",
8188
"serve-handler": "^6.1.2",
89+
"size-limit": "^4.4.5",
8290
"style-loader": "^1.2.0",
8391
"ts-jest": "^25.4.0",
8492
"ts-loader": "^7.0.1",
@@ -87,6 +95,7 @@
8795
"vue": "^3.0.0-beta.3",
8896
"vue-loader": "^16.0.0-alpha.3",
8997
"webpack": "^4.43.0",
98+
"webpack-bundle-analyzer": "^3.7.0",
9099
"webpack-cli": "^3.3.11",
91100
"webpack-dev-server": "^3.10.3",
92101
"yorkie": "^2.0.0"

size-checks/appWithWebRouter.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { h, createApp } from '@vue/runtime-dom'
2+
import { createRouter, createWebHistory } from './dist/src'
3+
4+
createRouter({
5+
history: createWebHistory(),
6+
routes: [],
7+
})
8+
9+
// The bare minimum code required for rendering something to the screen
10+
createApp({
11+
render: () => h('div', 'hello world!'),
12+
}).mount('#app')

webpack.config.js

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,71 @@
11
const { resolve } = require('path')
22
const HtmlWebpackPlugin = require('html-webpack-plugin')
3+
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
34
const { VueLoaderPlugin } = require('vue-loader')
45
const webpack = require('webpack')
56

67
const outputPath = resolve(__dirname, 'playground_dist')
78

89
/** @type {import('webpack').ConfigurationFactory} */
9-
const config = (env = {}) => ({
10-
mode: env.prod ? 'production' : 'development',
11-
devtool: env.prod ? 'source-map' : 'inline-source-map',
10+
const config = (env = {}) => {
11+
const extraPlugins = env.prod ? [new BundleAnalyzerPlugin()] : []
1212

13-
devServer: {
14-
contentBase: outputPath,
15-
historyApiFallback: true,
16-
hot: true,
17-
stats: 'minimal',
18-
},
13+
return {
14+
mode: env.prod ? 'production' : 'development',
15+
devtool: env.prod ? 'source-map' : 'inline-source-map',
1916

20-
output: {
21-
path: outputPath,
22-
publicPath: '/',
23-
filename: 'bundle.js',
24-
},
17+
devServer: {
18+
contentBase: outputPath,
19+
historyApiFallback: true,
20+
hot: true,
21+
stats: 'minimal',
22+
},
2523

26-
entry: [resolve(__dirname, 'playground/main.ts')],
27-
module: {
28-
rules: [
29-
{
30-
test: /\.ts$/,
31-
use: 'ts-loader',
32-
},
33-
{
34-
test: /\.vue$/,
35-
use: 'vue-loader',
36-
},
37-
],
38-
},
39-
resolve: {
40-
alias: {
41-
// this isn't technically needed, since the default `vue` entry for bundlers
42-
// is a simple `export * from '@vue/runtime-dom`. However having this
43-
// extra re-export somehow causes webpack to always invalidate the module
44-
// on the first HMR update and causes the page to reload.
45-
vue: '@vue/runtime-dom',
24+
output: {
25+
path: outputPath,
26+
publicPath: '/',
27+
filename: 'bundle.js',
4628
},
47-
// Add `.ts` and `.tsx` as a resolvable extension.
48-
extensions: ['.ts', 'd.ts', '.tsx', '.js', '.vue'],
49-
},
50-
plugins: [
51-
new VueLoaderPlugin(),
52-
new HtmlWebpackPlugin({
53-
template: resolve(__dirname, 'playground/index.html'),
54-
}),
55-
new webpack.DefinePlugin({
56-
__DEV__: JSON.stringify(!env.prod),
57-
__BROWSER__: 'true',
58-
'process.env': {
59-
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
29+
30+
entry: [resolve(__dirname, 'playground/main.ts')],
31+
module: {
32+
rules: [
33+
{
34+
test: /\.ts$/,
35+
use: 'ts-loader',
36+
},
37+
{
38+
test: /\.vue$/,
39+
use: 'vue-loader',
40+
},
41+
],
42+
},
43+
resolve: {
44+
alias: {
45+
// this isn't technically needed, since the default `vue` entry for bundlers
46+
// is a simple `export * from '@vue/runtime-dom`. However having this
47+
// extra re-export somehow causes webpack to always invalidate the module
48+
// on the first HMR update and causes the page to reload.
49+
vue: '@vue/runtime-dom',
6050
},
61-
}),
62-
],
63-
})
51+
// Add `.ts` and `.tsx` as a resolvable extension.
52+
extensions: ['.ts', 'd.ts', '.tsx', '.js', '.vue'],
53+
},
54+
plugins: [
55+
new VueLoaderPlugin(),
56+
new HtmlWebpackPlugin({
57+
template: resolve(__dirname, 'playground/index.html'),
58+
}),
59+
new webpack.DefinePlugin({
60+
__DEV__: JSON.stringify(!env.prod),
61+
__BROWSER__: 'true',
62+
'process.env': {
63+
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
64+
},
65+
}),
66+
...extraPlugins,
67+
],
68+
}
69+
}
6470

6571
module.exports = config

0 commit comments

Comments
 (0)