Skip to content

Commit f2138c5

Browse files
committed
fix: to support lazy loading ffmpeg as module
1 parent 0085fe1 commit f2138c5

File tree

1 file changed

+55
-32
lines changed

1 file changed

+55
-32
lines changed

webpack.config.js

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ module.exports = async (env, argv) => {
2020
path: path.resolve(__dirname, 'dist'),
2121
filename: isProduction ? '[name].min.js' : '[name].js',
2222
chunkFilename: isProduction ? '[name].min.js' : '[name].js',
23+
// filename: isProduction ? '[name].js' : '[name].js',
24+
// chunkFilename: isProduction ? '[name].js' : '[name].js',
2325
libraryTarget: 'umd',
2426
libraryExport: 'default',
2527
library: 'CoCreate',
2628
globalObject: "this",
2729
},
2830

31+
experiments: {
32+
asyncWebAssembly: true,
33+
topLevelAwait: true,
34+
},
35+
2936
plugins: [
3037
new ModuleGenerator(CoCreateConfig.modules),
3138
new FileUploader(env, argv),
@@ -50,43 +57,59 @@ module.exports = async (env, argv) => {
5057
mode: isProduction ? 'production' : 'development',
5158

5259
// add source map
53-
...(isProduction ? { devtool: 'eval-source-map' } : { devtool: 'eval-source-map' }),
60+
...(isProduction ? {} : { devtool: 'eval-source-map' }),
5461

5562
module: {
56-
rules: [{
57-
test: /\.js$/,
58-
use: [
59-
{
60-
loader: path.resolve(__dirname, 'node_modules/@cocreate/webpack/src/replace-unicode.js')
63+
rules: [
64+
{
65+
test: /\.js$/,
66+
exclude: (modulePath) => {
67+
// Additionally, exclude `CoCreate-ffmpeg.js` file
68+
if (/ffmpeg/.test(modulePath)) {
69+
return true;
70+
}
71+
// Include all other .js files
72+
return false;
6173
},
62-
{
63-
loader: 'babel-loader',
64-
options: {
65-
plugins: ["@babel/plugin-transform-modules-commonjs"],
66-
retainLines: true, // Add this option
74+
use: [
75+
{
76+
loader: path.resolve(__dirname, 'node_modules/@cocreate/webpack/src/replace-unicode.js')
77+
},
78+
{
79+
loader: 'babel-loader',
80+
options: {
81+
plugins: ["@babel/plugin-transform-modules-commonjs"],
82+
retainLines: true, // Add this option
83+
}
6784
}
68-
}
69-
]
70-
},
71-
{
72-
test: /.css$/i,
73-
use: [
74-
MiniCssExtractPlugin.loader,
75-
'css-loader'
76-
]
77-
},
78-
{
79-
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
80-
use: [
81-
{
82-
loader: 'file-loader',
83-
options: {
84-
name: '[name].[ext]',
85-
outputPath: 'fonts/'
85+
]
86+
},
87+
{
88+
test: /\.js$/,
89+
generator: {
90+
filename: '[name].js', // Customize this pattern
91+
},
92+
},
93+
{
94+
test: /.css$/i,
95+
use: [
96+
MiniCssExtractPlugin.loader,
97+
'css-loader'
98+
]
99+
},
100+
{
101+
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
102+
use: [
103+
{
104+
loader: 'file-loader',
105+
options: {
106+
name: '[name].[ext]',
107+
outputPath: 'fonts/'
108+
}
86109
}
87-
}
88-
]
89-
}]
110+
]
111+
}
112+
]
90113
},
91114

92115
optimization: {

0 commit comments

Comments
 (0)