Skip to content

Commit

Permalink
fix: bud.terser (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
kellymears committed Mar 22, 2022
1 parent c6a50b6 commit 0616d0b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 54 deletions.
28 changes: 28 additions & 0 deletions sources/@roots/bud-terser/src/bud.env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {Extension} from '@roots/bud-framework'
import TerserPlugin from 'terser-webpack-plugin/types'
import {terser} from './terser.api'

declare module '@roots/bud-framework' {
interface Framework {
terser: terser
}

interface Modules {
'@roots/bud-terser': Terser.Extension
}

namespace Terser {
export type Options = TerserPlugin.BasePluginOptions

export type Plugin = TerserPlugin

export interface Extension
extends Extension.CompilerPlugin<
TerserPlugin,
TerserPlugin.BasePluginOptions
> {
name: '@roots/bud-terser'
options: (app: Framework) => Terser.Options
}
}
}
13 changes: 0 additions & 13 deletions sources/@roots/bud-terser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,4 @@
* @packageDocumentation
*/

import type {terser} from './terser.api'
import type {Extension} from './terser.interface'

declare module '@roots/bud-framework' {
interface Framework {
terser: terser
}

interface Modules {
'terser-webpack-plugin': Extension
}
}

export {name, api, options, boot} from './terser.extension'
4 changes: 2 additions & 2 deletions sources/@roots/bud-terser/src/terser.api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Framework, Terser} from './terser.interface'
import type {Framework, Terser} from '@roots/bud-framework'

export interface terser {
(this: Framework, options: Terser.Options): Framework
Expand All @@ -8,7 +8,7 @@ export const terser: terser = function (
this: Framework,
options: Terser.Options,
): Framework {
this.extensions.get('terser-webpack-plugin').setOptions(options)
this.extensions.get('@roots/bud-terser').setOptions(options)

return this
}
30 changes: 13 additions & 17 deletions sources/@roots/bud-terser/src/terser.extension.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import type {Framework} from '@roots/bud-framework'
import * as Framework from '@roots/bud-framework'
import TerserPlugin from 'terser-webpack-plugin'

import * as api from './terser.api'
import {TerserPlugin} from './terser.dependencies'
import {terser} from './terser.api'

export const name = '@roots/bud-terser'
export const name: Framework.Terser.Extension['name'] = '@roots/bud-terser'

export const options = (app: Framework) => ({
parallel: app.hooks.filter('build.parallelism'),
export const options: Framework.Terser.Extension['options'] = app => ({
include: app.store.get('patterns.js'),
extractComments: false,
terserOptions: {
parse: {
ecma: 2018,
},
parse: {ecma: 2018},
compress: false,
mangle: {
safari10: true,
},
mangle: {safari10: true},
output: {
ecma: 5,
comments: false,
Expand All @@ -25,15 +20,16 @@ export const options = (app: Framework) => ({
},
})

export const boot = ({extensions, hooks, store}) => {
export const boot: Framework.Terser.Extension['boot'] = ({
extensions,
hooks,
}) => {
hooks.on('build.optimization.minimizer', minimizer => {
minimizer.push(
new TerserPlugin(
extensions.get('terser-webpack-plugin').options.all(),
),
new TerserPlugin(extensions.get('@roots/bud-terser').options.all()),
)
return minimizer
})
}

export {api}
export const api: Framework.Terser.Extension['api'] = {terser}
16 changes: 0 additions & 16 deletions sources/@roots/bud-terser/src/terser.interface.ts

This file was deleted.

11 changes: 5 additions & 6 deletions sources/@roots/bud-terser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"extends": "../../../config/tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"declarationDir": "./types",
"esModuleInterop": true,
"rootDir": "./src",
"outDir": "./lib/cjs",
"declarationDir": "./types",
"esModuleInterop": true
"types": ["node", "@roots/bud-api"]
},
"include": [
"src"
],
"files": ["./src/bud.env.d.ts"],
"include": ["src/**/*.ts", "src/**/*.json"],
"references": [
{
"path": "./../bud-framework/tsconfig.json"
Expand Down

0 comments on commit 0616d0b

Please sign in to comment.