This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathwebpack.config.ts
156 lines (149 loc) · 4.38 KB
/
webpack.config.ts
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { CheckerPlugin as AsyncTypeScriptChecker } from 'awesome-typescript-loader'
import * as CopyWebpackPlugin from 'copy-webpack-plugin'
import * as HtmlWebpackPlugin from 'html-webpack-plugin'
import * as _ from 'lodash'
import * as webpack from 'webpack'
import config from './config'
const { paths } = config
const { __DEV__, __PROD__ } = config.compiler_globals
const webpackConfig: any = {
name: 'client',
target: 'web',
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: {
'anchor-js': 'AnchorJS',
'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: [/\.json$/, /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__,
},
},
{
test: /\.md$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-react'],
plugins: ['@babel/plugin-proposal-object-rest-spread'],
},
},
'@mdx-js/loader',
],
},
],
},
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: {
jsBeautify: require('js-beautify/package.json').version,
lodash: require('lodash/package.json').version,
propTypes: require('prop-types/package.json').version,
react: require('react/package.json').version,
reactDOM: require('react-dom/package.json').version,
sui: require('semantic-ui-css/package.json').version,
suir: require('./package.json').version,
},
}),
],
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
'@stardust-ui/react': paths.src(),
src: paths.src(),
docs: paths.base('docs'),
'package.json': paths.base('package.json'),
},
},
}
// ------------------------------------
// 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,
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
unused: true,
dead_code: true,
warnings: false,
},
}),
)
}
export default webpackConfig