1
- const path = require ( "path" )
2
- const TerserPlugin = require ( "terser-webpack-plugin" )
3
- const MiniCssExtractPlugin = require ( "mini-css-extract-plugin" )
4
- const { CleanWebpackPlugin } = require ( "clean-webpack-plugin" )
5
-
6
- module . exports = ( env , argv ) => {
7
- let isProduction = false
8
- if ( argv . mode === 'production' )
9
- isProduction = true
10
-
11
- const config = {
12
- entry : {
13
- "CoCreate-element-prototype" : "./src/index.js" ,
14
- } ,
15
- output : {
16
- path : path . resolve ( __dirname , "dist" ) ,
17
- filename : isProduction ? "[name].min.js" : "[name].js" ,
18
- libraryTarget : "umd" ,
19
- libraryExport : "default" ,
20
- library : [ "CoCreate" , "element-prototype" ] ,
21
- globalObject : "this" ,
22
- } ,
23
-
24
- plugins : [
25
- new CleanWebpackPlugin ( ) ,
26
- new MiniCssExtractPlugin ( {
27
- filename : "[name].css" ,
28
- } ) ,
29
- ] ,
30
- // Default mode for Webpack is production.
31
- // Depending on mode Webpack will apply different things
32
- // on final bundle. For now we don't need production's JavaScript
33
- // minifying and other thing so let's set mode to development
34
- mode : isProduction ? "production" : "development" ,
35
- module : {
36
- rules : [
37
- {
38
- test : / .j s $ / ,
39
- exclude : / ( n o d e _ m o d u l e s ) / ,
40
- use : {
41
- loader : "babel-loader" ,
42
- options : {
43
- plugins : [ "@babel/plugin-transform-modules-commonjs" ] ,
44
- } ,
45
- } ,
46
- } ,
47
- {
48
- test : / .c s s $ / i,
49
- use : [
50
- { loader : "style-loader" , options : { injectType : "linkTag" } } ,
51
- "file-loader" ,
52
- ] ,
53
- } ,
54
- ] ,
55
- } ,
56
-
57
- // add source map
58
- ...( isProduction ? { } : { devtool : "eval-source-map" } ) ,
59
-
60
- optimization : {
61
- minimize : true ,
62
- minimizer : [
63
- new TerserPlugin ( {
64
- extractComments : true ,
65
- // cache: true,
66
- parallel : true ,
67
- // sourceMap: true, // Must be set to true if using source-maps in production
68
- terserOptions : {
69
- // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
70
- // extractComments: 'all',
71
- compress : {
72
- drop_console : true ,
73
- } ,
74
- } ,
75
- } ) ,
76
- ] ,
77
- splitChunks : {
78
- chunks : "all" ,
79
- minSize : 200 ,
80
- // maxSize: 99999,
81
- //minChunks: 1,
82
-
83
- cacheGroups : {
84
- defaultVendors : false ,
85
- } ,
86
- } ,
87
- } ,
88
- }
89
- return config
90
- }
1
+ const path = require ( "path" ) ;
2
+ const MiniCssExtractPlugin = require ( "mini-css-extract-plugin" ) ;
3
+ const { EsbuildPlugin } = require ( "esbuild-loader" ) ;
4
+ const { FileUploader } = require ( "@cocreate/webpack" ) ;
5
+
6
+ module . exports = async ( env , argv ) => {
7
+ const isProduction = argv && argv . mode === "production" ;
8
+ const config = {
9
+ entry : {
10
+ "CoCreate-element-prototype" : "./src/index.js"
11
+ } ,
12
+ output : {
13
+ path : path . resolve ( __dirname , "dist" ) ,
14
+ filename : isProduction ? "[name].min.js" : "[name].js" ,
15
+ libraryExport : "default" ,
16
+ library : [ "CoCreate" , "elementPrototype" ] ,
17
+ clean : true
18
+ } ,
19
+ plugins : [
20
+ new MiniCssExtractPlugin ( {
21
+ filename : isProduction ? "[name].min.css" : "[name].css"
22
+ } ) ,
23
+ new FileUploader ( env , argv )
24
+ ] ,
25
+ mode : isProduction ? "production" : "development" ,
26
+ devtool : isProduction ? "source-map" : "eval-source-map" ,
27
+ module : {
28
+ rules : [
29
+ {
30
+ test : / .j s $ / ,
31
+ exclude : / n o d e _ m o d u l e s / ,
32
+ use : {
33
+ loader : "esbuild-loader" ,
34
+ options : {
35
+ loader : "js" ,
36
+ target : "es2017"
37
+ }
38
+ }
39
+ } ,
40
+ {
41
+ test : / .c s s $ / i,
42
+ use : [ MiniCssExtractPlugin . loader , "css-loader" ]
43
+ }
44
+ ]
45
+ } ,
46
+ optimization : {
47
+ minimize : isProduction ,
48
+ minimizer : [
49
+ new EsbuildPlugin ( {
50
+ target : "es2017" ,
51
+ css : true
52
+ } )
53
+ ] ,
54
+ splitChunks : {
55
+ cacheGroups : {
56
+ defaultVendors : false
57
+ }
58
+ }
59
+ } ,
60
+ performance : {
61
+ hints : isProduction ? "warning" : false
62
+ }
63
+ } ;
64
+ return config ;
65
+ } ;
0 commit comments