-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
109 lines (101 loc) · 2.63 KB
/
webpack.config.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
104
105
106
107
108
109
// @ts-nocheck
const path = require('path')
const webpack = require('webpack')
const nodeExternals = require('webpack-node-externals')
const StringReplacePlugin = require("string-replace-webpack-plugin")
const projectDir = path.resolve(__dirname)
const appDir = path.join(projectDir, 'app')
const mainAppEntryPoint = path.join(appDir, 'appMain.lsc')
const frontEndJsPath = path.join(appDir, 'components', 'settingsWindow', 'frontEnd', 'js')
const settingsWindowMainEntryPoint = path.join(frontEndJsPath, 'settingsWindowWeb.lsc')
const ISDEV = process.env.NODE_ENV !== 'production'
console.log('ISDEV: ', ISDEV)
console.log('process.env.NODE_ENV: ', process.env.NODE_ENV)
/*****
* We dont want webpack to include polyfills or mocks for various node stuff, which we set with
* the 'node' key https://webpack.js.org/configuration/node/
*
* We also dont want webpack to transpile the stuff in node_modules folder, so we use the
* webpack-node-externals plugin.
*
* Gonna still use DefinePlugin as its a bit shorter than using global.ISDEV.
*
* Ignore types.lsc imports with StringReplacePlugin as that's just flow and we don't need that
* in the compiled code.
*/
const commonWebpackOptions = {
mode: process.env.NODE_ENV,
devtool: ISDEV ? 'source-map' : 'none',
context: projectDir,
module: {
rules: [
{
test: /\.lsc$/,
exclude: [
/(node_modules)/
],
enforce: "pre",
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /import +\{.*\} +from.*\/types\/types\.lsc'/ig,
replacement: () => ''
}
]
})
},
{
test: /.lsc/,
exclude: [
/(node_modules)/
],
loader: 'babel-loader',
options: {
sourceMap: ISDEV
}
},
]
},
resolve: {
extensions: ['.lsc', '.js']
},
optimization: {
minimize: false
},
plugins: [
new webpack.DefinePlugin({ISDEV}),
new StringReplacePlugin()
]
}
const mainWebpackOptions = {
...commonWebpackOptions,
target: 'node',
entry: mainAppEntryPoint,
output: {
filename: 'appMain-compiled.js',
path: appDir
},
externals: [nodeExternals()],
node: {
console: false,
global: false,
process: false,
Buffer: false,
__filename: false,
__dirname: false,
setImmediate: false
}
}
const frontEndWebpackOptions = {
...commonWebpackOptions,
target: 'web',
entry: settingsWindowMainEntryPoint,
output: {
filename: 'settingsWindowWeb-compiled.js',
path: frontEndJsPath
}
}
module.exports = [
mainWebpackOptions,
frontEndWebpackOptions,
]