Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6064095

Browse files
committed
split webpack configs
1 parentd47fa70 commit6064095

File tree

9 files changed

+145
-114
lines changed

9 files changed

+145
-114
lines changed

‎package.json‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name":"redux-ts",
33
"version":"2.6.0",
44
"description":"Utils to define redux reducer/action in typescript",
5-
"main":"lib/index.js",
6-
"typings":"lib/src/index.d.ts",
5+
"main":"dist/redux-ts.min.js",
6+
"typings":"dist/src/index.d.ts",
77
"files": [
88
"*.md",
99
"dist",
@@ -17,15 +17,12 @@
1717
],
1818
"license":"MIT",
1919
"scripts": {
20-
"build:dev":"cross-env NODE_ENV=dev webpack src/index.ts lib/index.js",
21-
"build:prod":"cross-env NODE_ENV=prod webpack src/index.ts dist/redux-ts.js",
22-
"build:prod:min":"cross-env NODE_ENV=prod webpack -p src/index.ts dist/redux-ts.min.js",
23-
"build:test":"cross-env NODE_ENV=test webpack --output-filename lib/specs.js",
20+
"build:dev":"webpack --config webpack.dev.js",
21+
"build:prod":"webpack --config webpack.prod.js",
2422
"clean":"rimraf dist lib",
25-
"build":"npm run build:dev && npm run build:test && npm run build:prod && npm run build:prod:min",
26-
"prepublish":"npm run clean && npm run build && npm run test:run",
27-
"test":"npm run clean && npm run build:test && npm run test:run",
28-
"test:run":"mocha --require source-map-support/register ./lib/specs.js"
23+
"build":"npm run build:dev && npm run build:prod",
24+
"prepublish":"npm run clean && npm run build && npm run test",
25+
"test":"mocha --require source-map-support/register --require ts-node/register **/*.spec.ts"
2926
},
3027
"tags": [
3128
"react",
@@ -58,17 +55,17 @@
5855
"@types/react":"^16.3.13",
5956
"@types/react-redux":"^5.0.19",
6057
"chai":"^4.1.2",
61-
"cross-env":"^5.1.4",
62-
"glob":"^7.1.2",
6358
"mocha":"^5.1.1",
6459
"prettier-tslint":"^0.4.0",
6560
"rimraf":"^2.6.2",
6661
"source-map-support":"^0.5.5",
6762
"ts-loader":"^4.2.0",
63+
"ts-node":"^6.0.3",
6864
"tslint-config-airbnb":"^5.8.0",
6965
"typescript":"^2.8.3",
7066
"webpack":"^4.7.0",
7167
"webpack-cli":"^2.1.3",
68+
"webpack-merge":"^4.1.2",
7269
"webpack-node-externals":"^1.7.2"
7370
},
7471
"peerDependencies": {

‎src/utils/actionHelpers.ts‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,38 @@
11
import'./promiseHelpers'
22
import{Dispatch,Action}from'redux'
33

4-
exporttypeNullableDispatch=Dispatch<any>|void
5-
64
exportabstractclassSyncActionimplementsAction<string>{
75
type:string
86
}
97

10-
exportabstractclassAsyncActionextendsSyncAction{
8+
exportabstractclassAsyncActionextendsSyncAction
9+
implementsPromise<Dispatch>{
1110
privateresolve:(value?:Dispatch<any>|PromiseLike<Dispatch<any>>)=>void
1211
privatepromise:Promise<Dispatch<any>>=newPromise<Dispatch<any>>(
1312
(resolve,reject)=>{
1413
this.resolve=resolve
1514
},
1615
)
1716

18-
then(
19-
onfulfilled?:(
20-
value:Dispatch<any>,
21-
)=>NullableDispatch|PromiseLike<NullableDispatch>,
22-
onrejected?:(reason:any)=>void,
23-
):Promise<NullableDispatch>{
17+
then<TResult1=Dispatch,TResult2=never>(
18+
onfulfilled?:(value:Dispatch)=>TResult1|PromiseLike<TResult1>,
19+
onrejected?:(reason:any)=>TResult2|PromiseLike<TResult2>,
20+
):Promise<TResult1|TResult2>{
2421
returnthis.promise.then(onfulfilled,onrejected)
2522
}
2623

27-
catch(
28-
onrejected?:(
29-
reason:any,
30-
)=>NullableDispatch|PromiseLike<NullableDispatch>,
31-
):Promise<NullableDispatch>{
24+
catch<TResult=never>(
25+
onrejected?:(reason:any)=>TResult|PromiseLike<TResult>,
26+
):Promise<Dispatch|TResult>{
3227
returnthis.promise.catch(onrejected)
3328
}
3429

35-
finally(
30+
finally<TResult>(
3631
onfulfilled?:(
37-
value?:NullableDispatch,
32+
value?:Dispatch,
3833
isSuccess?:boolean,
39-
)=>any|PromiseLike<NullableDispatch>,
40-
):Promise<NullableDispatch>{
34+
)=>TResult|PromiseLike<TResult>,
35+
):Promise<TResult>{
4136
returnthis.promise.finally(onfulfilled)
4237
}
4338
}

‎src/utils/reducerBuilder.ts‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import{Action}from'redux'
2-
import{SyncAction,AsyncAction}from'../utils/actionHelpers'
1+
import{Action,Reducer}from'redux'
2+
import{SyncAction}from'../utils/actionHelpers'
33

44
exportinterfaceIAction<TextendsAction>{
55
prototype:T
66
}
77

8-
exporttypeReducer<State,ActionTypeextendsSyncAction>=(
9-
state:State,
10-
action:ActionType,
11-
)=>State
12-
138
exportclassReducerBuilder<State>{
149
privateactions:{[type:string]:Reducer<State,SyncAction>}={}
1510
privateinitState:State
@@ -20,10 +15,10 @@ export class ReducerBuilder<State> {
2015
}
2116

2217
publichandle<TextendsSyncAction>(
23-
actionType:IAction<T>,
24-
actionBody:Reducer<State,T>,
18+
type:IAction<T>,
19+
action:Reducer<State,T>,
2520
){
26-
this.actions[(<any>actionType).name]=actionBody
21+
this.actions[(<any>type).name]=action
2722
returnthis
2823
}
2924

‎src/utils/storeBuilder.ts‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@ import {
1313
import{asyncMiddleware}from'./asyncMiddleware'
1414
import'./browserPolyfill'
1515

16-
constdevTools:StoreEnhancer=f=>
17-
(windowasany).__REDUX_DEVTOOLS_EXTENSION__
18-
?(windowasany).__REDUX_DEVTOOLS_EXTENSION__
19-
:f
20-
21-
exportclassStoreBuilder<StoreType>{
16+
exportclassStoreBuilder<StoreTypeextends{[key:string]:any}>{
2217
privatemiddlewares:Middleware[]
23-
privatereducers:ReducersMapObject
18+
privatereducers:ReducersMapObject<StoreType>
2419
privateinitialState:DeepPartial<StoreType>
2520
privateenhancer:StoreEnhancer
2621

2722
constructor(){
28-
this.middlewares=[]
29-
this.reducers={}
23+
this.middlewares=[asyncMiddleware]
24+
this.reducers={}asStoreType
3025
this.initialState={}
3126
this.enhancer=f=>f
3227
}
@@ -41,7 +36,7 @@ export class StoreBuilder<StoreType> {
4136
returnthis
4237
}
4338

44-
publicwithReducer<K=keyofStoreType>(name:K,reducer:Reducer){
39+
publicwithReducer(name:string,reducer:Reducer){
4540
this.reducers[name]=reducer
4641
returnthis
4742
}
@@ -54,17 +49,23 @@ export class StoreBuilder<StoreType> {
5449
}
5550

5651
publicwithEnhancer(enhancer:StoreEnhancer){
57-
this.enhancer=f=>enhancer(this.enhancer(f))
52+
constpreEnhancer=this.enhancer
53+
this.enhancer=f=>enhancer(preEnhancer(f))
5854
returnthis
5955
}
6056

6157
publicwithDevTools(){
62-
this.withEnhancer(devTools)
58+
this.withEnhancer(
59+
f=>
60+
(windowasany).__REDUX_DEVTOOLS_EXTENSION__
61+
?(windowasany).__REDUX_DEVTOOLS_EXTENSION__
62+
:f,
63+
)
6364
returnthis
6465
}
6566

6667
publicbuild():Store<StoreType>{
67-
constmiddlewares=applyMiddleware(...this.middlewares,asyncMiddleware)
68+
constmiddlewares=applyMiddleware(...this.middlewares)
6869
constreducers=combineReducers<StoreType>(this.reducers)
6970
constcomposer=compose(middlewares,this.enhancer)(createStore)
7071
conststore=composer(reducers,this.initialState)

‎webpack.common.js‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
constwebpack=require("webpack")
2+
constnodeExternals=require("webpack-node-externals")
3+
4+
module.exports={
5+
externals:[nodeExternals()],
6+
entry:"./src/index.ts",
7+
resolve:{
8+
extensions:[".ts",".tsx",".js",".jsx"]
9+
},
10+
module:{
11+
rules:[
12+
{
13+
test:/\.tsx?$/,
14+
use:[
15+
{
16+
loader:"ts-loader",
17+
options:{
18+
compilerOptions:{
19+
declaration:true,
20+
sourceMap:true
21+
}
22+
}
23+
}
24+
]
25+
}
26+
]
27+
},
28+
29+
plugins:[
30+
// new webpack.DefinePlugin({
31+
// "process.env.NODE_ENV": JSON.stringify(env)
32+
// }),
33+
// new webpack.SourceMapDevToolPlugin({
34+
// filename: "[file].map"
35+
// })
36+
]
37+
}

‎webpack.config.js‎

Lines changed: 0 additions & 47 deletions
This file was deleted.

‎webpack.dev.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
constmerge=require("webpack-merge")
2+
constcommon=require("./webpack.common.js")
3+
4+
module.exports=merge(common,{
5+
mode:"development",
6+
devtool:"source-map",
7+
output:{
8+
filename:"redux-ts.js"
9+
}
10+
})

‎webpack.prod.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
constmerge=require("webpack-merge")
2+
constcommon=require("./webpack.common.js")
3+
constUglifyJSPlugin=require("uglifyjs-webpack-plugin")
4+
5+
module.exports=merge(common,{
6+
mode:"production",
7+
devtool:"source-map",
8+
output:{
9+
library:"ReduxTs",
10+
libraryTarget:"umd",
11+
umdNamedDefine:true,
12+
globalObject:"this",
13+
filename:"redux-ts.min.js"
14+
},
15+
optimization:{
16+
minimizer:[
17+
newUglifyJSPlugin({
18+
sourceMap:true,
19+
uglifyOptions:{
20+
mangle:{
21+
keep_fnames:true
22+
}
23+
}
24+
})
25+
]
26+
}
27+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp