Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
178 lines (159 loc) · 6.03 KB
/
Copy pathwebpack.config.js
File metadata and controls
178 lines (159 loc) · 6.03 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import path from "path";
import { fileURLToPath } from "url";
import webpack from "webpack";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import { EsbuildPlugin } from "esbuild-loader";
// Reconstruct __dirname for ES Modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import CoCreateConfig from "./CoCreate.config.js";
import cocreateWebpack from "@cocreate/webpack";
const { ModuleGenerator, FileUploader, UnicodeLoader } = cocreateWebpack;
export default async (env, argv) => {
const isProduction = argv.mode === "production";
const config = {
entry: {
CoCreate: "./CoCreate.index.js"
},
output: {
path: path.resolve(__dirname, "./src/dist"),
filename: isProduction ? "[name].js" : "[name].js",
chunkFilename: isProduction ? "[name].js" : "[name].js",
library: "CoCreate", // Global namespace in the browser
libraryExport: "default",
clean: true
},
// Explicitly target client/browser environment
target: "web",
experiments: {
asyncWebAssembly: true,
topLevelAwait: true
},
resolve: {
fallback: {
// Completely exclude server-only node core modules from the client bundle
"child_process": false,
"fs": false,
"module": false,
"os": false,
"path": false,
"readline": false,
"url": false,
"util": false,
"stream": false,
"crypto": false,
"http": false,
"https": false,
"zlib": false,
"assert": false,
"buffer": false
}
},
externals: {
// Treat these dependencies as browser globals rather than bundling them
"marked": "marked",
"github-markdown-css/github-markdown.css": "var Object",
"@simonwep/pickr": "Pickr",
"@simonwep/pickr/dist/themes/monolith.min.css": "var Object",
"prismjs": "Prism",
"prismjs/components/prism-css-extras.js": "var Object",
"prismjs/plugins/line-numbers/prism-line-numbers.js": "var Object",
"prismjs/plugins/line-numbers/prism-line-numbers.css": "var Object"
},
plugins: [
new ModuleGenerator(CoCreateConfig),
new FileUploader(env, argv),
// Bypass compile-time evaluation and prevent compiling of 'node:*' schemes
new webpack.IgnorePlugin({
resourceRegExp: /^node:/
}),
// Redirect any dynamic import of "CoCreate.config.js" straight to root
new webpack.NormalModuleReplacementPlugin(
/CoCreate\.config\.js$/,
function (resource) {
resource.request = path.resolve(__dirname, "./CoCreate.config.js");
}
),
new MiniCssExtractPlugin({
filename: isProduction ? "[name].min.css" : "[name].css",
chunkFilename: (pathData) => {
if (pathData.chunk.name === "CoCreateCSS") {
return isProduction
? "CoCreate.min.css"
: "CoCreate.css";
}
return isProduction ? "[name].min.css" : "[name].css";
}
})
],
mode: isProduction ? "production" : "development",
devtool: isProduction ? "source-map" : "eval-source-map",
module: {
rules: [
{
test: /\.js$/,
exclude: (modulePath) => {
if (/ffmpeg/.test(modulePath)) {
return true;
}
if (/node_modules/.test(modulePath)) {
return true;
}
return false;
},
use: [
{
loader: path.resolve(
__dirname,
"node_modules/@cocreate/webpack/src/replace-unicode.js"
)
},
{
loader: "esbuild-loader",
options: {
target: "es2017"
}
}
]
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader"]
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
type: "asset/resource",
generator: {
filename: "fonts/[name][ext][query]"
}
}
]
},
optimization: {
minimize: isProduction,
minimizer: [
new EsbuildPlugin({
target: "es2017",
css: true
})
],
splitChunks: {
chunks: "all",
minSize: 1,
minChunks: 1,
maxAsyncRequests: 30,
maxInitialRequests: 30,
enforceSizeThreshold: 50000,
cacheGroups: {
defaultVendors: false
}
}
},
performance: {
hints: isProduction ? "warning" : false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
}
};
return config;
};