9
9
configureMiniCssExtractPlugin ,
10
10
} from '../utils.js' ;
11
11
import * as fixtures from '../fixtures.js' ;
12
- import type { EsbuildPluginOptions } from '#esbuild-loader' ;
12
+ import { EsbuildPlugin , type EsbuildPluginOptions } from '#esbuild-loader' ;
13
13
14
14
const assertMinified = ( code : string ) => {
15
15
expect ( code ) . not . toMatch ( / \s { 2 , } / ) ;
@@ -23,7 +23,72 @@ export default testSuite(({ describe }, webpack: typeof webpack4 | typeof webpac
23
23
const webpackIs4 = isWebpack4 ( webpack ) ;
24
24
25
25
describe ( 'Plugin' , ( { test, describe } ) => {
26
- describe ( 'Minify JS' , ( { test } ) => {
26
+ describe ( 'Minify JS' , ( { test, describe } ) => {
27
+ describe ( 'should not minify by default' , ( { test } ) => {
28
+ test ( 'minimizer' , async ( ) => {
29
+ const built = await build (
30
+ fixtures . minification ,
31
+ ( config ) => {
32
+ config . optimization = {
33
+ minimize : false ,
34
+ minimizer : [
35
+ new EsbuildPlugin ( ) ,
36
+ ] ,
37
+ } ;
38
+ } ,
39
+ webpack ,
40
+ ) ;
41
+
42
+ expect ( built . stats . hasWarnings ( ) ) . toBe ( false ) ;
43
+ expect ( built . stats . hasErrors ( ) ) . toBe ( false ) ;
44
+
45
+ const exportedFunction = built . require ( '/dist/' ) ;
46
+ expect ( exportedFunction ( 'hello world' ) ) . toBe ( 'hello world' ) ;
47
+ expect ( exportedFunction . toString ( ) ) . toMatch ( / \s { 2 , } / ) ;
48
+ } ) ;
49
+
50
+ test ( 'plugin' , async ( ) => {
51
+ const built = await build (
52
+ fixtures . minification ,
53
+ ( config ) => {
54
+ config . plugins ?. push ( new EsbuildPlugin ( ) ) ;
55
+ } ,
56
+ webpack ,
57
+ ) ;
58
+
59
+ expect ( built . stats . hasWarnings ( ) ) . toBe ( false ) ;
60
+ expect ( built . stats . hasErrors ( ) ) . toBe ( false ) ;
61
+
62
+ const exportedFunction = built . require ( '/dist/' ) ;
63
+ expect ( exportedFunction ( 'hello world' ) ) . toBe ( 'hello world' ) ;
64
+ expect ( exportedFunction . toString ( ) ) . toMatch ( / \s { 2 , } / ) ;
65
+ } ) ;
66
+
67
+ test ( 'plugin with minimize enabled' , async ( ) => {
68
+ const built = await build (
69
+ fixtures . minification ,
70
+ ( config ) => {
71
+ config . optimization = {
72
+ minimize : true ,
73
+
74
+ // Remove Terser
75
+ minimizer : [ ] ,
76
+ } ;
77
+
78
+ config . plugins ?. push ( new EsbuildPlugin ( ) ) ;
79
+ } ,
80
+ webpack ,
81
+ ) ;
82
+
83
+ expect ( built . stats . hasWarnings ( ) ) . toBe ( false ) ;
84
+ expect ( built . stats . hasErrors ( ) ) . toBe ( false ) ;
85
+
86
+ const exportedFunction = built . require ( '/dist/' ) ;
87
+ expect ( exportedFunction ( 'hello world' ) ) . toBe ( 'hello world' ) ;
88
+ expect ( exportedFunction . toString ( ) ) . toMatch ( / \s { 2 , } / ) ;
89
+ } ) ;
90
+ } ) ;
91
+
27
92
test ( 'minify' , async ( ) => {
28
93
const built = await build (
29
94
fixtures . minification ,
0 commit comments