This repository has been archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
68 lines (63 loc) · 1.88 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
const webpack = require("webpack")
const { dirname, basename, join } = require("path")
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const { publicFolder } = require("./config")
const isProduction = process.env.NODE_ENV === "production"
const prodPlugins = [
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production")
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: "[name].css",
chunkFilename: "[id].css",
})
]
const config = (entry, outfile, node = false) => {
return {
entry,
output: {
path: join(__dirname, dirname(outfile)),
filename: basename(outfile)
},
mode: isProduction ? "production" : "development",
target: node ? "node" : "web",
module: {
rules: [{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.(sa|sc|c)ss$/,
use: [
isProduction ? MiniCssExtractPlugin.loader : "style-loader",
{
loader: "css-loader",
options: {
url: false
}
},
"sass-loader"
]
}],
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".css", ".scss", ".sass"],
// Comment this in if preact-compat is necessary
"alias": {
'react': 'preact-compat',
'react-dom': 'preact-compat',
// Not necessary unless you consume a module using `createClass`
'create-react-class': 'preact-compat/lib/create-react-class',
// Not necessary unless you consume a module requiring `react-dom-factories`
'react-dom-factories': 'preact-compat/lib/react-dom-factories'
}
},
plugins: isProduction ? prodPlugins : []
}
}
module.exports = [
config("./src/index.tsx", publicFolder + "/bundle.js")
]