Elderjs / elderjs

Elder.js is an opinionated static site generator and web framework for Svelte built with SEO in mind.

Home Page:https://elderguide.com/tech/elderjs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tree shaking, removal of unused/dead code

cayolblake opened this issue · comments

@nickreese for the life of me I'm not able to find a way to use Terser/Uglify to do treeshaking, or remove any JavaScript code that is not used, sometimes called dead code, for builds.

In terser (which supports ES6) for example, compress: {defaults: false, dead_code: true, unused: true} which ends up removing both unused and dead code, in addition to https://rollupjs.org/guide/en/#tree-shaking

Where/How to do it? 🤷

commented

Elderjs does include terser in its default config:

import { terser } from 'rollup-plugin-terser';

It is only used on production builds:
const production = process.env.NODE_ENV === 'production' || !process.env.ROLLUP_WATCH;

if (production) {
config.plugins.push(
babel({
extensions: ['.js', '.mjs', '.cjs', '.html', '.svelte'],
include: ['node_modules/**', 'src/**'],
exclude: ['node_modules/@babel/**'],
runtimeHelpers: true,
}),
);
// terser on prod
config.plugins.push(terser());
}