Skip to content

Commit 0f4b0e0

Browse files
alex-ketchmarkerikson
authored andcommitted
Fix module bundling & ESM runtime error (#280)
1 parent 3ebb9fa commit 0f4b0e0

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/getDefaultMiddleware.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Middleware } from 'redux'
22
import thunkMiddleware from 'redux-thunk'
3-
// UMD-DEV-ONLY: import createImmutableStateInvariantMiddleware from 'redux-immutable-state-invariant'
3+
/* START_REMOVE_UMD */
4+
import createImmutableStateInvariantMiddleware from 'redux-immutable-state-invariant'
5+
/* STOP_REMOVE_UMD */
46

57
import {
68
createSerializableStateInvariantMiddleware,
@@ -55,10 +57,10 @@ export function getDefaultMiddleware<S = any>(
5557
}
5658

5759
if (process.env.NODE_ENV !== 'production') {
58-
/* START_REMOVE_UMD */
5960
if (immutableCheck) {
60-
const createImmutableStateInvariantMiddleware = require('redux-immutable-state-invariant')
61-
.default
61+
/* PROD_START_REMOVE_UMD */
62+
63+
// UMD-ONLY: const createImmutableStateInvariantMiddleware = require('redux-immutable-state-invariant').default
6264

6365
let immutableOptions: ImmutableStateInvariantMiddlewareOptions = {}
6466

@@ -69,9 +71,9 @@ export function getDefaultMiddleware<S = any>(
6971
middlewareArray.unshift(
7072
createImmutableStateInvariantMiddleware(immutableOptions)
7173
)
72-
}
7374

74-
/* STOP_REMOVE_UMD */
75+
/* PROD_STOP_REMOVE_UMD */
76+
}
7577

7678
if (serializableCheck) {
7779
let serializableOptions: SerializableStateInvariantMiddlewareOptions = {}

tsdx.config.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,26 @@ module.exports = {
1515
case 'umd':
1616
delete config.external
1717
config.output.indent = false
18-
config.plugins.push(
18+
config.plugins.unshift(
1919
replace({
20-
'// UMD-DEV-ONLY: ': ''
20+
'// UMD-ONLY: ': '',
21+
delimiters: ['', '']
2122
})
2223
)
23-
config.plugins.push(
24+
config.plugins.unshift(
2425
stripCode({
25-
// Remove the `require()` import of RISI so we use the import statement
26+
// Remove the `import` of RISI so we use the dynamic `require()` statement
2627
start_comment: 'START_REMOVE_UMD',
2728
end_comment: 'STOP_REMOVE_UMD'
2829
})
2930
)
3031
if (env === 'production') {
32+
config.plugins.unshift(
33+
stripCode({
34+
start_comment: 'PROD_START_REMOVE_UMD',
35+
end_comment: 'PROD_STOP_REMOVE_UMD'
36+
})
37+
)
3138
config.output.file = join(__dirname, pkg.unpkg)
3239
} else {
3340
config.output.file = config.output.file.replace(

0 commit comments

Comments
 (0)