forked from shakacode/shakapacker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (43 loc) · 1.2 KB
/
index.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
/* eslint global-require: 0 */
/* eslint import/no-dynamic-require: 0 */
const { resolve } = require('path')
const { existsSync } = require('fs')
const { merge } = require('webpack-merge')
const isJsxFile = (filename) => !!filename.match(/\.(jsx|tsx)?(\.erb)?$/)
const isTypescriptFile = (filename) => !!filename.match(/\.(ts|tsx)?(\.erb)?$/)
const getCustomConfig = () => {
const path = resolve('config', 'swc.config.js')
if (existsSync(path)) {
return require(path)
}
return {}
}
const getSwcLoaderConfig = (filenameToProcess) => {
const customConfig = getCustomConfig()
const defaultConfig = {
loader: require.resolve('swc-loader'),
options: {
jsc: {
parser: {
dynamicImport: true,
syntax: isTypescriptFile(filenameToProcess)
? 'typescript'
: 'ecmascript',
[isTypescriptFile(filenameToProcess) ? 'tsx' : 'jsx']:
isJsxFile(filenameToProcess)
},
loose: true
},
sourceMaps: true,
env: {
coreJs: 3,
exclude: ['transform-typeof-symbol'],
mode: 'entry'
}
}
}
return merge(defaultConfig, customConfig)
}
module.exports = {
getSwcLoaderConfig
}