1 | 'use strict'
|
2 |
|
3 | const path = require('path')
|
4 | const webpack = require('webpack')
|
5 | const merge = require('webpack-merge')
|
6 | const HtmlWebpackPlugin = require('sina-html-webpack-plugin')
|
7 | const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin')
|
8 | const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin')
|
9 | const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
|
10 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
|
11 | const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware')
|
12 | const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware')
|
13 | const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin')
|
14 | const ignoredFiles = require('react-dev-utils/ignoredFiles')
|
15 | const { localIp, getChunks, rootPath } = require('../libs/utils')
|
16 | const config = require('../config')
|
17 |
|
18 | function parseChunks(entry) {
|
19 | const chunkObj = getChunks(`src/view/${entry}/index.*.js`)
|
20 | const chunks = [].concat(...Object.values(chunkObj))
|
21 |
|
22 | return { [entry]: chunks }
|
23 | }
|
24 |
|
25 | module.exports = function({ entry }) {
|
26 | const baseWebpackConfig = require('./webpack.base.conf')(entry, 'dev')
|
27 | const pagePublicDir = rootPath(`${config.paths.page}/${entry}/public`)
|
28 | const chunksEntry = parseChunks(entry)
|
29 | const { transformer, formatter } = require('../libs/resolveLoaderError')
|
30 |
|
31 |
|
32 |
|
33 | const webpackConfig = merge(baseWebpackConfig, {
|
34 | devtool: 'cheap-module-source-map',
|
35 | entry: chunksEntry,
|
36 | output: {
|
37 | publicPath: config.dev.assetsPublicPath,
|
38 |
|
39 | devtoolModuleFilenameTemplate: info =>
|
40 | path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
|
41 |
|
42 | pathinfo: true
|
43 | },
|
44 | devServer: {
|
45 |
|
46 | disableHostCheck: true,
|
47 | headers: { 'Access-Control-Allow-Origin': '*' },
|
48 |
|
49 | compress: true,
|
50 |
|
51 |
|
52 | clientLogLevel: 'none',
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | contentBase: [
|
58 | config.paths.public,
|
59 | pagePublicDir
|
60 |
|
61 |
|
62 | ],
|
63 |
|
64 | watchContentBase: true,
|
65 |
|
66 |
|
67 |
|
68 | hot: true,
|
69 |
|
70 | publicPath: config.dev.assetsPublicPath,
|
71 |
|
72 | quiet: true,
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | watchOptions: {
|
78 | ignored: ignoredFiles(config.paths.src)
|
79 | },
|
80 | host: localIp(),
|
81 | overlay: false,
|
82 | historyApiFallback: {
|
83 |
|
84 |
|
85 | disableDotRule: true
|
86 | },
|
87 |
|
88 |
|
89 | before(app) {
|
90 |
|
91 | app.use(errorOverlayMiddleware())
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | app.use(noopServiceWorkerMiddleware())
|
98 | }
|
99 | },
|
100 | plugins: [
|
101 | new webpack.DefinePlugin(config.dev.env.stringified),
|
102 |
|
103 |
|
104 |
|
105 | new InterpolateHtmlPlugin(config.dev.env.raw),
|
106 | new webpack.NamedModulesPlugin(),
|
107 | new DuplicatePackageCheckerPlugin({
|
108 |
|
109 | verbose: true,
|
110 | showHelp: false,
|
111 |
|
112 | emitError: false,
|
113 |
|
114 | strict: true
|
115 | }),
|
116 |
|
117 | new webpack.HotModuleReplacementPlugin(),
|
118 |
|
119 | new webpack.NoEmitOnErrorsPlugin(),
|
120 |
|
121 | new WatchMissingNodeModulesPlugin(config.paths.nodeModules),
|
122 |
|
123 |
|
124 | new FriendlyErrorsPlugin({
|
125 | additionalTransformers: [transformer],
|
126 | additionalFormatters: [formatter]
|
127 | }),
|
128 | new CaseSensitivePathsPlugin(),
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
135 | new HtmlWebpackPlugin({
|
136 |
|
137 | filename: `${entry}.html`,
|
138 |
|
139 | template: `${config.paths.page}/${entry}/index.html`,
|
140 | inject: true,
|
141 |
|
142 | chunks: [entry]
|
143 | })
|
144 | ],
|
145 |
|
146 |
|
147 |
|
148 | performance: {
|
149 | hints: false
|
150 | }
|
151 | })
|
152 |
|
153 | return webpackConfig
|
154 | }
|