Jul
AUG
Sep
21
2020
2021
2022
About this capture
T h e W a y b a c k M a c h i n e - h t t p : / / w e b . a r c h i v e . o r g / w e b / 2 0 2 1 0 8 2 1 1 9 3 0 1 6 / h t t p s : / / w e b p a c k . j s . o r g / c o n f i g u r a t i o n / d e v - s e r v e r /
C o n t r i b u t e V o t e B l o g
● E n g l i s h
● 中 文
● 한 국 어
S e a r c h
a p i c o n c e p t s g u i d e s l o a d e r s m i g r a t e p l u g i n s
a g - g r i d i s p r o u d t o p a r t n e r w i t h w e b p a c k
Webpack 5 Webpack 4
● U s e a d i f f e r e n t c o n f i g u r a t i o n f i l e
● O p t i o n s
● T y p e S c r i p t
● C o f f e e S c r i p t
● B a b e l a n d J S X
● E x p o r t i n g a F u n c t i o n
● E x p o r t i n g a P r o m i s e
● E x p o r t i n g m u l t i p l e c o n f i g u r a t i o n s
● p a r a l l e l i s m
● c o n t e x t
● e n t r y
● N a m i n g
● E n t r y d e s c r i p t o r
● O u t p u t f i l e n a m e
● D e p e n d e n c i e s
● D y n a m i c e n t r y
● U s a g e
● M o d e : d e v e l o p m e n t
● M o d e : p r o d u c t i o n
● M o d e : n o n e
● a s s e t M o d u l e F i l e n a m e
● a u x i l i a r y C o m m e n t
● c h a r s e t
● c h u n k F i l e n a m e
● c h u n k F o r m a t
● c h u n k L o a d T i m e o u t
● c h u n k L o a d i n g G l o b a l
● c h u n k L o a d i n g
● c l e a n
● c o m p a r e B e f o r e E m i t
● c r o s s O r i g i n L o a d i n g
● d e v t o o l F a l l b a c k M o d u l e F i l e n a m e T e m p l a t e
● d e v t o o l M o d u l e F i l e n a m e T e m p l a t e
● d e v t o o l N a m e s p a c e
● e n a b l e d C h u n k L o a d i n g T y p e s
● e n a b l e d L i b r a r y T y p e s
● e n a b l e d W a s m L o a d i n g T y p e s
● e n v i r o n m e n t
● f i l e n a m e
● T e m p l a t e s t r i n g s
● f u t u r e E m i t A s s e t s
● g l o b a l O b j e c t
● h a s h D i g e s t
● h a s h D i g e s t L e n g t h
● h a s h F u n c t i o n
● h a s h S a l t
● h o t U p d a t e C h u n k F i l e n a m e
● h o t U p d a t e G l o b a l
● h o t U p d a t e M a i n F i l e n a m e
● i i f e
● i m p o r t F u n c t i o n N a m e
● l i b r a r y
● n a m e
● t y p e
● e x p o r t
● a u x i l i a r y C o m m e n t
● u m d N a m e d D e f i n e
● l i b r a r y E x p o r t
● l i b r a r y T a r g e t
● E x p o s e a V a r i a b l e
● E x p o s e V i a O b j e c t A s s i g n m e n t
● M o d u l e D e f i n i t i o n S y s t e m s
● O t h e r T a r g e t s
● m o d u l e
● p a t h
● p a t h i n f o
● p u b l i c P a t h
● s c r i p t T y p e
● s o u r c e M a p F i l e n a m e
● s o u r c e P r e f i x
● s t r i c t M o d u l e E r r o r H a n d l i n g
● s t r i c t M o d u l e E x c e p t i o n H a n d l i n g
● t r u s t e d T y p e s
● u m d N a m e d D e f i n e
● u n i q u e N a m e
● w a s m L o a d i n g
● w o r k e r C h u n k L o a d i n g
● g e n e r a t o r
● p a r s e r
● j a v a s c r i p t
● n o P a r s e
● u n s a f e C a c h e
● r u l e s
● R u l e
● R u l e C o n d i t i o n s
● R u l e r e s u l t s
● N e s t e d r u l e s
● R u l e . e n f o r c e
● R u l e . e x c l u d e
● R u l e . i n c l u d e
● R u l e . i s s u e r
● R u l e . i s s u e r L a y e r
● R u l e . l a y e r
● R u l e . l o a d e r
● R u l e . l o a d e r s
● R u l e . m i m e t y p e
● R u l e . o n e O f
● R u l e . o p t i o n s / R u l e . q u e r y
● R u l e . p a r s e r
● R u l e . p a r s e r . d a t a U r l C o n d i t i o n
● R u l e . g e n e r a t o r
● d a t a U r l
● e m i t
● f i l e n a m e
● p u b l i c P a t h
● R u l e . r e s o u r c e
● R u l e . r e s o u r c e Q u e r y
● R u l e . p a r s e r . p a r s e
● R u l e . r u l e s
● R u l e . s c h e m e
● R u l e . s i d e E f f e c t s
● R u l e . t e s t
● R u l e . t y p e
● R u l e . u s e
● R u l e . r e s o l v e
● r e s o l v e . f u l l y S p e c i f i e d
● C o n d i t i o n
● U s e E n t r y
● M o d u l e C o n t e x t s
● r e s o l v e
● a l i a s
● a l i a s F i e l d s
● c a c h e W i t h C o n t e x t
● c o n d i t i o n N a m e s
● d e s c r i p t i o n F i l e s
● e n f o r c e E x t e n s i o n
● e x t e n s i o n s
● f a l l b a c k
● m a i n F i e l d s
● m a i n F i l e s
● e x p o r t s F i e l d s
● m o d u l e s
● u n s a f e C a c h e
● p l u g i n s
● p r e f e r R e l a t i v e
● p r e f e r A b s o l u t e
● s y m l i n k s
● c a c h e P r e d i c a t e
● r e s t r i c t i o n s
● r o o t s
● i m p o r t s F i e l d s
● b y D e p e n d e n c y
● r e s o l v e L o a d e r
● m i n i m i z e
● m i n i m i z e r
● s p l i t C h u n k s
● r u n t i m e C h u n k
● e m i t O n E r r o r s
● m o d u l e I d s
● c h u n k I d s
● n o d e E n v
● m a n g l e W a s m I m p o r t s
● r e m o v e A v a i l a b l e M o d u l e s
● r e m o v e E m p t y C h u n k s
● m e r g e D u p l i c a t e C h u n k s
● f l a g I n c l u d e d C h u n k s
● p r o v i d e d E x p o r t s
● u s e d E x p o r t s
● c o n c a t e n a t e M o d u l e s
● s i d e E f f e c t s
● p o r t a b l e R e c o r d s
● m a n g l e E x p o r t s
● i n n e r G r a p h
● r e a l C o n t e n t H a s h
● p l u g i n s
● d e v S e r v e r
● U s a g e v i a C L I
● a l l o w e d H o s t s
● b o n j o u r
● c l i e n t
● l o g g i n g
● o v e r l a y
● p r o g r e s s
● w e b S o c k e t T r a n s p o r t
● w e b S o c k e t U R L
● c o m p r e s s
● d e v M i d d l e w a r e
● h t t p 2
● h t t p s
● h e a d e r s
● h i s t o r y A p i F a l l b a c k
● h o s t
● l o c a l - i p
● l o c a l - i p v 4
● l o c a l - i p v 6
● h o t
● i p c
● l i v e R e l o a d
● o n A f t e r S e t u p M i d d l e w a r e
● o n B e f o r e S e t u p M i d d l e w a r e
● o n L i s t e n i n g
● o p e n
● p o r t
● p r o x y
● s e t u p E x i t S i g n a l s
● s t a t i c
● d i r e c t o r y
● s t a t i c O p t i o n s
● p u b l i c P a t h
● s e r v e I n d e x
● w a t c h
● w a t c h F i l e s
● w e b S o c k e t S e r v e r
● c a c h e
● a l l o w C o l l e c t i n g M e m o r y
● b u i l d D e p e n d e n c i e s
● c a c h e D i r e c t o r y
● c a c h e L o c a t i o n
● c o m p r e s s i o n
● h a s h A l g o r i t h m
● i d l e T i m e o u t
● i d l e T i m e o u t A f t e r L a r g e C h a n g e s
● i d l e T i m e o u t F o r I n i t i a l S t o r e
● m a n a g e d P a t h s
● m a x A g e
● m a x G e n e r a t i o n s
● m a x M e m o r y G e n e r a t i o n s
● n a m e
● p r o f i l e
● s t o r e
● t y p e
● v e r s i o n
● d e v t o o l
● Q u a l i t i e s
● D e v e l o p m e n t
● S p e c i a l c a s e s
● P r o d u c t i o n
● t a r g e t
● s t r i n g
● [ s t r i n g ]
● f a l s e
● w a t c h
● w a t c h O p t i o n s
● a g g r e g a t e T i m e o u t
● i g n o r e d
● p o l l
● f o l l o w S y m l i n k s
● T r o u b l e s h o o t i n g
● C h a n g e s S e e n B u t N o t P r o c e s s e d
● N o t E n o u g h W a t c h e r s
● m a c O S f s e v e n t s B u g
● W i n d o w s P a t h s
● V i m
● S a v i n g i n W e b S t o r m
● e x t e r n a l s
● s t r i n g
● [ s t r i n g ]
● o b j e c t
● f u n c t i o n
● R e g E x p
● C o m b i n i n g s y n t a x e s
● b y L a y e r
● e x t e r n a l s T y p e
● m o d u l e
● n o d e - c o m m o n j s
● s c r i p t
● e x t e r n a l s P r e s e t s
● p e r f o r m a n c e
● a s s e t F i l t e r
● h i n t s
● m a x A s s e t S i z e
● m a x E n t r y p o i n t S i z e
● n o d e
● g l o b a l
● _ _ f i l e n a m e
● _ _ d i r n a m e
● S t a t s P r e s e t s
● S t a t s O p t i o n s
● s t a t s . a l l
● s t a t s . a s s e t s
● s t a t s . a s s e t s S o r t
● s t a t s . b u i l t A t
● s t a t s . m o d u l e A s s e t s
● s t a t s . a s s e t s S p a c e
● s t a t s . m o d u l e s S p a c e
● s t a t s . c h u n k M o d u l e s S p a c e
● s t a t s . n e s t e d M o d u l e s S p a c e
● s t a t s . c a c h e d
● s t a t s . c a c h e d M o d u l e s
● s t a t s . r u n t i m e M o d u l e s
● s t a t s . d e p e n d e n t M o d u l e s
● s t a t s . g r o u p A s s e t s B y C h u n k
● s t a t s . g r o u p A s s e t s B y E m i t S t a t u s
● s t a t s . g r o u p A s s e t s B y I n f o
● s t a t s . g r o u p M o d u l e s B y A t t r i b u t e s
● s t a t s . g r o u p R e a s o n s B y O r i g i n
● s t a t s . c a c h e d A s s e t s
● s t a t s . c h i l d r e n
● s t a t s . c h u n k s
● s t a t s . c h u n k G r o u p s
● s t a t s . c h u n k M o d u l e s
● s t a t s . c h u n k O r i g i n s
● s t a t s . c h u n k s S o r t
● s t a t s . c o n t e x t
● s t a t s . c o l o r s
● s t a t s . d e p t h
● s t a t s . e n t r y p o i n t s
● s t a t s . e n v
● s t a t s . o r p h a n M o d u l e s
● s t a t s . e r r o r s
● s t a t s . e r r o r D e t a i l s
● s t a t s . e r r o r S t a c k
● s t a t s . e x c l u d e A s s e t s
● s t a t s . e x c l u d e M o d u l e s
● s t a t s . e x c l u d e
● s t a t s . h a s h
● s t a t s . l o g g i n g
● s t a t s . l o g g i n g D e b u g
● s t a t s . l o g g i n g T r a c e
● s t a t s . m o d u l e s
● s t a t s . m o d u l e s S o r t
● s t a t s . m o d u l e T r a c e
● s t a t s . o u t p u t P a t h
● s t a t s . p e r f o r m a n c e
● s t a t s . p r e s e t
● s t a t s . p r o v i d e d E x p o r t s
● s t a t s . e r r o r s C o u n t
● s t a t s . w a r n i n g s C o u n t
● s t a t s . p u b l i c P a t h
● s t a t s . r e a s o n s
● s t a t s . r e a s o n s S p a c e
● s t a t s . r e l a t e d A s s e t s
● s t a t s . s o u r c e
● s t a t s . t i m i n g s
● s t a t s . i d s
● s t a t s . u s e d E x p o r t s
● s t a t s . v e r s i o n
● s t a t s . c h u n k G r o u p A u x i l i a r y
● s t a t s . c h u n k G r o u p C h i l d r e n
● s t a t s . c h u n k G r o u p M a x A s s e t s
● s t a t s . w a r n i n g s
● s t a t s . w a r n i n g s F i l t e r
● s t a t s . c h u n k R e l a t i o n s
● S o r t i n g f i e l d s
● E x t e n d i n g s t a t s b e h a v i o u r s
● e x p e r i m e n t s
● b u i l d H t t p
● e x e c u t e M o d u l e
● l a z y C o m p i l a t i o n
● o u t p u t M o d u l e
● a m d
● b a i l
● d e p e n d e n c i e s
● i g n o r e W a r n i n g s
● i n f r a s t r u c t u r e L o g g i n g
● a p p e n d O n l y
● c o l o r s
● c o n s o l e
● d e b u g
● l e v e l
● s t r e a m
● l o a d e r
● n a m e
● p a r a l l e l i s m
● p r o f i l e
● r e c o r d s I n p u t P a t h
● r e c o r d s O u t p u t P a t h
● r e c o r d s P a t h
● s n a p s h o t
● b u i l d D e p e n d e n c i e s
● i m m u t a b l e P a t h s
● m a n a g e d P a t h s
● m o d u l e
● r e s o l v e
● r e s o l v e B u i l d D e p e n d e n c i e s
D e v S e r v e r
w e b p a c k - d e v - s e r v e r c a n b e u s e d t o q u i c k l y d e v e l o p a n a p p l i c a t i o n . S e e t h e d e v e l o p m e n t g u i d e t o g e t s t a r t e d .
T h i s p a g e d e s c r i b e s t h e o p t i o n s t h a t a f f e c t t h e b e h a v i o r o f w e b p a c k - d e v - s e r v e r ( s h o r t : d e v - s e r v e r ) v e r s i o n > = 4 . 0 . 0 . M i g r a t i o n g u i d e f r o m v 3 to v 4 c a n b e f o u n d h e r e .
d e v S e r v e r
o b j e c t
T h i s s e t o f o p t i o n s i s p i c k e d u p b y w e b p a c k - d e v - s e r v e r a n d c a n b e u s e d t o c h a n g e i t s b e h a v i o r i n v a r i o u s w a y s . H e r e ' s a r u d i m e n t a r y e x a m p l e t h a t g z i p s a n d s e r v e s e v e r y t h i n g f r o m o u r p u b l i c / d i r e c t o r y i n t h e p r o j e c t r o o t :
w e b p a c k . c o n f i g . j s
var path = require ( 'path' ) ;
module. exports = {
devServer: {
static : {
directory: path. join ( __dirname, 'public' ) ,
} ,
compress: true ,
port: 9000 ,
} ,
} ;
W h e n t h e s e r v e r i s s t a r t e d , t h e r e w i l l b e a m e s s a g e p r i o r t o t h e l i s t o f r e s o l v e d m o d u l e s :
< i > [ webpack-dev-server] Project is running at:
< i > [ webpack-dev-server] Loopback: http://localhost:9000/
< i > [ webpack-dev-server] On Your Network ( IPv4) : http://197.158.164.104:9000/
< i > [ webpack-dev-server] On Your Network ( IPv6) : http://[ fe80::1] :9000/
< i > [ webpack-dev-server] Content not from webpack is served from '/path/to/public' directory
t h a t w i l l g i v e s o m e b a c k g r o u n d o n w h e r e t h e s e r v e r i s l o c a t e d a n d w h a t i t ' s s e r v i n g .
I f y o u ' r e u s i n g d e v - s e r v e r t h r o u g h t h e N o d e . j s A P I , t h e o p t i o n s i n d e v S e r v e r w i l l b e i g n o r e d . P a s s t h e o p t i o n s a s t h e f i r s t p a r a m e t e r i n s t e a d : n e w W e b p a c k D e v S e r v e r ( { . . . } , c o m p i l e r ) . S e e h e r e f o r a n e x a m p l e o f h o w t o u s e w e b p a c k - d e v - s e r v e r t h r o u g h t h e N o d e . j s A P I .
w a r n i n g
Y o u c a n n o t u s e t h e s e c o n d c o m p i l e r a r g u m e n t ( a c a l l b a c k ) w h e n u s i n g W e b p a c k D e v S e r v e r .
w a r n i n g
B e a w a r e t h a t w h e n e x p o r t i n g m u l t i p l e c o n f i g u r a t i o n s o n l y t h e d e v S e r v e r o p t i o n s f o r t h e f i r s t c o n f i g u r a t i o n w i l l b e t a k e n i n t o a c c o u n t a n d u s e d f o r a l l t h e c o n f i g u r a t i o n s i n t h e a r r a y .
t i p
I f y o u ' r e h a v i n g t r o u b l e , n a v i g a t i n g t o t h e / w e b p a c k - d e v - s e r v e r r o u t e w i l l s h o w w h e r e f i l e s a r e s e r v e d . F o r e x a m p l e , h t t p : / / l o c a l h o s t : 9 0 0 0 / w e b p a c k - d e v - s e r v e r .
t i p
I f y o u w a n t t o m a n u a l l y r e c o m p i l e t h e b u n d l e , n a v i g a t i n g t o t h e / i n v a l i d a t e r o u t e w i l l i n v a l i d a t e t h e c u r r e n t c o m p i l a t i o n o f t h e b u n d l e a n d r e c o m p i l e i t f o r y o u v i a w e b p a c k - d e v - m i d d l e w a r e . D e p e n d i n g o n y o u r c o n f i g u r a t i o n , U R L m a y l o o k l i k e h t t p : / / l o c a l h o s t : 9 0 0 0 / i n v a l i d a t e .
t i p
H T M L t e m p l a t e i s r e q u i r e d t o s e r v e t h e b u n d l e , u s u a l l y i t i s a n i n d e x . h t m l f i l e . M a k e s u r e t h a t s c r i p t r e f e r e n c e s a r e a d d e d i n t o H T M L , w e b p a c k - d e v - s e r v e r d o e s n ' t i n j e c t t h e m a u t o m a t i c a l l y .
U s a g e v i a C L I
Y o u c a n i n v o k e w e b p a c k - d e v - s e r v e r v i a C L I b y :
npx webpack serve
A l i s t o f C L I o p t i o n s f o r s e r v e i s a v a i l a b l e h e r e
d e v S e r v e r . a l l o w e d H o s t s
' a u t o ' | ' a l l ' [ s t r i n g ]
T h i s o p t i o n a l l o w s y o u t o w h i t e l i s t s e r v i c e s t h a t a r e a l l o w e d t o a c c e s s t h e d e v s e r v e r .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
allowedHosts: [
'host.com' ,
'subdomain.host.com' ,
'subdomain2.host.com' ,
'host2.com' ,
] ,
} ,
} ;
M i m i c k i n g d j a n g o ' s A L L O W E D _ H O S T S , a v a l u e b e g i n n i n g w i t h . c a n b e u s e d a s a s u b d o m a i n w i l d c a r d . . h o s t . c o m w i l l m a t c h h o s t . c o m , w w w . h o s t . c o m , a n d a n y o t h e r s u b d o m a i n o f h o s t . c o m .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
allowedHosts: [ '.host.com' , 'host2.com' ] ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --allowed-hosts .host.com --allowed-hosts host2.com
W h e n s e t t o ' a l l ' t h i s o p t i o n b y p a s s e s h o s t c h e c k i n g . T H I S I S N O T R E C O M M E N D E D a s a p p s t h a t d o n o t c h e c k t h e h o s t a r e v u l n e r a b l e t o D N S r e b i n d i n g a t t a c k s .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
allowedHosts: 'all' ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --allowed-hosts all
d e v S e r v e r . b o n j o u r
b o o l e a n o b j e c t
T h i s o p t i o n b r o a d c a s t s t h e s e r v e r v i a Z e r o C o n f n e t w o r k i n g o n s t a r t .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
bonjour: true ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --bonjour
T o d i s a b l e :
npx webpack serve --no-bonjour
Y o u c a n a l s o p a s s c u s t o m o p t i o n s t o b o n j o u r , f o r e x a m p l e :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
bonjour: {
type: 'http' ,
protocol: 'udp' ,
} ,
} ,
} ;
d e v S e r v e r . c l i e n t
l o g g i n g
' l o g ' | ' i n f o ' | ' w a r n ' | ' e r r o r ' | ' n o n e ' | ' v e r b o s e '
A l l o w s t o s e t l o g l e v e l i n t h e b r o w s e r , e . g . b e f o r e r e l o a d i n g , b e f o r e a n e r r o r o r w h e n H o t M o d u l e R e p l a c e m e n t i s e n a b l e d .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
client: {
logging: 'info' ,
} ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --client-logging info
o v e r l a y
b o o l e a n = t r u e o b j e c t : { e r r o r s b o o l e a n = t r u e , w a r n i n g s b o o l e a n = t r u e }
S h o w s a f u l l - s c r e e n o v e r l a y i n t h e b r o w s e r w h e n t h e r e a r e c o m p i l e r e r r o r s o r w a r n i n g s .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
client: {
overlay: true ,
} ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --client-overlay
T o d i s a b l e :
npx webpack serve --no-client-overlay
I f y o u w a n t t o s h o w o n l y e r r o r s :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
client: {
overlay: {
errors: true ,
warnings: false ,
} ,
} ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --client-overlay-errors --no-client-overlay-warnings
p r o g r e s s
P r i n t s c o m p i l a t i o n p r o g r e s s i n p e r c e n t a g e i n t h e b r o w s e r .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
client: {
progress: true ,
} ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --client-progress
T o d i s a b l e :
npx webpack serve --no-client-progress
w e b S o c k e t T r a n s p o r t
' w s ' | ' s o c k j s ' s t r i n g
T h i s o p t i o n a l l o w s u s e i t h e r t o c h o o s e t h e c u r r e n t d e v S e r v e r t r a n s p o r t m o d e f o r c l i e n t i n d i v i d u a l l y o r t o p r o v i d e c u s t o m c l i e n t i m p l e m e n t a t i o n . T h i s a l l o w s t o s p e c i f y h o w b r o w s e r o r o t h e r c l i e n t c o m m u n i c a t e s w i t h t h e d e v S e r v e r .
t i p
P r o v i d i n g ' w s ' or ' s o c k j s ' to w e b S o c k e t S e r v e r i s a s h o r t c u t t o s e t t i n g b o t h d e v S e r v e r . c l i e n t . w e b S o c k e t T r a n s p o r t a n d d e v S e r v e r . w e b S o c k e t S e r v e r t o t h e g i v e n v a l u e .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
client: {
webSocketTransport: 'ws' ,
} ,
webSocketServer: 'ws' ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --client-web-socket-transport ws --web-socket-server ws
t i p
W h e n p r o v i d i n g a c u s t o m c l i e n t a n d s e r v e r i m p l e m e n t a t i o n m a k e s u r e t h a t t h e y a r e c o m p a t i b l e w i t h o n e a n o t h e r t o c o m m u n i c a t e s u c c e s s f u l l y .
T o c r e a t e a c u s t o m c l i e n t i m p l e m e n t a t i o n , c r e a t e a c l a s s t h a t e x t e n d s B a s e C l i e n t .
U s i n g p a t h t o C u s t o m C l i e n t . j s , a c u s t o m W e b S o c k e t c l i e n t i m p l e m e n t a t i o n , a l o n g w i t h t h e c o m p a t i b l e ' w s ' s e r v e r :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
client: {
webSocketTransport: require. resolve ( './CustomClient' ) ,
} ,
webSocketServer: 'ws' ,
} ,
} ;
U s i n g c u s t o m , c o m p a t i b l e W e b S o c k e t c l i e n t a n d s e r v e r i m p l e m e n t a t i o n s :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
client: {
webSocketTransport: require. resolve ( './CustomClient' ) ,
} ,
webSocketServer: require. resolve ( './CustomServer' ) ,
} ,
} ;
w e b S o c k e t U R L
s t r i n g o b j e c t
T h i s o p t i o n a l l o w s t o s p e c i f y U R L t o w e b s o c k e t s e r v e r ( u s e f u l w h e n y o u ' r e p r o x y i n g d e v s e r v e r a n d c l i e n t s c r i p t d o e s n o t a l w a y s k n o w w h e r e t o c o n n e c t t o ) .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
client: {
webSocketURL: 'ws://0.0.0.0:8080/ws' ,
} ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --client-web-socket-url ws://0.0.0.0:8080/ws
Y o u c a n a l s o s p e c i f y a n o b j e c t w i t h t h e f o l l o w i n g p r o p e r t i e s :
● h o s t n a m e : T e l l s c l i e n t s c o n n e c t e d t o d e v S e r v e r t o u s e t h e p r o v i d e d h o s t n a m e .
● p a t h n a m e : T e l l s c l i e n t s c o n n e c t e d t o d e v S e r v e r t o u s e t h e p r o v i d e d p a t h t o c o n n e c t .
● p a s s w o r d : T e l l s c l i e n t s c o n n e c t e d t o d e v S e r v e r t o u s e t h e p r o v i d e d p a s s w o r d t o a u t h e n t i c a t e .
● p o r t : T e l l s c l i e n t s c o n n e c t e d t o d e v S e r v e r t o u s e t h e p r o v i d e d p o r t .
● p r o t o c o l : T e l l s c l i e n t s c o n n e c t e d t o d e v S e r v e r t o u s e t h e p r o v i d e d p r o t o c o l .
● u s e r n a m e : T e l l s c l i e n t s c o n n e c t e d t o d e v S e r v e r t o u s e t h e p r o v i d e d u s e r n a m e t o a u t h e n t i c a t e .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
client: {
webSocketURL: {
hostname: '0.0.0.0' ,
pathname: '/ws' ,
password: 'dev-server' ,
port: 8080 ,
protocol: 'ws' ,
username: 'webpack' ,
} ,
} ,
} ,
} ;
t i p
T o g e t p r o t o c o l / h o s t n a m e / p o r t f r o m b r o w s e r u s e w e b S o c k e t U R L : ' a u t o : / / 0 . 0 . 0 . 0 : 0 / w s ' .
d e v S e r v e r . c o m p r e s s
b o o l e a n = t r u e
E n a b l e g z i p c o m p r e s s i o n f o r e v e r y t h i n g s e r v e d :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
compress: true ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --compress
T o d i s a b l e :
npx webpack serve --no-compress
d e v s e r v e r . d e v M i d d l e w a r e
P r o v i d e o p t i o n s t o w e b p a c k - d e v - m i d d l e w a r e w h i c h h a n d l e s w e b p a c k a s s e t s .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
index: true ,
mimeTypes: { 'text/html' : [ 'phtml' ] } ,
publicPath: '/publicPathForDevServe' ,
serverSideRender: true ,
writeToDisk: true ,
} ,
} ;
d e v S e r v e r . h t t p 2
b o o l e a n
S e r v e o v e r H T T P / 2 u s i n g s p d y . T h i s o p t i o n i s i g n o r e d f o r N o d e 1 5 . 0 . 0 a n d a b o v e , a s s p d y i s b r o k e n f o r t h o s e v e r s i o n s . T h e d e v s e r v e r w i l l m i g r a t e o v e r t o N o d e ' s b u i l t - i n H T T P / 2 o n c e E x p r e s s s u p p o r t s i t .
H T T P / 2 w i t h a s e l f - s i g n e d c e r t i f i c a t e :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
http2: true ,
} ,
} ;
P r o v i d e y o u r o w n c e r t i f i c a t e u s i n g t h e h t t p s o p t i o n :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
http2: true ,
https: {
key: fs . readFileSync ( '/path/to/server.key' ) ,
cert: fs . readFileSync ( '/path/to/server.crt' ) ,
cacert: fs . readFileSync ( '/path/to/ca.pem' ) ,
} ,
} ,
} ;
U s a g e v i a C L I
npx webpack serve --http2
T o d i s a b l e :
npx webpack serve --no-http2
T o p a s s y o u r o w n c e r t i f i c a t e v i a C L I , u s e t h e f o l l o w i n g o p t i o n s :
npx webpack serve --http2 --https-key ./path/to/server.key --https-cert ./path/to/server.crt --https-cacert ./path/to/ca.pem
d e v S e r v e r . h t t p s
b o o l e a n o b j e c t
B y d e f a u l t , d e v - s e r v e r w i l l b e s e r v e d o v e r H T T P . I t c a n o p t i o n a l l y b e s e r v e d o v e r H T T P / 2 w i t h H T T P S :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
https: true ,
} ,
} ;
W i t h t h e a b o v e s e t t i n g , a s e l f - s i g n e d c e r t i f i c a t e i s u s e d , b u t y o u c a n p r o v i d e y o u r o w n :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
https: {
cacert: './server.pem' ,
pfx: './server.pfx' ,
key: './server.key' ,
cert: './server.crt' ,
passphrase: 'webpack-dev-server' ,
requestCert: true ,
} ,
} ,
} ;
T h i s o b j e c t i s p a s s e d s t r a i g h t t o N o d e . j s H T T P S m o d u l e , s o s e e t h e H T T P S d o c u m e n t a t i o n f o r m o r e i n f o r m a t i o n .
U s a g e v i a t h e C L I :
npx webpack serve --https
T o d i s a b l e :
npx webpack serve --no-https
T o p a s s y o u r o w n c e r t i f i c a t e v i a t h e C L I u s e t h e f o l l o w i n g o p t i o n s :
npx webpack serve --https-key ./path/to/server.key --https--cert ./path/to/server.crt --https-cacert ./path/to/ca.pem
f u n c t i o n o b j e c t
A d d s h e a d e r s t o a l l r e s p o n s e s :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
headers: {
'X-Custom-Foo' : 'bar' ,
} ,
} ,
} ;
d e v S e r v e r . h i s t o r y A p i F a l l b a c k
b o o l e a n o b j e c t
W h e n u s i n g t h e H T M L 5 H i s t o r y A P I , t h e i n d e x . h t m l p a g e w i l l l i k e l y h a v e t o b e s e r v e d i n p l a c e o f a n y 4 0 4 r e s p o n s e s . E n a b l e d e v S e r v e r . h i s t o r y A p i F a l l b a c k b y s e t t i n g i t t o t r u e :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
historyApiFallback: true ,
} ,
} ;
B y p a s s i n g a n o b j e c t t h i s b e h a v i o r c a n b e c o n t r o l l e d f u r t h e r u s i n g o p t i o n s l i k e r e w r i t e s :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
historyApiFallback: {
rewrites: [
{ from : /^\/$/ , to : '/views/landing.html' } ,
{ from : /^\/subpage/ , to : '/views/subpage.html' } ,
{ from : /./ , to : '/views/404.html' } ,
] ,
} ,
} ,
} ;
W h e n u s i n g d o t s i n y o u r p a t h ( c o m m o n w i t h A n g u l a r ) , y o u m a y n e e d t o u s e t h e d i s a b l e D o t R u l e :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
historyApiFallback: {
disableDotRule: true ,
} ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --history-api-fallback
T o d i s a b l e :
npx webpack serve --no-history-api-fallback
F o r m o r e o p t i o n s a n d i n f o r m a t i o n , s e e t h e c o n n e c t - h i s t o r y - a p i - f a l l b a c k d o c u m e n t a t i o n .
d e v S e r v e r . h o s t
' l o c a l - i p ' | ' l o c a l - i p v 4 ' | ' l o c a l - i p v 6 ' s t r i n g
S p e c i f y a h o s t t o u s e . I f y o u w a n t y o u r s e r v e r t o b e a c c e s s i b l e e x t e r n a l l y , s p e c i f y i t l i k e t h i s :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
host: '0.0.0.0' ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --host 0.0 .0.0
T h i s a l s o w o r k s w i t h I P v 6 :
npx webpack serve --host ::
l o c a l - i p
S p e c i f y i n g l o c a l - i p a s h o s t w i l l t r y t o r e s o l v e t h e h o s t o p t i o n a s y o u r l o c a l I P v 4 a d d r e s s i f a v a i l a b l e , i f I P v 4 i s n o t a v a i l a b l e i t w i l l t r y t o r e s o l v e y o u r l o c a l I P v 6 a d d r e s s .
npx webpack serve --host local-ip
l o c a l - i p v 4
S p e c i f y i n g l o c a l - i p v 4 a s h o s t w i l l t r y t o r e s o l v e t h e h o s t o p t i o n a s y o u r l o c a l I P v 4 a d d r e s s .
npx webpack serve --host local-ipv4
l o c a l - i p v 6
S p e c i f y i n g l o c a l - i p v 6 a s h o s t w i l l t r y t o r e s o l v e t h e h o s t o p t i o n a s y o u r l o c a l I P v 6 a d d r e s s .
npx webpack serve --host local-ipv6
d e v S e r v e r . h o t
' o n l y ' b o o l e a n
E n a b l e w e b p a c k ' s H o t M o d u l e R e p l a c e m e n t f e a t u r e :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
hot: true ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --hot
T o d i s a b l e :
npx webpack serve --no-hot
T o e n a b l e H o t M o d u l e R e p l a c e m e n t w i t h o u t p a g e r e f r e s h a s a f a l l b a c k i n c a s e o f b u i l d f a i l u r e s , u s e h o t : ' o n l y ' :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
hot: 'only' ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --hot only
t i p
N o t e t h a t w e b p a c k . H o t M o d u l e R e p l a c e m e n t P l u g i n i s r e q u i r e d t o f u l l y e n a b l e H M R . I f w e b p a c k or w e b p a c k - d e v - s e r v e r a r e l a u n c h e d w i t h t h e - - h o t o p t i o n , t h i s p l u g i n w i l l b e a d d e d a u t o m a t i c a l l y , s o y o u m a y n o t n e e d t o a d d t h i s t o y o u r w e b p a c k . c o n f i g . j s . S e e t h e H M R c o n c e p t s p a g e f o r m o r e i n f o r m a t i o n .
d e v S e r v e r . i p c
t r u e s t r i n g
T h e U n i x s o c k e t t o l i s t e n t o ( i n s t e a d o f a h o s t ) .
S e t t i n g i t t o t r u e w i l l l i s t e n t o a s o c k e t a t / y o u r - o s - t e m p - d i r / w e b p a c k - d e v - s e r v e r . s o c k :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
ipc: true ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --ipc
Y o u c a n a l s o l i s t e n t o a d i f f e r e n t s o c k e t w i t h :
w e b p a c k . c o n f i g . j s
const path = require ( 'path' ) ;
module. exports = {
devServer: {
ipc: path. join ( __dirname, 'my-socket.sock' ) ,
} ,
} ;
d e v S e r v e r . l i v e R e l o a d
b o o l e a n = t r u e
B y d e f a u l t , t h e d e v - s e r v e r w i l l r e l o a d / r e f r e s h t h e p a g e w h e n f i l e c h a n g e s a r e d e t e c t e d . d e v S e r v e r . h o t o p t i o n m u s t b e d i s a b l e d o r d e v S e r v e r . w a t c h F i l e s o p t i o n m u s t b e e n a b l e d i n o r d e r f o r l i v e R e l o a d t o t a k e e f f e c t . D i s a b l e d e v S e r v e r . l i v e R e l o a d b y s e t t i n g i t t o f a l s e :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
liveReload: false ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --live-reload
T o d i s a b l e :
npx webpack serve --no-live-reload
w a r n i n g
L i v e r e l o a d i n g w o r k s o n l y w i t h w e b r e l a t e d t a r g e t s l i k e w e b , w e b w o r k e r , e l e c t r o n - r e n d e r e r a n d n o d e - w e b k i t .
d e v S e r v e r . o n A f t e r S e t u p M i d d l e w a r e
f u n c t i o n ( d e v S e r v e r )
P r o v i d e s t h e a b i l i t y t o e x e c u t e c u s t o m m i d d l e w a r e a f t e r a l l o t h e r m i d d l e w a r e
i n t e r n a l l y w i t h i n t h e s e r v e r .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
onAfterSetupMiddleware : function ( devServer ) {
if ( ! devServer) {
throw new Error ( 'webpack-dev-server is not defined' ) ;
}
devServer. app. get ( '/some/path' , function ( req, res ) {
res. json ( { custom: 'response' } ) ;
} ) ;
} ,
} ,
} ;
d e v S e r v e r . o n B e f o r e S e t u p M i d d l e w a r e
f u n c t i o n ( d e v S e r v e r )
P r o v i d e s t h e a b i l i t y t o e x e c u t e c u s t o m m i d d l e w a r e p r i o r t o a l l o t h e r m i d d l e w a r e
i n t e r n a l l y w i t h i n t h e s e r v e r . T h i s c o u l d b e u s e d t o d e f i n e c u s t o m h a n d l e r s , f o r
e x a m p l e :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
onBeforeSetupMiddleware : function ( devServer ) {
if ( ! devServer) {
throw new Error ( 'webpack-dev-server is not defined' ) ;
}
devServer. app. get ( '/some/path' , function ( req, res ) {
res. json ( { custom: 'response' } ) ;
} ) ;
} ,
} ,
} ;
d e v s e r v e r . o n L i s t e n i n g
f u n c t i o n ( d e v S e r v e r )
P r o v i d e s t h e a b i l i t y t o e x e c u t e a c u s t o m f u n c t i o n w h e n w e b p a c k - d e v - s e r v e r s t a r t s l i s t e n i n g f o r c o n n e c t i o n s o n a p o r t .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
onListening : function ( devServer ) {
if ( ! devServer) {
throw new Error ( 'webpack-dev-server is not defined' ) ;
}
const port = devServer. server. address ( ) . port;
console. log ( 'Listening on port:' , port) ;
} ,
} ,
} ;
d e v S e r v e r . o p e n
b o o l e a n s t r i n g [ s t r i n g ] o b j e c t [ o b j e c t ]
T e l l s d e v - s e r v e r t o o p e n t h e b r o w s e r a f t e r s e r v e r h a d b e e n s t a r t e d . S e t i t t o t r u e t o o p e n y o u r d e f a u l t b r o w s e r .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
open: true ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --open
T o d i s a b l e :
npx webpack serve --no-open
T o o p e n a s p e c i f i e d p a g e i n b r o w s e r :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
open: [ '/my-page' ] ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --open /my-page
T o o p e n m u l t i p l e s p e c i f i e d p a g e s i n b r o w s e r :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
open: [ '/my-page' , '/another-page' ] ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --open /my-page --open /another-page
P r o v i d e b r o w s e r n a m e t o u s e i n s t e a d o f t h e d e f a u l t o n e :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
open: {
app: {
name: 'google-chrome' ,
} ,
} ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --open-app-name 'google-chrome'
T h e o b j e c t a c c e p t s a l l o p e n o p t i o n s :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
open: {
target: [ 'first.html' , 'http://localhost:8080/second.html' ] ,
app: {
name: 'google-chrome' ,
arguments: [ '--incognito' , '--new-window' ] ,
} ,
} ,
} ,
} ;
t i p
T h e b r o w s e r a p p l i c a t i o n n a m e i s p l a t f o r m d e p e n d e n t . D o n ' t h a r d c o d e i t i n r e u s a b l e m o d u l e s . F o r e x a m p l e , ' C h r o m e ' is ' G o o g l e C h r o m e ' o n m a c O S , ' g o o g l e - c h r o m e ' o n L i n u x a n d ' c h r o m e ' o n W i n d o w s .
d e v S e r v e r . p o r t
' a u t o ' s t r i n g n u m b e r
S p e c i f y a p o r t n u m b e r t o l i s t e n f o r r e q u e s t s o n :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
port: 8080 ,
} ,
} ;
U s a g e v i a t h e C L I :
npx webpack serve --port 8080
p o r t o p t i o n c a n ' t b e n u l l o r e m p t y s t r i n g , t o a u t o m a t i c a l l y u s e a f r e e p o r t p l e a s e u s e p o r t : ' a u t o ' :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
port: 'auto' ,
} ,
} ;
d e v S e r v e r . p r o x y
o b j e c t [ o b j e c t , f u n c t i o n ]
P r o x y i n g s o m e U R L s c a n b e u s e f u l w h e n y o u h a v e a s e p a r a t e A P I b a c k e n d d e v e l o p m e n t s e r v e r a n d y o u w a n t t o s e n d A P I r e q u e s t s o n t h e s a m e d o m a i n .
T h e d e v - s e r v e r m a k e s u s e o f t h e p o w e r f u l h t t p - p r o x y - m i d d l e w a r e p a c k a g e . C h e c k o u t i t s d o c u m e n t a t i o n f o r m o r e a d v a n c e d u s a g e s . N o t e t h a t s o m e o f h t t p - p r o x y - m i d d l e w a r e ' s f e a t u r e s d o n o t r e q u i r e a t a r g e t k e y , e . g . i t s r o u t e r f e a t u r e , b u t y o u w i l l s t i l l n e e d t o i n c l u d e a t a r g e t k e y i n y o u r c o n f i g u r a t i o n h e r e , o t h e r w i s e w e b p a c k - d e v - s e r v e r w o n ' t p a s s i t a l o n g t o h t t p - p r o x y - m i d d l e w a r e ) .
W i t h a b a c k e n d o n l o c a l h o s t : 3 0 0 0 , y o u c a n u s e t h i s t o e n a b l e p r o x y i n g :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
proxy: {
'/api' : 'http://localhost:3000' ,
} ,
} ,
} ;
A r e q u e s t t o / a p i / u s e r s w i l l n o w p r o x y t h e r e q u e s t t o h t t p : / / l o c a l h o s t : 3 0 0 0 / a p i / u s e r s .
I f y o u d o n ' t w a n t / a p i t o b e p a s s e d a l o n g , w e n e e d t o r e w r i t e t h e p a t h :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
proxy: {
'/api' : {
target: 'http://localhost:3000' ,
pathRewrite: { '^/api' : '' } ,
} ,
} ,
} ,
} ;
A b a c k e n d s e r v e r r u n n i n g o n H T T P S w i t h a n i n v a l i d c e r t i f i c a t e w i l l n o t b e a c c e p t e d b y d e f a u l t . I f y o u w a n t t o , m o d i f y y o u r c o n f i g u r a t i o n l i k e t h i s :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
proxy: {
'/api' : {
target: 'https://other-server.example.com' ,
secure: false ,
} ,
} ,
} ,
} ;
S o m e t i m e s y o u d o n ' t w a n t t o p r o x y e v e r y t h i n g . I t i s p o s s i b l e t o b y p a s s t h e p r o x y b a s e d o n t h e r e t u r n v a l u e o f a f u n c t i o n .
I n t h e f u n c t i o n y o u g e t a c c e s s t o t h e r e q u e s t , r e s p o n s e , a n d p r o x y o p t i o n s .
● R e t u r n n u l l or u n d e f i n e d t o c o n t i n u e p r o c e s s i n g t h e r e q u e s t w i t h p r o x y .
● R e t u r n f a l s e t o p r o d u c e a 4 0 4 e r r o r f o r t h e r e q u e s t .
● R e t u r n a p a t h t o s e r v e f r o m , i n s t e a d o f c o n t i n u i n g t o p r o x y t h e r e q u e s t .
E . g . f o r a b r o w s e r r e q u e s t , y o u w a n t t o s e r v e a n H T M L p a g e , b u t f o r a n A P I r e q u e s t y o u w a n t t o p r o x y i t . Y o u c o u l d d o s o m e t h i n g l i k e t h i s :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
proxy: {
'/api' : {
target: 'http://localhost:3000' ,
bypass : function ( req, res, proxyOptions ) {
if ( req. headers. accept. indexOf ( 'html' ) !== - 1 ) {
console. log ( 'Skipping proxy for browser request.' ) ;
return '/index.html' ;
}
} ,
} ,
} ,
} ,
} ;
I f y o u w a n t t o p r o x y m u l t i p l e , s p e c i f i c p a t h s t o t h e s a m e t a r g e t , y o u c a n u s e a n a r r a y o f o n e o r m o r e o b j e c t s w i t h a c o n t e x t p r o p e r t y :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
proxy: [
{
context: [ '/auth' , '/api' ] ,
target: 'http://localhost:3000' ,
} ,
] ,
} ,
} ;
N o t e t h a t r e q u e s t s t o r o o t w o n ' t b e p r o x i e d b y d e f a u l t . T o e n a b l e r o o t p r o x y i n g , t h e d e v S e r v e r . i n d e x o p t i o n s h o u l d b e s p e c i f i e d a s a f a l s y v a l u e :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
index: '' ,
host: '...' ,
static : '...' ,
proxy: {
context : ( ) => true ,
target: 'http://localhost:1234' ,
} ,
} ,
} ;
T h e o r i g i n o f t h e h o s t h e a d e r i s k e p t w h e n p r o x y i n g b y d e f a u l t , y o u c a n s e t c h a n g e O r i g i n to t r u e t o o v e r r i d e t h i s b e h a v i o u r . I t i s u s e f u l i n s o m e c a s e s l i k e u s i n g n a m e - b a s e d v i r t u a l h o s t e d s i t e s .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
proxy: {
'/api' : {
target: 'http://localhost:3000' ,
changeOrigin: true ,
} ,
} ,
} ,
} ;
d e v S e r v e r . s e t u p E x i t S i g n a l s
b o o l e a n = t r u e
A l l o w s t o c l o s e d e v s e r v e r a n d e x i t t h e p r o c e s s o n S I G I N T a n d S I G T E R M s i g n a l s .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
setupExitSignals: true ,
} ,
} ;
d e v S e r v e r . s t a t i c
b o o l e a n s t r i n g [ s t r i n g ] o b j e c t [ o b j e c t ]
T h i s o p t i o n s a l l o w s t o c o n f i g u r e o p t i o n s f o r s e r v i n g s t a t i c f i l e s f r o m d i r e c t o r y ( b y d e f a u l t ' p u b l i c ' d i r e c t o r y ) . T o d i s a b l e s e t i t t o f a l s e :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
static : false ,
} ,
} ;
U s a g e v i a C L I :
npx webpack serve --static
T o d i s a b l e :
npx webpack serve --no-static
d i r e c t o r y
s t r i n g = p a t h . j o i n ( p r o c e s s . c w d ( ) , ' p u b l i c ' )
T e l l t h e s e r v e r w h e r e t o s e r v e t h e c o n t e n t f r o m . T h i s i s o n l y n e c e s s a r y i f y o u w a n t t o s e r v e s t a t i c f i l e s . s t a t i c . p u b l i c P a t h w i l l b e u s e d t o d e t e r m i n e w h e r e t h e b u n d l e s s h o u l d b e s e r v e d f r o m , a n d t a k e s p r e c e d e n c e .
w e b p a c k . c o n f i g . j s
const path = require ( 'path' ) ;
module. exports = {
devServer: {
static : {
directory: path. join ( __dirname, 'public' ) ,
} ,
} ,
} ;
t i p
I t i s r e c o m m e n d e d t o u s e a n a b s o l u t e p a t h .
s t a t i c O p t i o n s
I t i s p o s s i b l e t o c o n f i g u r e a d v a n c e d o p t i o n s f o r s e r v i n g s t a t i c f i l e s f r o m s t a t i c . d i r e c t o r y . S e e t h e E x p r e s s d o c u m e n t a t i o n f o r t h e p o s s i b l e o p t i o n s .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
static : {
staticOptions: {
redirect: true ,
} ,
} ,
} ,
} ;
p u b l i c P a t h
s t r i n g = ' / ' [ s t r i n g ]
T e l l t h e s e r v e r a t w h i c h U R L t o s e r v e s t a t i c . d i r e c t o r y c o n t e n t . F o r e x a m p l e t o s e r v e a f i l e a s s e t s / m a n i f e s t . j s o n at / s e r v e - p u b l i c - p a t h - u r l / m a n i f e s t . j s o n , y o u r c o n f i g u r a t i o n s s h o u l d b e a s f o l l o w i n g :
w e b p a c k . c o n f i g . j s
const path = require ( 'path' ) ;
module. exports = {
devServer: {
static : {
directory: path. join ( __dirname, 'assets' ) ,
publicPath: '/serve-public-path-url' ,
} ,
} ,
} ;
P r o v i d e a n a r r a y o f o b j e c t s i n c a s e y o u h a v e m u l t i p l e s t a t i c f o l d e r s :
w e b p a c k . c o n f i g . j s
const path = require ( 'path' ) ;
module. exports = {
devServer: {
static : [
{
directory: path. join ( __dirname, 'assets' ) ,
publicPath: '/serve-public-path-url' ,
} ,
{
directory: path. join ( __dirname, 'css' ) ,
publicPath: '/other-serve-public-path-url' ,
} ,
] ,
} ,
} ;
s e r v e I n d e x
b o o l e a n o b j e c t = { i c o n s : t r u e }
T e l l d e v - s e r v e r t o u s e s e r v e I n d e x m i d d l e w a r e w h e n e n a b l e d .
s e r v e I n d e x m i d d l e w a r e g e n e r a t e s d i r e c t o r y l i s t i n g s o n v i e w i n g d i r e c t o r i e s t h a t d o n ' t h a v e a n i n d e x . h t m l f i l e .
w e b p a c k . c o n f i g . j s
const path = require ( 'path' ) ;
module. exports = {
devServer: {
static : {
directory: path. join ( __dirname, 'public' ) ,
serveIndex: true ,
} ,
} ,
} ;
U s a g e v i a C L I :
npx webpack serve --static-serve-index
T o d i s a b l e :
npx webpack serve --no-static-serve-index
w a t c h
b o o l e a n o b j e c t
T e l l d e v - s e r v e r t o w a t c h t h e f i l e s s e r v e d b y t h e s t a t i c . d i r e c t o r y o p t i o n . I t i s d i s a b l e d b y d e f a u l t . W h e n e n a b l e d , f i l e c h a n g e s w i l l t r i g g e r a f u l l p a g e r e l o a d .
w e b p a c k . c o n f i g . j s
const path = require ( 'path' ) ;
module. exports = {
devServer: {
static : {
directory: path. join ( __dirname, 'public' ) ,
watch: true ,
} ,
} ,
} ;
U s a g e v i a C L I :
npx webpack serve --static-watch
T o d i s a b l e :
npx webpack serve --no-static-watch
I t i s p o s s i b l e t o c o n f i g u r e a d v a n c e d o p t i o n s f o r w a t c h i n g s t a t i c f i l e s f r o m s t a t i c . d i r e c t o r y . S e e t h e c h o k i d a r d o c u m e n t a t i o n f o r t h e p o s s i b l e o p t i o n s .
w e b p a c k . c o n f i g . j s
const path = require ( 'path' ) ;
module. exports = {
devServer: {
static : {
directory: path. join ( __dirname, 'public' ) ,
watch: {
ignored: '*.txt' ,
usePolling: false ,
} ,
} ,
} ,
} ;
d e v S e r v e r . w a t c h F i l e s
s t r i n g [ s t r i n g ] o b j e c t [ o b j e c t ]
T h i s o p t i o n a l l o w s y o u t o c o n f i g u r e l i s t o f g l o b s / d i r e c t o r i e s / f i l e s t o w a t c h f o r f i l e c h a n g e s . F o r e x a m p l e :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
watchFiles: [ 'src/**/*.php' , 'public/**/*' ] ,
} ,
} ;
I t i s p o s s i b l e t o c o n f i g u r e a d v a n c e d o p t i o n s f o r w a t c h i n g f i l e s . S e e t h e c h o k i d a r d o c u m e n t a t i o n f o r t h e p o s s i b l e o p t i o n s .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
watchFiles: {
paths: [ 'src/**/*.php' , 'public/**/*' ] ,
options: {
usePolling: false ,
} ,
} ,
} ,
} ;
d e v S e r v e r . w e b S o c k e t S e r v e r
f a l s e | ' s o c k j s ' | ' w s ' s t r i n g f u n c t i o n o b j e c t
T h i s o p t i o n a l l o w s u s e i t h e r t o c h o o s e t h e c u r r e n t w e b - s o c k e t s e r v e r o r t o p r o v i d e c u s t o m w e b - s o c k e t s e r v e r i m p l e m e n t a t i o n .
T h e c u r r e n t d e f a u l t m o d e i s ' w s ' . T h i s m o d e u s e s ws a s a s e r v e r , a n d n a t i v e W e b S o c k e t s o n t h e c l i e n t .
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
webSocketServer: 'ws' ,
} ,
} ;
T o c r e a t e a c u s t o m s e r v e r i m p l e m e n t a t i o n , c r e a t e a c l a s s t h a t e x t e n d s B a s e S e r v e r .
U s i n g p a t h t o C u s t o m S e r v e r . j s , a c u s t o m W e b S o c k e t s e r v e r i m p l e m e n t a t i o n , a l o n g w i t h t h e c o m p a t i b l e ' w s ' c l i e n t :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
client: {
webSocketTransport: 'ws' ,
} ,
webSocketServer: require. resolve ( './CustomServer' ) ,
} ,
} ;
U s i n g c u s t o m , c o m p a t i b l e W e b S o c k e t c l i e n t a n d s e r v e r i m p l e m e n t a t i o n s :
w e b p a c k . c o n f i g . j s
module. exports = {
devServer: {
client: {
webSocketTransport: require. resolve ( './CustomClient' ) ,
} ,
webSocketServer: require. resolve ( './CustomServer' ) ,
} ,
} ;
E d i t t h i s p a g e · P r i n t t h i s p a g e
« P r e v i o u s
P l u g i n s
N e x t »
C a c h e
C o n t r i b u t o r s
s o k r a s k i p j a c k s p a c e k 3 3 z c h a r l e s p w d o r t e t h 0 1 b y z y k E u g e n e H l u s h k o Y i i d i i r L o o n r i d e d m o h n s E s l a m H i k o d i g i t a l j o h n b h a v y a 9 1 0 7 w i z a r d o f h o g w a r t s j a m e s g e o r g e 0 0 7 g 1 0 0 g a n i k e t h s a h a s n i t i n 3 1 5