11"use strict" ;
22
33const path = require ( "path" ) ;
4+ const webpack = require ( "webpack" ) ;
45const { CheckEsVersionPlugin } = require ( "@bitjourney/check-es-version-webpack-plugin" ) ;
5- module . exports = {
6+ const _ = require ( "lodash" ) ;
7+
8+ const config = {
69 mode : "production" ,
710
811 entry : "./src/index.ts" ,
912 output : {
1013 path : path . resolve ( __dirname , "dist.es5" ) ,
11- filename : "msgpack.js" ,
1214 libraryTarget : "commonjs" ,
1315 } ,
1416 resolve : {
@@ -26,7 +28,17 @@ module.exports = {
2628 ] ,
2729 } ,
2830
29- // We use webpack just to reduce filesystem accesses
31+ plugins : [
32+ new CheckEsVersionPlugin ( {
33+ esVersion : 5 , // for IE11 support
34+ } ) ,
35+ ] ,
36+ externals : {
37+ "base64-js" : {
38+ commonjs : "base64-js" ,
39+ } ,
40+ } ,
41+
3042 optimization : {
3143 noEmitOnErrors : true ,
3244 minimize : false ,
@@ -36,11 +48,34 @@ module.exports = {
3648 // https://webpack.js.org/configuration/node/
3749 node : false ,
3850
39- plugins : [
40- new CheckEsVersionPlugin ( {
41- esVersion : 5 , // for IE11 support
42- } ) ,
43- ] ,
44-
4551 devtool : "source-map" ,
4652} ;
53+
54+ module . exports = [
55+ // default bundle does not includes wasm
56+ ( ( config ) => {
57+ config . output . filename = "msgpack.js" ;
58+ config . plugins . push (
59+ new webpack . DefinePlugin ( {
60+ // The default bundle does not includes WASM
61+ "process.env.MSGPACK_WASM" : JSON . stringify ( "never" ) ,
62+ "process.env.WASM" : JSON . stringify ( null ) ,
63+ } ) ,
64+ new webpack . IgnorePlugin ( / \. \/ d i s t \/ w a s m \/ m s g p a c k \. w a s m \. j s $ / ) ,
65+ ) ;
66+ return config ;
67+ } ) ( _ . cloneDeep ( config ) ) ,
68+
69+ // +wsm
70+ ( ( config ) => {
71+ config . output . filename = "msgpack+wasm.js" ;
72+ config . plugins . push (
73+ new webpack . DefinePlugin ( {
74+ // The default bundle does not includes WASM
75+ "process.env.MSGPACK_WASM" : JSON . stringify ( null ) ,
76+ "process.env.WASM" : JSON . stringify ( null ) ,
77+ } ) ,
78+ ) ;
79+ return config ;
80+ } ) ( _ . cloneDeep ( config ) ) ,
81+ ] ;
0 commit comments