-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathwebpack.base.config.js
More file actions
156 lines (153 loc) · 5.44 KB
/
webpack.base.config.js
File metadata and controls
156 lines (153 loc) · 5.44 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = (_env, argv) => {
const {
mode,
googleAnalyticsID = false,
algolia = {},
hasGdprBanner = false,
hasFooter = false,
hasVersionSwitcher = false,
hasDesignGuidelines = false,
hasDarkThemeSwitcher = false,
hasRTLSwitcher = false,
hasSpookySwitcher = false,
componentsData = {},
sideNavItems = [],
topNavItems = [],
includePaths = []
} = argv;
const isProd = mode === 'production';
return {
entry: path.resolve(__dirname, '../../app.js'),
output: {
publicPath: '/',
pathinfo: false, // https://webpack.js.org/guides/build-performance/#output-without-path-info,
hashDigestLength: 8,
clean: true, // Clean the output directory before emit.
},
amd: false, // We don't use any AMD modules, helps performance
mode: isProd ? 'production' : 'development',
devtool: isProd ? false : 'cheap-module-source-map',
module: {
rules: [
{
test: /\.[tj]sx?$/,
include: [
path.resolve(process.cwd(), 'src'),
path.resolve(process.cwd(), 'patternfly-docs'),
path.resolve(process.cwd(), 'examples'),
path.resolve(__dirname, '../..'), // Temporarily compile theme using webpack for development
/react-[\w-]+\/src\/.*\/examples/,
/react-[\w-]+\\src\\.*\\examples/, // fix for Windows
/react-[\w-]+\/patternfly-docs\/.*\/examples/, //fixes for extensions
/react-[\w-]+\\patternfly-docs\\.*\\examples/,
path.resolve(__dirname, '../../../../node_modules/@patternfly/design-tokens/patternfly-docs/content')
].concat(includePaths.map(path => new RegExp(path))),
exclude: [
path.resolve(__dirname, '../../node_modules'), // Temporarily compile theme using webpack for development
],
use: {
loader: 'babel-loader',
options: {
cacheDirectory: '.cache/babel',
cacheCompression: false,
presets: [
'@babel/preset-react',
['@babel/preset-env', {
loose: true,
targets: '> 1%, not dead'
}],
],
}
},
},
{
test: /\.(png|jpe?g|webp)$/,
use: {
loader: 'responsive-loader',
options: {
adapter: require('responsive-loader/sharp'),
name: '[name].[contenthash].[ext]',
outputPath: 'images/'
},
}
},
{
test: /\.(gif|svg)$/,
type: 'asset/resource',
dependency: { not: ['url'] },
generator: {
filename: 'images/[hash][ext][query]'
}
},
{
test: /\.(pdf)$/,
type: 'asset/resource',
dependency: { not: ['url'] },
generator: {
filename: '[hash][ext][query]'
}
},
{
test: /.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
dependency: { not: ['url'] },
generator: {
filename: 'fonts/[name][ext][query]'
}
},
]
},
resolve: {
// Allow importing client routes
alias: {
'client-styles': path.resolve(process.cwd(), 'patternfly-docs/patternfly-docs.css.js'),
'./routes-client': path.resolve(process.cwd(), 'patternfly-docs/patternfly-docs.routes.js'),
'./routes-generated': path.resolve(process.cwd(), 'patternfly-docs/generated/index.js'),
process: "process/browser"
},
modules: [
'node_modules',
...module.paths,
],
fallback: {
"path": require.resolve("path-browserify")
},
},
// Use this module's node_modules first (for use in Core/React workspaces)
resolveLoader: {
modules: module.paths,
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(mode),
'process.env.googleAnalyticsID': JSON.stringify(isProd ? googleAnalyticsID : ''),
'process.env.algolia': JSON.stringify(algolia),
'process.env.hasGdprBanner': JSON.stringify(hasGdprBanner),
'process.env.hasFooter': JSON.stringify(hasFooter),
'process.env.hasVersionSwitcher': JSON.stringify(hasVersionSwitcher),
'process.env.hasDesignGuidelines': JSON.stringify(hasDesignGuidelines),
'process.env.hasDarkThemeSwitcher': JSON.stringify(hasDarkThemeSwitcher),
'process.env.hasRTLSwitcher': JSON.stringify(hasRTLSwitcher),
'process.env.hasSpookySwitcher': JSON.stringify(hasSpookySwitcher),
'process.env.componentsData': JSON.stringify(componentsData),
'process.env.sideNavItems': JSON.stringify(sideNavItems),
'process.env.topNavItems': JSON.stringify(topNavItems),
'process.env.prnum': JSON.stringify(process.env.CIRCLE_PR_NUMBER || process.env.PR_NUMBER || ''),
'process.env.prurl': JSON.stringify(process.env.CIRCLE_PULL_REQUEST || '')
}),
new CopyWebpackPlugin({
patterns: [
{ from: path.join(__dirname, '../../assets'), to: 'assets' }
]
})
],
stats: 'minimal'
};
}