This repository was archived by the owner on May 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
66 lines (62 loc) · 1.69 KB
/
webpack.config.js
File metadata and controls
66 lines (62 loc) · 1.69 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
const webpack = require('webpack')
const nodeExternals = require('webpack-node-externals')
const expandEntries = require('./config/expandEntries')
const DtsGeneratorPlugin = require('./config/plugins/DtsGeneratorPlugin')
const ImportReplacementPlugin = require('./config/plugins/ImportReplacementPlugin')
const getConfig = async (entries, envName = 'development') => {
return {
entry: entries,
mode: envName,
target: 'node',
output: {
path: __dirname,
filename: ({ chunk: { name } }) => {
return name.replace(/\.tsx?$/, '.js') // may change index.ts to index.js
},
libraryTarget: 'commonjs2'
},
resolve: {
extensions: [
'.ts',
'.js',
'.tsx'
]
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [
'ts-loader'
],
exclude: /node_modules/
}
]
},
externalsPresets: { node: true },
externals: [
nodeExternals()
],
plugins: [
new ImportReplacementPlugin({
react: 'preact/compat',
'react-dom': 'preact/compat'
}, /preact\//),
new DtsGeneratorPlugin(),
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(envName)
}),
new webpack.IgnorePlugin({
resourceRegExp: /.md$/
})
],
watch: envName === 'development',
devtool: envName === 'development' && 'inline-source-map'
}
}
exports = module.exports = async env => {
const expandedEntriesPath = env.ENTRY_PATH || process.env.ENTRY_PATH || '{packages,react}/*'
const entries = await expandEntries(expandedEntriesPath)
return getConfig(entries, process.env.NODE_ENV)
}
exports.getConfig = getConfig