-
Notifications
You must be signed in to change notification settings - Fork 4
/
libraryCracoPlugin.js
55 lines (48 loc) · 1.64 KB
/
libraryCracoPlugin.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
const path = require("path");
module.exports = {
overrideWebpackConfig: ({
webpackConfig,
cracoConfig,
pluginOptions,
context: { env, paths },
}) => {
// console.log({ env, paths });
paths.appBuild = path.resolve(__dirname, "./packageToPublish");
if (env === "production" && process.env.library) {
webpackConfig.entry = [path.resolve(__dirname, "./src/library.ts")];
webpackConfig.output.path = path.resolve(__dirname, "./packageToPublish");
webpackConfig.output.filename = `[name].js`;
webpackConfig.output.libraryTarget = `umd`;
webpackConfig.output.libraryExport = ``;
webpackConfig.externals = {
react: "react",
};
webpackConfig.optimization = {
minimize: true,
splitChunks: { chunks: "all", name: false, minSize: Math.pow(10, 10) },
// splitChunks: undefined,
};
const pluginsToKeep = new Set([
"ForkTsCheckerWebpackPlugin",
"IgnorePlugin",
"DefinePlugin",
"ModuleNotFoundPlugin",
"ManifestPlugin",
"MiniCssExtractPlugin",
]);
webpackConfig.plugins = webpackConfig.plugins.filter((p) =>
pluginsToKeep.has(p.constructor.name)
);
const miniCssExtractPlugin = webpackConfig.plugins.find(
(p) => p.constructor.name === "MiniCssExtractPlugin"
);
// MiniCssExtractPlugin.options.filename = "";
miniCssExtractPlugin.options.filename = "[name].css";
miniCssExtractPlugin.options.chunkFilename = undefined;
// console.log(webpackConfig);
// return;
}
// Always return the config object.
return webpackConfig;
},
};