forked from github-education-resources/classroom-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.renderer.config.js
113 lines (106 loc) · 2.5 KB
/
webpack.renderer.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
110
111
112
113
const fs = require("fs-extra")
const path = require("path")
const rules = require("./webpack.rules")
const webpack = require("webpack")
const getReplacements = require("./app-info")
const replacements = getReplacements()
const isDev = process.env.NODE_ENV === "development"
const AfterDonePlugin = function (calllback) {
this.apply = function (compiler) {
const runAfter = () => {
calllback()
}
const webpackTap =
compiler.hooks &&
compiler.hooks.done &&
compiler.hooks.done.tap.bind(compiler.hooks.done)
if (webpackTap) {
webpackTap("WebpackAfterDonePlugin", runAfter)
} else {
compiler.plugin("done", runAfter)
}
}
}
const plugins = [
new webpack.DefinePlugin(
Object.assign({}, replacements, {
__PROCESS_KIND__: JSON.stringify("renderer"),
})
),
]
// In development we don't need to copy because we use the node_modules version of dugite
if (!isDev) {
plugins.push(new AfterDonePlugin((logger) => {
const gitDir = ".webpack/git"
fs.removeSync(gitDir)
fs.mkdirpSync(gitDir)
fs.copySync(path.resolve(__dirname, "node_modules/dugite/git"), gitDir, { recursive: true })
}))
}
rules.push(
{
test: /\.(scss|sass)$/,
exclude: /node_modules/,
loaders: [
{
loader: "style-loader",
},
{
loader: "css-loader",
},
{
loader: "sass-loader", // the sass-loader converts the sass into css, the css-loader puts that css into the JS, the style-loader puts the javascript into the DOM.
},
],
},
{
test: /\.css$/i, // regex to select only .css files
use: [
{
loader: "style-loader",
},
{
loader: "css-loader",
},
],
},
// Needed for font-awesome
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "url-loader?limit=10000000&mimetype=application/font-woff",
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "file-loader",
},
{
test: /\.(png|jpg|gif)$/,
// loader: "file-loader",
loader: "url-loader?limit=1000000",
},
{
test: /\.jsx$/,
use: [
{
loader: "babel-loader",
options: {
presets: ["@babel/env", "@babel/react"],
plugins: ["@babel/plugin-transform-runtime"],
},
},
],
}
)
module.exports = {
module: {
rules,
},
node: {
__dirname: isDev,
},
resolve: {
extensions: [".js", ".jsx", ".css", ".scss", ".json"],
modules: ["node_modules"],
},
plugins: plugins,
}