@@ -3,19 +3,23 @@ var path = require('path');
3
3
var http = require ( 'http' ) ;
4
4
var ecstatic = require ( 'ecstatic' ) ;
5
5
var open = require ( 'open' ) ;
6
- var browserify = require ( 'browserify ' ) ;
6
+ var webpack = require ( 'webpack ' ) ;
7
7
var minimist = require ( 'minimist' ) ;
8
8
9
9
var constants = require ( '../../tasks/util/constants' ) ;
10
- var makeWatchifiedBundle = require ( '../../tasks/util/watchified_bundle' ) ;
11
- var shortcutPaths = require ( '../../tasks/util/shortcut_paths' ) ;
10
+ var config = require ( '../../webpack.config.js' ) ;
11
+ config . optimization = { minimize : false } ;
12
+ // If interested in development mode
13
+ // config.mode = 'development';
12
14
13
15
var args = minimist ( process . argv . slice ( 2 ) , { } ) ;
14
16
var PORT = args . port || 3000 ;
15
17
var strict = args . strict ;
16
18
var mathjax3 = args . mathjax3 ;
17
19
var mathjax3chtml = args . mathjax3chtml ;
18
20
21
+ if ( strict ) config . entry = './lib/index-strict.js' ;
22
+
19
23
// Create server
20
24
var server = http . createServer ( ecstatic ( {
21
25
root : constants . pathToRoot ,
@@ -24,33 +28,70 @@ var server = http.createServer(ecstatic({
24
28
cors : true
25
29
} ) ) ;
26
30
27
- // Make watchified bundle for plotly.js
28
- var bundlePlotly = makeWatchifiedBundle ( strict , function ( ) {
29
- // open up browser window on first bundle callback
30
- open ( 'http://localhost:' + PORT + '/devtools/test_dashboard/index' + (
31
- strict ? '-strict' :
32
- mathjax3 ? '-mathjax3' :
33
- mathjax3chtml ? '-mathjax3chtml' : ''
34
- ) + '.html' ) ;
35
- } ) ;
36
-
37
- // Bundle devtools code
38
- var devtoolsPath = path . join ( constants . pathToRoot , 'devtools/test_dashboard' ) ;
39
- var devtools = browserify ( path . join ( devtoolsPath , 'devtools.js' ) , {
40
- transform : [ shortcutPaths ]
41
- } ) ;
42
-
43
31
// Start the server up!
44
32
server . listen ( PORT ) ;
45
33
46
- // Build and bundle all the things!
34
+ // open up browser window on first bundle callback
35
+ open ( 'http://localhost:' + PORT + '/devtools/test_dashboard/index' + (
36
+ strict ? '-strict' :
37
+ mathjax3 ? '-mathjax3' :
38
+ mathjax3chtml ? '-mathjax3chtml' : ''
39
+ ) + '.html' ) ;
40
+
41
+ // mock list
47
42
getMockFiles ( )
48
43
. then ( readFiles )
49
44
. then ( createMocksList )
50
- . then ( saveToFile )
51
- . then ( bundleDevtools )
52
- . then ( bundlePlotly ) ;
45
+ . then ( saveToFile ) ;
53
46
47
+ // Devtools config
48
+ var devtoolsConfig = { } ;
49
+
50
+ var devtoolsPath = path . join ( constants . pathToRoot , 'devtools/test_dashboard' ) ;
51
+ devtoolsConfig . entry = path . join ( devtoolsPath , 'devtools.js' ) ;
52
+
53
+ devtoolsConfig . output = {
54
+ path : config . output . path ,
55
+ filename : 'test_dashboard-bundle.js' ,
56
+ library : {
57
+ name : 'Tabs' ,
58
+ type : 'umd' ,
59
+ umdNamedDefine : true
60
+ }
61
+ } ;
62
+
63
+ devtoolsConfig . target = config . target ;
64
+ devtoolsConfig . plugins = config . plugins ;
65
+ devtoolsConfig . optimization = config . optimization ;
66
+ devtoolsConfig . mode = config . mode ;
67
+
68
+ var compiler ;
69
+
70
+ compiler = webpack ( devtoolsConfig ) ;
71
+ compiler . run ( function ( devtoolsErr , devtoolsStats ) {
72
+ if ( devtoolsErr ) {
73
+ console . log ( 'err:' , devtoolsErr ) ;
74
+ } else if ( devtoolsStats . hasErrors ( ) ) {
75
+ console . log ( 'stats.errors:' , devtoolsStats . errors ) ;
76
+ } else {
77
+ console . log ( 'success:' , devtoolsConfig . output . path + '/' + devtoolsConfig . output . filename ) ;
78
+ }
79
+
80
+ compiler . close ( function ( closeErr ) {
81
+ if ( ! closeErr ) {
82
+ compiler = webpack ( config ) ;
83
+ compiler . watch ( { } , function ( err , stats ) {
84
+ if ( err ) {
85
+ console . log ( 'err:' , err ) ;
86
+ } else if ( stats . hasErrors ( ) ) {
87
+ console . log ( 'stats.errors:' , stats . errors ) ;
88
+ } else {
89
+ console . log ( 'success:' , config . output . path + '/' + config . output . filename ) ;
90
+ }
91
+ } ) ;
92
+ }
93
+ } ) ;
94
+ } ) ;
54
95
55
96
function getMockFiles ( ) {
56
97
return new Promise ( function ( resolve , reject ) {
@@ -137,16 +178,3 @@ function writeFilePromise(path, contents) {
137
178
} ) ;
138
179
} ) ;
139
180
}
140
-
141
- function bundleDevtools ( ) {
142
- return new Promise ( function ( resolve , reject ) {
143
- devtools . bundle ( function ( err ) {
144
- if ( err ) {
145
- console . error ( 'Error while bundling!' , JSON . stringify ( String ( err ) ) ) ;
146
- return reject ( err ) ;
147
- } else {
148
- return resolve ( ) ;
149
- }
150
- } ) . pipe ( fs . createWriteStream ( constants . pathToTestDashboardBundle ) ) ;
151
- } ) ;
152
- }
0 commit comments