forked from hensm/fx_cast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·96 lines (87 loc) · 3.25 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
"use strict";
const path = require("path");
const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const sourceFileExtensions = [
".js", ".jsx"
, ".ts", ".tsx"
];
module.exports = (env) => ({
entry: {
"main": `${env.includePath}/main.ts`
// UI
, "ui/popup/bundle": `${env.includePath}/ui/popup/index.tsx`
, "ui/options/bundle": `${env.includePath}/ui/options/index.tsx`
, "ui/updater/bundle": `${env.includePath}/ui/updater/index.tsx`
// Sender apps
, "senders/mediaCast": `${env.includePath}/senders/mediaCast.ts`
, "senders/mirroringCast": `${env.includePath}/senders/mirroringCast.ts`
// Shim entries
, "shim/bundle": `${env.includePath}/shim/index.ts`
, "shim/content": `${env.includePath}/shim/content.ts`
, "shim/contentSetup": `${env.includePath}/shim/contentSetup.ts`
}
, output: {
filename: "[name].js"
, path: env.outputPath
}
, plugins: [
new webpack.DefinePlugin({
"EXTENSION_NAME": JSON.stringify(env.extensionName)
, "EXTENSION_ID": JSON.stringify(env.extensionId)
, "EXTENSION_VERSION": JSON.stringify(env.extensionVersion)
, "MIRRORING_APP_ID": JSON.stringify(env.mirroringAppId)
, "APPLICATION_NAME": JSON.stringify(env.applicationName)
, "APPLICATION_VERSION": JSON.stringify(env.applicationVersion)
})
// Copy static assets
, new CopyWebpackPlugin([
{
from: env.includePath
, to: env.outputPath
, ignore: sourceFileExtensions.map(ext => `*${ext}`)
, transform (content, path) {
// Access to variables in static files
if (path.endsWith(".json")) {
return Buffer.from(content.toString()
.replace("EXTENSION_NAME", env.extensionName)
.replace("EXTENSION_ID", env.extensionId)
.replace("EXTENSION_VERSION", env.extensionVersion)
.replace("MIRRORING_APP_ID", env.mirroringAppId)
.replace("APPLICATION_NAME", env.applicationName)
.replace("APPLICATION_VERSION", env.applicationVersion)
.replace("CONTENT_SECURITY_POLICY", env.contentSecurityPolicy)
.replace("AUTHOR", env.author)
.replace("AUTHOR_HOMEPAGE", env.authorHomepage));
}
return content;
}
}
, {
// Copy vendor dir
from: path.join(env.includePath, "vendor")
, to: path.join(env.outputPath, "vendor")
}
])
]
, module: {
rules: [
{
test: /\.(js|ts)x?$/
, resolve: {
extensions: sourceFileExtensions
}
, include: env.includePath
, use: {
loader: "ts-loader"
}
}
]
}
, resolve: {
alias: {
"react": "preact-compat"
, "react-dom": "preact-compat"
}
}
});