@@ -11,85 +11,97 @@ module.exports = config => {
11
11
return new Promise ( resolve => {
12
12
const bs = require ( 'browser-sync' ) . create ( ) ;
13
13
const compiler = webpack ( config . webpack ) ;
14
- const middlewarecross = function ( req , res , next ) {
15
- res . setHeader ( "Access-Control-Allow-Origin" , "*" ) ;
16
- res . setHeader ( 'Access-Control-Allow-Credentials' , true ) ;
17
- res . setHeader ( "Access-Control-Allow-Headers" , "Origin, X-Requested-With, Content-Type, Accept" ) ;
18
- next ( ) ;
19
- }
14
+ const middlewarecross = function ( req , res , next ) {
15
+ res . setHeader ( "Access-Control-Allow-Origin" , "*" ) ;
16
+ res . setHeader ( 'Access-Control-Allow-Credentials' , true ) ;
17
+ res . setHeader ( "Access-Control-Allow-Headers" , "Origin, X-Requested-With, Content-Type, Accept" ) ;
18
+ next ( ) ;
19
+ }
20
20
21
- if ( ! process . env . template ) {
22
- const webpackMiddl = webpackDevMiddleware ( compiler , {
23
- publicPath : config . webpack . output . publicPath ,
24
- stats : config . webpack . stats ,
25
- } ) ;
26
- compiler . plugin ( 'done' , stats => {
27
- // Generate index.html page
28
- const bundle = stats . compilation . chunks . find ( x => x . name === 'main' ) . files [ 0 ] ;
29
- const template = fs . readFileSync ( './index.ejs' , 'utf8' ) ;
30
- const render = ejs . compile ( template , { filename : './index.ejs' } ) ;
31
- const output = render ( { debug : true , bundle : `/dist/${ bundle } ` , config : config . webpack } ) ;
32
- fs . writeFileSync ( './public/index.html' , output , 'utf8' ) ;
21
+ if ( ! process . env . template ) {
22
+ const webpackMiddl = webpackDevMiddleware ( compiler , {
23
+ publicPath : config . webpack . output . publicPath ,
24
+ stats : config . webpack . stats ,
25
+ } ) ;
26
+ compiler . plugin ( 'done' , stats => {
27
+ // Generate index.html page
28
+ const bundle = stats . compilation . chunks . find ( x => x . name === 'main' ) . files [ 0 ] ;
29
+ const template = fs . readFileSync ( './index.ejs' , 'utf8' ) ;
30
+ const render = ejs . compile ( template , {
31
+ filename : './index.ejs'
32
+ } ) ;
33
+ const output = render ( {
34
+ debug : process . env . NODE_ENV === 'development' ,
35
+ bundle : `/dist/${ bundle } ` ,
36
+ config : config . webpack
37
+ } ) ;
38
+ fs . writeFileSync ( './public/index.html' , output , 'utf8' ) ;
33
39
34
- // Launch Browsersync after the initial bundling is complete
35
- // For more information visit https://browsersync.io/docs/options
36
- if ( ++ count === 1 ) {
37
- bs . init ( {
38
- // host: "fr.skiscool.com",
39
- // port: process.env.PORT || 3000,
40
- // ui: { port: Number(process.env.PORT || 3000) + 1 },
41
- // server: {
42
- // baseDir: 'public',
43
- proxy : {
44
- target : 'localhost:3000' ,
45
- ws : true ,
46
- middleware : [
47
- webpackMiddl ,
48
- require ( 'webpack-hot-middleware' ) ( compiler ) ,
49
- require ( 'connect-history-api-fallback' ) ( ) ,
50
- ] ,
51
- } ,
52
- } , resolve ) ;
53
- }
54
- } ) ;
55
- } else {
56
- // Node.js middleware that compiles application in watch mode with HMR support
57
- // http://webpack.github.io/docs/webpack-dev-middleware.html
58
- const publicPath = config . webpack [ 0 ] . output . publicPath
59
- const webpackMiddl = webpackMiddleware ( compiler , {
60
- publicPath : publicPath ,
61
- stats : config . webpack [ 0 ] . stats ,
62
- } ) ;
63
- compiler . plugin ( 'done' , stats => {
64
- const bundle = stats . stats [ 0 ] . compilation . chunks . find ( x => x . name === 'main' ) . files [ 0 ] ;
65
- const bundleserver = stats . stats [ 1 ] . compilation . chunks . find ( x => x . name === 'main' ) . files [ 0 ] ;
66
- console . log ( bundle )
40
+ // Launch Browsersync after the initial bundling is complete
41
+ // For more information visit https://browsersync.io/docs/options
42
+ if ( ++ count === 1 ) {
43
+ bs . init ( {
44
+ // host: "fr.skiscool.com",
45
+ // port: process.env.PORT || 3000,
46
+ // ui: { port: Number(process.env.PORT || 3000) + 1 },
47
+ // server: {
48
+ // baseDir: 'public',
49
+ proxy : {
50
+ target : 'localhost:3000' ,
51
+ ws : true ,
52
+ middleware : [
53
+ webpackMiddl ,
54
+ require ( 'webpack-hot-middleware' ) ( compiler ) ,
55
+ require ( 'connect-history-api-fallback' ) ( ) ,
56
+ ] ,
57
+ } ,
58
+ snippetOptions : {
59
+ ignorePaths : [ 'tiles/**' ] ,
60
+ }
61
+ } , resolve ) ;
62
+ }
63
+ } ) ;
64
+ } else {
65
+ // Node.js middleware that compiles application in watch mode with HMR support
66
+ // http://webpack.github.io/docs/webpack-dev-middleware.html
67
+ const publicPath = config . webpack [ 0 ] . output . publicPath
68
+ const webpackMiddl = webpackMiddleware ( compiler , {
69
+ publicPath : publicPath ,
70
+ stats : config . webpack [ 0 ] . stats ,
71
+ } ) ;
72
+ compiler . plugin ( 'done' , stats => {
73
+ const bundle = stats . stats [ 0 ] . compilation . chunks . find ( x => x . name === 'main' ) . files [ 0 ] ;
74
+ const bundleserver = stats . stats [ 1 ] . compilation . chunks . find ( x => x . name === 'main' ) . files [ 0 ] ;
75
+ console . log ( bundle )
67
76
68
- // Launch Browsersync after the initial bundling is complete
69
- // For more information visit https://browsersync.io/docs/options
70
- if ( ++ count === 1 ) {
71
- const startbs = ( err ) => {
72
- if ( ! err ) {
73
- bs . init ( {
74
- proxy : {
75
- target : 'localhost:3000' ,
76
- // baseDir: 'public',
77
- middleware : [
78
- middlewarecross ,
79
- webpackMiddl ,
80
- require ( 'webpack-hot-middleware' ) ( compiler ) ,
81
- //require('connect-history-api-fallback')(),
82
- ] ,
83
- } ,
84
- files : [ 'public/dist/*.*' ]
85
- } , resolve ) ;
86
- //todo browser-sync
87
- }
88
- } ;
89
- runServer ( startbs ) ;
90
- }
77
+ // Launch Browsersync after the initial bundling is complete
78
+ // For more information visit https://browsersync.io/docs/options
79
+ if ( ++ count === 1 ) {
80
+ const startbs = ( err ) => {
81
+ if ( ! err ) {
82
+ bs . init ( {
83
+ proxy : {
84
+ target : 'localhost:3000' ,
85
+ // baseDir: 'public',
86
+ middleware : [
87
+ middlewarecross ,
88
+ webpackMiddl ,
89
+ require ( 'webpack-hot-middleware' ) ( compiler ) ,
90
+ //require('connect-history-api-fallback')(),
91
+ ] ,
92
+ } ,
93
+ snippetOptions : {
94
+ ignorePaths : [ 'tiles/**' ] ,
95
+ } ,
96
+ files : [ 'public/dist/*.*' ]
97
+ } , resolve ) ;
98
+ //todo browser-sync
99
+ }
100
+ } ;
101
+ runServer ( startbs ) ;
102
+ }
91
103
92
- } ) ;
104
+ } ) ;
93
105
94
106
}
95
107
} ) ;
0 commit comments