forked from mbman/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
141 lines (134 loc) · 4.2 KB
/
webpack.config.ts
File metadata and controls
141 lines (134 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import * as CopyWebpackPlugin from 'copy-webpack-plugin'
import * as HtmlWebpackPlugin from 'html-webpack-plugin'
import { webpack as lernaAliases } from 'lerna-alias'
import * as _ from 'lodash'
import * as webpack from 'webpack'
import { CheckerPlugin as AsyncTypeScriptChecker } from 'awesome-typescript-loader'
import config from './config'
const { paths } = config
const { __DEV__, __PROD__ } = config.compiler_globals
const webpackConfig: any = {
name: 'client',
target: 'web',
mode: __DEV__ ? 'development' : 'production',
entry: {
app: paths.docsSrc('index'),
vendor: config.compiler_vendor,
},
output: {
filename: `[name].[${config.compiler_hash_type}].js`,
path: config.compiler_output_path,
pathinfo: true,
publicPath: config.compiler_public_path,
},
devtool: config.compiler_devtool,
externals: {
'@babel/standalone': 'Babel',
'anchor-js': 'AnchorJS',
'prettier/standalone': 'prettier',
'prop-types': 'PropTypes',
react: 'React',
'react-dom': 'ReactDOM',
'react-dom/server': 'ReactDOMServer',
},
node: {
fs: 'empty',
module: 'empty',
child_process: 'empty',
net: 'empty',
readline: 'empty',
},
module: {
noParse: [/anchor-js/],
rules: [
{
test: /\.(js|ts|tsx)$/,
loader: 'awesome-typescript-loader',
exclude: /node_modules/,
options: {
useCache: true,
configFileName: paths.base('build/tsconfig.docs.json'),
errorsAsWarnings: __DEV__,
},
},
],
},
plugins: [
new AsyncTypeScriptChecker(),
new webpack.DefinePlugin(config.compiler_globals),
new webpack.ContextReplacementPlugin(
/node_modules[\\|/]typescript[\\|/]lib/,
/typescript\.js/,
false,
),
new CopyWebpackPlugin([
{
from: paths.docsSrc('public'),
to: paths.docsDist('public'),
},
]),
new webpack.DllReferencePlugin({
context: paths.base('node_modules'),
manifest: require(paths.base('dll/vendor-manifest.json')),
}),
new HtmlWebpackPlugin({
template: paths.docsSrc('index.ejs'),
filename: 'index.html',
hash: false,
inject: 'body',
minify: {
collapseWhitespace: true,
},
versions: {
babelStandalone: require('@babel/standalone/package.json').version,
lodash: require('lodash/package.json').version,
prettier: require('prettier/package.json').version,
propTypes: require('prop-types/package.json').version,
react: require('react/package.json').version,
reactDOM: require('react-dom/package.json').version,
stardust: require('./package.json').version,
},
}),
],
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
...lernaAliases(),
src: paths.packageSrc('react'),
docs: paths.base('docs'),
},
},
performance: {
hints: false, // to (temporarily) disable "WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit")
},
}
// ------------------------------------
// Environment Configuration
// ------------------------------------
if (__DEV__) {
const webpackHotPath = `${config.compiler_public_path}__webpack_hmr`
const webpackHotMiddlewareEntry = `webpack-hot-middleware/client?${_.map(
{
path: webpackHotPath, // The path which the middleware is serving the event stream on
timeout: 2000, // The time to wait after a disconnection before attempting to reconnect
overlay: true, // Set to false to disable the DOM-based client-side overlay.
reload: true, // Set to true to auto-reload the page when webpack gets stuck.
noInfo: false, // Set to true to disable informational console logging.
quiet: false, // Set to true to disable all console logging.
},
(val, key) => `&${key}=${val}`,
).join('')}`
webpackConfig.entry.app = [webpackHotMiddlewareEntry].concat(webpackConfig.entry.app)
webpackConfig.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
)
}
if (__PROD__) {
webpackConfig.plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true,
}),
)
}
export default webpackConfig