Skip to content

Commit 7f45577

Browse files
committed
fix: webpack.config and devdependencies
1 parent f8e790a commit 7f45577

File tree

2 files changed

+76
-107
lines changed

2 files changed

+76
-107
lines changed

package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,9 @@
4242
},
4343
"main": "./src/index.js",
4444
"devDependencies": {
45-
"@babel/core": "^7.9.6",
46-
"@babel/preset-env": "^7.9.6",
47-
"babel-loader": "^8.1.0",
48-
"clean-webpack-plugin": "^3.0.0",
49-
"file-loader": "^6.2.0",
45+
"esbuild": "^0.25.2",
46+
"esbuild-loader": "^4.3.0",
5047
"mini-css-extract-plugin": "^1.5.0",
51-
"style-loader": "^3.3.1",
52-
"terser-webpack-plugin": "^5.1.1",
5348
"webpack": "^5.24.4",
5449
"webpack-cli": "^4.5.0",
5550
"webpack-log": "^3.0.1"
@@ -60,4 +55,4 @@
6055
"@ffmpeg/ffmpeg": "^0.12.10",
6156
"@ffmpeg/util": "^0.12.1"
6257
}
63-
}
58+
}

webpack.config.js

Lines changed: 73 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,75 @@
1+
const path = require("path");
2+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
13

4+
const { EsbuildPlugin } = require("esbuild-loader");
5+
const { FileUploader } = require("@cocreate/webpack");
26

3-
const path = require("path")
4-
5-
const TerserPlugin = require("terser-webpack-plugin")
6-
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
7-
const { CleanWebpackPlugin } = require("clean-webpack-plugin")
8-
9-
module.exports = (env, argv) => {
10-
let isProduction = false
11-
if (argv.mode === 'production')
12-
isProduction = true
13-
14-
const config = {
15-
entry: {
16-
"CoCreate-ffmpeg": "./src/index.js",
17-
},
18-
output: {
19-
path: path.resolve(__dirname, "dist"),
20-
filename: isProduction ? "[name].min.js" : "[name].js",
21-
libraryTarget: "umd",
22-
libraryExport: "default",
23-
library: ["CoCreate", "ffmpeg"],
24-
globalObject: "this",
25-
},
26-
experiments: {
27-
asyncWebAssembly: true,
28-
topLevelAwait: true,
29-
},
30-
31-
plugins: [
32-
new CleanWebpackPlugin(),
33-
new MiniCssExtractPlugin({
34-
filename: "[name].css",
35-
}),
36-
],
37-
38-
mode: isProduction ? "production" : "development",
39-
module: {
40-
rules: [
41-
{
42-
test: /.js$/,
43-
exclude: (modulePath) => {
44-
// Additionally, exclude `CoCreate-ffmpeg.js` file
45-
if (/ffmpeg/.test(modulePath)) {
46-
return true;
47-
}
48-
// Include all other .js files
49-
return false;
50-
},
51-
use: {
52-
loader: "babel-loader",
53-
options: {
54-
plugins: ["@babel/plugin-transform-modules-commonjs"],
55-
},
56-
},
57-
},
58-
{
59-
test: /.css$/i,
60-
use: [
61-
{ loader: "style-loader", options: { injectType: "linkTag" } },
62-
"file-loader",
63-
],
64-
},
65-
],
66-
},
67-
68-
// add source map
69-
...(isProduction ? {} : { devtool: "eval-source-map" }),
70-
71-
optimization: {
72-
minimize: true,
73-
minimizer: [
74-
new TerserPlugin({
75-
extractComments: true,
76-
// cache: true,
77-
parallel: true,
78-
// sourceMap: true, // Must be set to true if using source-maps in production
79-
terserOptions: {
80-
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
81-
// extractComments: 'all',
82-
compress: {
83-
drop_console: true,
84-
},
85-
},
86-
}),
87-
],
88-
// splitChunks: {
89-
// chunks: "all",
90-
// minSize: 200,
91-
// // maxSize: 99999,
92-
// //minChunks: 1,
93-
94-
// cacheGroups: {
95-
// defaultVendors: false,
96-
// },
97-
// },
98-
},
99-
}
100-
return config
101-
}
7+
module.exports = async (env, argv) => {
8+
const isProduction = argv && argv.mode === "production";
9+
const config = {
10+
entry: {
11+
"CoCreate-ffmpeg": "./src/index.js"
12+
},
13+
output: {
14+
path: path.resolve(__dirname, "dist"),
15+
filename: isProduction ? "[name].min.js" : "[name].js",
16+
libraryExport: "default",
17+
library: ["CoCreate", "ffmpeg"],
18+
clean: true
19+
},
20+
plugins: [
21+
new MiniCssExtractPlugin({
22+
filename: isProduction ? "[name].min.css" : "[name].css"
23+
}),
24+
,
25+
new FileUploader(env, argv)
26+
],
27+
mode: isProduction ? "production" : "development",
28+
devtool: isProduction ? "source-map" : "eval-source-map",
29+
module: {
30+
rules: [
31+
{
32+
test: /\.js$/,
33+
exclude: (modulePath) => {
34+
if (/ffmpeg/.test(modulePath)) {
35+
return true;
36+
}
37+
if (/node_modules/.test(modulePath)) {
38+
return true;
39+
}
40+
return false;
41+
},
42+
use: {
43+
loader: "esbuild-loader",
44+
options: {
45+
loader: "js",
46+
target: "es2017"
47+
}
48+
}
49+
},
50+
{
51+
test: /.css$/i,
52+
use: [MiniCssExtractPlugin.loader, "css-loader"]
53+
}
54+
]
55+
},
56+
optimization: {
57+
minimize: isProduction,
58+
minimizer: [
59+
new EsbuildPlugin({
60+
target: "es2017",
61+
css: true
62+
})
63+
],
64+
splitChunks: {
65+
cacheGroups: {
66+
defaultVendors: false
67+
}
68+
}
69+
},
70+
performance: {
71+
hints: isProduction ? "warning" : false
72+
}
73+
};
74+
return config;
75+
};

0 commit comments

Comments
 (0)