forked from Semantic-Org/Semantic-UI-React
-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.webpack.js
103 lines (100 loc) · 2.93 KB
/
static.webpack.js
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
import path from 'path'
import uglifyPlugin from 'react-static/node_modules/uglifyjs-webpack-plugin'
import webpack from 'react-static/node_modules/webpack'
import TerserLegacyPlugin from 'terser-webpack-plugin-legacy'
import config from './config'
export default (webpackConfig, { stage }) => ({
...webpackConfig,
devtool: config.compiler_devtool,
entry:
stage === 'prod'
? {
main: [config.paths.docsSrc('index.js'), config.paths.src('index.js')],
}
: webpackConfig.entry,
externals:
stage === 'node'
? webpackConfig.externals
: {
'anchor-js': 'AnchorJS',
'@babel/standalone': 'Babel',
faker: 'faker',
'prop-types': 'PropTypes',
react: 'React',
'react-dom': 'ReactDOM',
'react-dom/server': 'ReactDOMServer',
},
module: {
...webpackConfig.module,
rules: [
{
test: /\.js$/,
include: [
// Heads up!
// There modules should be manually transpiled because they are not compatible with IE11
path.resolve(__dirname, 'node_modules/ansi-styles'),
path.resolve(__dirname, 'node_modules/chalk'),
path.resolve(__dirname, 'node_modules/debug'),
path.resolve(__dirname, 'node_modules/leven'),
path.resolve(__dirname, 'node_modules/prettier'),
path.resolve(__dirname, 'docs'),
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'tmp'),
],
use: {
loader: 'babel-loader',
options: {
cacheDirectory: stage === 'dev',
configFile: path.resolve(__dirname, '.babelrc'),
},
},
},
{
test: /.mdx?$/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
'@mdx-js/loader',
],
},
],
},
plugins: [
new webpack.DefinePlugin({
__PATH_SEP__: JSON.stringify(path.sep),
}),
// Disable outdated "uglifyjs-webpack-plugin", can be removed after migration to RS7
...webpackConfig.plugins.filter((plugin) => plugin.constructor !== uglifyPlugin),
stage === 'prod' &&
new TerserLegacyPlugin({
sourceMap: true,
terserOptions: {
output: {
comments: false,
},
},
}),
].filter(Boolean),
resolve: {
alias: {
'semantic-ui-react': config.paths.src('index.js'),
},
// Heads up!
// We need this to prefer own node_modules instead of react-static's.
modules: [
config.paths.base(),
config.paths.base('node_modules'),
...webpackConfig.resolve.modules,
],
},
resolveLoader: {
// Heads up!
// We need this to resolve our own babel-loader for Babel 7. Can be safely removed when
// react-static will use Babel 7.
modules: [config.paths.base('node_modules'), 'node_modules'],
},
})