1 | const webpack = require('webpack')
|
2 | const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
3 |
|
4 | const { cssLoader, injectWHM } = require('./common')
|
5 |
|
6 | const { clientConfig, serverConfig, } = require('./webpack.config.test')
|
7 | const clientConfigNode = require('lodash/cloneDeep')(clientConfig)
|
8 |
|
9 | const commonPlugins = [
|
10 | new webpack.DefinePlugin({
|
11 | 'process.env.TEST': true,
|
12 | 'process.env.NODE_ENV': '"development"',
|
13 | }),
|
14 | new ExtractTextPlugin({ filename: 'styles.css', allChunks: false }),
|
15 | ]
|
16 |
|
17 |
|
18 |
|
19 | clientConfig.devtool = 'cheap-module-eval-source-map'
|
20 | clientConfig.module.rules.push(...cssLoader)
|
21 | clientConfig.plugins.push(new webpack.HotModuleReplacementPlugin())
|
22 | clientConfig.plugins.push(...commonPlugins)
|
23 |
|
24 | const clientCompiler = webpack(clientConfig)
|
25 | injectWHM(clientConfig, clientCompiler, 9080)
|
26 | clientCompiler.watch({}, (err, stats) => {
|
27 | console.log('Client Bundles in for browser \n', stats.toString({ chunkModules: false, colors: true }), '\n')
|
28 | })
|
29 |
|
30 |
|
31 | clientConfigNode.entry.client = ['./src/client/entry.node.test.js']
|
32 | clientConfigNode.output.filename = './src/client/client.node.js'
|
33 | compileAndTest(clientConfigNode, 'CLIENT')
|
34 |
|
35 |
|
36 | compileAndTest(serverConfig, 'SERVER')
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | function compileAndTest(config, arch) {
|
44 | config.devtool = 'cheap-module-eval-source-map'
|
45 | config.module.rules.push(...cssLoader)
|
46 | config.plugins.push(...commonPlugins)
|
47 |
|
48 | let child
|
49 | webpack(config).watch({}, (err, stats) => {
|
50 | if (stats.hasErrors()) {
|
51 | console.log(arch + '\n', stats.toString({ colors: true }))
|
52 | return
|
53 | }
|
54 | if (child) child.kill()
|
55 | child = require('child_process').fork(require('path').join(config.output.path, config.output.filename))
|
56 | })
|
57 | }
|