Skip to content

Commit

Permalink
build: Optimize bundle size
Browse files Browse the repository at this point in the history
- disable source map
- exclude dependencies in esm build
- enable production build
  • Loading branch information
DanSnow committed Jul 5, 2020
1 parent 71346d4 commit 5c012e5
Show file tree
Hide file tree
Showing 6 changed files with 1,206 additions and 3,866 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"presets": ["@babel/preset-typescript", "@babel/preset-env"],
"plugins": [
["@babel/plugin-transform-runtime", { "useESModules": true }],
["@babel/proposal-decorators", { "legacy": true }],
["@babel/proposal-class-properties", { "loose": true }]
]
}
}
27 changes: 22 additions & 5 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import babel from 'rollup-plugin-babel';
import babel from '@rollup/plugin-babel';
import vue from 'rollup-plugin-vue';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import pkg from '../package.json';

// TODO: visualizer - Bundle and dependency visualizer.

const base = {
input: 'src/index.ts',
external: ['vue'],
plugins: [
vue({
defaultLang: { script: 'ts' }
defaultLang: { script: 'ts' },
needMap: false,
template: {
isProduction: true,
}
}),
babel({
exclude: 'node_modules/**',
extensions: ['.js', '.ts', '.vue'],
babelHelpers: 'runtime',
}),
resolve({
extensions: ['.mjs', '.ts', '.js', '.json', '.node']
Expand All @@ -23,10 +28,21 @@ const base = {
]
};

const external = ['vue', ...Object.keys(pkg.dependencies)]

const esModuleBuild = {
output: {
file: 'dist/vue-color.min.mjs',
format: 'esm',
},
external: (id) => {
if (external.includes(id)) {
return true
}
if (id.startsWith('@babel/runtime')) {
return true
}
return false
}
};

Expand All @@ -38,7 +54,8 @@ const umdBuild = {
globals: {
'vue': 'Vue'
}
}
},
external: ['vue'],
}

export default [esModuleBuild, umdBuild].map((output) => ({ ...base, ...output }));
export default [esModuleBuild, umdBuild].map((output) => ({ ...base, ...output }));
Loading

0 comments on commit 5c012e5

Please sign in to comment.