1
1
const webpack = require ( 'webpack' )
2
2
let { join } = require ( 'path' )
3
3
4
- const rtkEntryPoints = [
5
- 'dist/redux-toolkit.cjs.production.min.js' ,
6
- 'dist/redux-toolkit.esm.js' ,
7
- 'dist/redux-toolkit.modern.js' ,
8
- 'dist/redux-toolkit.modern.production.min.js' ,
9
- ]
10
-
11
- const queryEntryPoints = [
12
- 'dist/query/rtk-query.cjs.production.min.js' ,
13
- 'dist/query/rtk-query.esm.js' ,
14
- 'dist/query/rtk-query.modern.js' ,
15
- 'dist/query/rtk-query.modern.production.min.js' ,
16
- ]
17
-
18
- const reactEntryPoints = [
19
- 'dist/query/react/rtk-query-react.cjs.production.min.js' ,
20
- 'dist/query/react/rtk-query-react.esm.js' ,
21
- 'dist/query/react/rtk-query-react.modern.js' ,
22
- 'dist/query/react/rtk-query-react.modern.production.min.js' ,
23
- ]
24
-
25
- const umdBuilds = [
26
- 'dist/redux-toolkit.umd.js' ,
27
- 'dist/query/rtk-query.umd.js' ,
28
- 'dist/query/react/rtk-query-react.umd.js' ,
29
- ]
4
+ const suffixes = [ 'cjs.production.min.js' , 'esm.js' ]
30
5
31
- function withRtkPath ( path ) {
6
+ function withRtkPath ( suffix ) {
32
7
return ( config ) => {
33
- if ( path . startsWith ( 'dist/query/rtk-query' ) ) {
34
- config . plugins . push (
35
- new webpack . NormalModuleReplacementPlugin (
36
- / @ r e d u x j s \/ t o o l k i t / ,
37
- join (
38
- __dirname ,
39
- path . replace ( 'dist/query/rtk-query' , 'dist/redux-toolkit' )
8
+ config . plugins . push (
9
+ new webpack . NormalModuleReplacementPlugin (
10
+ / @ r e d u x j s \/ t o o l k i t \/ q u e r y \/ r e a c t / ,
11
+ join ( __dirname , `query/react` )
12
+ ) ,
13
+ new webpack . NormalModuleReplacementPlugin (
14
+ / @ r e d u x j s \/ t o o l k i t \/ q u e r y / ,
15
+ join ( __dirname , `query` )
16
+ ) ,
17
+ new webpack . NormalModuleReplacementPlugin (
18
+ / @ r e d u x j s \/ t o o l k i t / ,
19
+ join ( __dirname )
20
+ ) ,
21
+ new webpack . NormalModuleReplacementPlugin (
22
+ / r t k - q u e r y - r e a c t .e s m .j s / ,
23
+ ( r ) => {
24
+ const old = r . request
25
+ r . request = r . request . replace (
26
+ / r t k - q u e r y - r e a c t .e s m .j s $ / ,
27
+ `rtk-query-react.${ suffix } `
40
28
)
29
+ // console.log(old, '=>', r.request)
30
+ }
31
+ ) ,
32
+ new webpack . NormalModuleReplacementPlugin ( / r t k - q u e r y .e s m .j s / , ( r ) => {
33
+ const old = r . request
34
+ r . request = r . request . replace (
35
+ / r t k - q u e r y .e s m .j s $ / ,
36
+ `rtk-query.${ suffix } `
41
37
)
42
- )
43
- }
44
- if ( path . startsWith ( 'dist/query/react/rtk-query-react' ) ) {
45
- config . plugins . push (
46
- new webpack . NormalModuleReplacementPlugin (
47
- / @ r e d u x j s \/ t o o l k i t \/ q u e r y / ,
48
- join (
49
- __dirname ,
50
- path . replace (
51
- 'dist/query/react/rtk-query-react' ,
52
- 'dist/query/rtk-query'
53
- )
38
+ // console.log(old, '=>', r.request)
39
+ } ) ,
40
+ new webpack . NormalModuleReplacementPlugin (
41
+ / r e d u x - t o o l k i t .e s m .j s $ / ,
42
+ ( r ) => {
43
+ const old = r . request
44
+ r . request = r . request . replace (
45
+ / r e d u x - t o o l k i t .e s m .j s $ / ,
46
+ `redux-toolkit.${ suffix } `
54
47
)
55
- ) ,
56
- new webpack . NormalModuleReplacementPlugin (
57
- / @ r e d u x j s \/ t o o l k i t / ,
58
- join (
59
- __dirname ,
60
- path . replace (
61
- 'dist/query/react/rtk-query-react' ,
62
- 'dist/redux-toolkit'
63
- )
64
- )
65
- )
48
+ // console.log(old, '=>', r.request)
49
+ }
66
50
)
51
+ )
52
+ if ( suffix === 'cjs.production.min.js' ) {
53
+ config . resolve . mainFields = [ 'main' , 'module' ]
67
54
}
55
+ config . optimization . nodeEnv = 'production'
68
56
return config
69
57
}
70
58
}
@@ -79,72 +67,78 @@ const ignoreAll = [
79
67
]
80
68
81
69
module . exports = [
82
- ...[ ...rtkEntryPoints , ...queryEntryPoints , ...reactEntryPoints ] . flatMap (
83
- ( path ) => [
70
+ {
71
+ name : `1. entry point: @reduxjs/toolkit` ,
72
+ path : 'dist/redux-toolkit.esm.js' ,
73
+ } ,
74
+ {
75
+ name : `1. entry point: @reduxjs/toolkit/query` ,
76
+ path : 'dist/query/rtk-query.esm.js' ,
77
+ } ,
78
+ {
79
+ name : `1. entry point: @reduxjs/toolkit/query/react` ,
80
+ path : 'dist/query/react/rtk-query-react.esm.js' ,
81
+ } ,
82
+ {
83
+ name : `2. entry point: @reduxjs/toolkit (without dependencies)` ,
84
+ path : 'dist/redux-toolkit.esm.js' ,
85
+ ignore : ignoreAll ,
86
+ } ,
87
+ {
88
+ name : `2. entry point: @reduxjs/toolkit/query (without dependencies)` ,
89
+ path : 'dist/query/rtk-query.esm.js' ,
90
+ ignore : ignoreAll ,
91
+ } ,
92
+ {
93
+ name : `2. entry point: @reduxjs/toolkit/query/react (without dependencies)` ,
94
+ path : 'dist/query/react/rtk-query-react.esm.js' ,
95
+ ignore : ignoreAll ,
96
+ } ,
97
+ ]
98
+ . flatMap ( ( e ) =>
99
+ suffixes . map ( ( suffix ) => ( {
100
+ ...e ,
101
+ name : e . name + ` (${ suffix } )` ,
102
+ modifyWebpackConfig : withRtkPath ( suffix ) ,
103
+ } ) )
104
+ )
105
+ . concat (
106
+ ...[
84
107
{
85
- name : `1. entry point: ${ path } ` ,
86
- path,
87
- modifyWebpackConfig : withRtkPath ( path ) ,
108
+ name : `3. createSlice` ,
109
+ import : { '@reduxjs/toolkit' : '{ createSlice }' } ,
88
110
} ,
89
111
{
90
- name : `2. entry point: ${ path } (without dependencies)` ,
91
- path,
92
- modifyWebpackConfig : withRtkPath ( path ) ,
93
- ignore : ignoreAll ,
112
+ name : `3. createEntityAdapter` ,
113
+ import : { '@reduxjs/toolkit' : '{ createEntityAdapter }' } ,
94
114
} ,
95
- ]
96
- ) ,
97
- ...rtkEntryPoints . flatMap ( ( path ) => [
98
- {
99
- name : `3. createSlice (${ path } )` ,
100
- path,
101
- import : '{ createSlice }' ,
102
- } ,
103
- {
104
- name : `3. createEntityAdapter (${ path } )` ,
105
- path,
106
- import : '{ createEntityAdapter }' ,
107
- } ,
108
- {
109
- name : `3. configureStore (${ path } )` ,
110
- path,
111
- import : '{ configureStore }' ,
112
- } ,
113
- ] ) ,
114
- ...[ ...queryEntryPoints , ...reactEntryPoints ] . flatMap ( ( path ) => [
115
- {
116
- name : `3. createApi (${ path } )` ,
117
- path,
118
- import : '{ createApi }' ,
119
- modifyWebpackConfig : withRtkPath ( path ) ,
120
- } ,
121
- {
122
- name : `3. setupListeners (${ path } )` ,
123
- path,
124
- import : '{ setupListeners }' ,
125
- modifyWebpackConfig : withRtkPath ( path ) ,
126
- } ,
127
- {
128
- name : `3. fetchBaseQuery (${ path } )` ,
129
- path,
130
- import : '{ fetchBaseQuery }' ,
131
- modifyWebpackConfig : withRtkPath ( path ) ,
132
- } ,
133
- ] ) ,
134
- ...umdBuilds . map ( ( path ) => ( {
135
- name : `4. UMD build: ${ path } ` ,
136
- path,
137
- } ) ) ,
138
- ] . sort ( byName )
139
- /*
140
- .filter(
141
- (x) => x.name == '3. createApi (dist/query/react/rtk-query-react.modern.js)'
142
- )
143
- */
144
-
145
- function byName ( a , b ) {
146
- return (
147
- b . path . localeCompare ( a . path ) +
148
- a . name . substring ( 0 , 12 ) . localeCompare ( b . name . substring ( 0 , 12 ) ) * 10
115
+ {
116
+ name : `3. configureStore` ,
117
+ import : { '@reduxjs/toolkit' : '{ configureStore }' } ,
118
+ } ,
119
+ {
120
+ name : `3. createApi` ,
121
+ import : { '@reduxjs/toolkit/query' : '{ createApi }' } ,
122
+ } ,
123
+ {
124
+ name : `3. createApi (react)` ,
125
+ import : { '@reduxjs/toolkit/query/react' : '{ createApi }' } ,
126
+ } ,
127
+ {
128
+ name : `3. fetchBaseQuery` ,
129
+ import : { '@reduxjs/toolkit/query' : '{ fetchBaseQuery }' } ,
130
+ } ,
131
+ {
132
+ name : `3. setupListeners` ,
133
+ import : { '@reduxjs/toolkit/query' : '{ setupListeners }' } ,
134
+ } ,
135
+ {
136
+ name : `3. ApiProvider` ,
137
+ import : { '@reduxjs/toolkit/query/react' : '{ ApiProvider }' } ,
138
+ } ,
139
+ ] . map ( ( e ) => ( {
140
+ ...e ,
141
+ name : e . name + ` (esm.js)` ,
142
+ modifyWebpackConfig : withRtkPath ( 'esm.js' ) ,
143
+ } ) )
149
144
)
150
- }
0 commit comments