1 | 'use strict'
|
2 |
|
3 | const fs = require('fs')
|
4 | const path = require('path')
|
5 | const webpack = require('webpack')
|
6 | const merge = require('webpack-merge')
|
7 | const HtmlWebpackPlugin = require('html-webpack-plugin')
|
8 | const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin')
|
9 | const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
|
10 | const perfInstallModulePlugin = require('../lib/perfInstallModulePlugin')
|
11 | const BuildProgressPlugin = require('../lib/BuildProgressPlugin')
|
12 | const InlineUmdHtmlPlugin = require('../lib/InlineUmdHtmlPlugin')
|
13 | const { getEntryPoints } = require('../lib/utils')
|
14 | const config = require('../config')
|
15 | const { GLOB, VIEWS_DIR } = require('../config/const')
|
16 |
|
17 | module.exports = function(context, spinner) {
|
18 | const entry = context.entry
|
19 | const baseWebpackConfig = require('./webpack.base.conf')(context, 'dev')
|
20 | const servantEntry = getEntryPoints(
|
21 | `${VIEWS_DIR}/${entry}/${GLOB.SERVANT_ENTRY}`
|
22 | )
|
23 | const htmlTemplatePath = `${config.paths.views}/${entry}/index.html`
|
24 | const hasHtml = fs.existsSync(htmlTemplatePath)
|
25 |
|
26 |
|
27 |
|
28 | const webpackConfig = merge(baseWebpackConfig, {
|
29 | mode: 'development',
|
30 | devtool: 'cheap-module-source-map',
|
31 | entry: servantEntry,
|
32 | output: {
|
33 |
|
34 | pathinfo: true,
|
35 | publicPath: context.publicPath,
|
36 |
|
37 | devtoolModuleFilenameTemplate: info =>
|
38 | path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')
|
39 | },
|
40 | plugins: [
|
41 |
|
42 |
|
43 | new BuildProgressPlugin({
|
44 | spinner,
|
45 | name: 'Starting',
|
46 | type: config.marax.progress
|
47 | }),
|
48 | hasHtml &&
|
49 | new HtmlWebpackPlugin({
|
50 |
|
51 | filename: `${entry}.html`,
|
52 |
|
53 | template: htmlTemplatePath,
|
54 | inject: true
|
55 | }),
|
56 | hasHtml && new InlineUmdHtmlPlugin(HtmlWebpackPlugin),
|
57 |
|
58 |
|
59 |
|
60 | hasHtml &&
|
61 | new InterpolateHtmlPlugin(HtmlWebpackPlugin, context.buildEnv.raw),
|
62 |
|
63 | new webpack.HotModuleReplacementPlugin(),
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | new CaseSensitivePathsPlugin()
|
70 | ].filter(Boolean)
|
71 | })
|
72 |
|
73 | return webpackConfig
|
74 | }
|