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 : / .j s $ / ,
43- exclude : ( modulePath ) => {
44- // Additionally, exclude `CoCreate-ffmpeg.js` file
45- if ( / f f m p e g / . 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 : / .c s s $ / 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 : / \. j s $ / ,
33+ exclude : ( modulePath ) => {
34+ if ( / f f m p e g / . test ( modulePath ) ) {
35+ return true ;
36+ }
37+ if ( / n o d e _ m o d u l e s / . 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 : / .c s s $ / 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