-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwebpack.prod.config.js
More file actions
57 lines (54 loc) · 1.41 KB
/
webpack.prod.config.js
File metadata and controls
57 lines (54 loc) · 1.41 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
const commonConfig = require('./webpack.config.js')
const nodeExternals = require('webpack-node-externals')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const ts = require('typescript')
function removeJsxAttributesTransformer(attributes) {
return (context) => {
const visitor = (node) => {
if (ts.isJsxAttribute(node) && attributes.includes(node.name.getText())) {
return undefined
}
return ts.visitEachChild(node, visitor, context)
}
return (node) => ts.visitNode(node, visitor, context)
}
}
function getCssFilename(pathData) {
if (pathData.chunk.name === 'library') {
return 'index.css'
}
return `components/${pathData.chunk.name}/index.css`
}
module.exports = {
...commonConfig,
mode: 'production',
target: 'node',
module: {
rules: [
{
test: /\.(t|j)sx?$/,
use: {
loader: 'ts-loader',
options: {
configFile: 'tsconfig.prod.json',
getCustomTransformers: () => ({
before: [removeJsxAttributesTransformer(['data-cy'])],
}),
},
},
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
],
},
externalsPresets: { node: true },
externals: [nodeExternals({})],
plugins: [
new MiniCssExtractPlugin({
filename: getCssFilename,
}),
],
}