forked from input-output-hk/lace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
120 lines (116 loc) · 3.82 KB
/
webpack.common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const path = require('path');
const { NormalModuleReplacementPlugin, ProvidePlugin, IgnorePlugin, EnvironmentPlugin } = require('webpack');
const Dotenv = require('dotenv-webpack');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const { SubresourceIntegrityPlugin } = require('webpack-subresource-integrity');
const commitHash = Buffer.from(require('child_process').execSync('git rev-parse HEAD')).toString();
const app_version = require('./manifest.json').version;
require('dotenv-defaults').config({
path: './.env',
encoding: 'utf8'
});
const envsToExpose = {
APP_VERSION: app_version,
COMMIT_HASH: commitHash
//'process.env': JSON.stringify(process.env)
};
if ('SENTRY_DSN' in process.env) envsToExpose['SENTRY_DSN'] = process.env.SENTRY_DSN;
if ('SENTRY_ENVIRONMENT' in process.env) envsToExpose['SENTRY_ENVIRONMENT'] = process.env.SENTRY_ENVIRONMENT;
module.exports = () => {
return {
output: {
path: path.join(__dirname, 'dist/js'),
filename: '[name].js',
// the following setting is required for SRI to work:
crossOriginLoading: 'anonymous'
},
module: {
rules: [
{
test: /packages\/.+\/dist\/.+\.js$/,
enforce: 'pre',
use: ['source-map-loader']
},
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules\/(?!(@cardano-sdk)\/).*/,
loader: 'swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
tsx: true
},
target: 'es2019',
loose: false
}
},
resolve: {
fullySpecified: false
}
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.mjs'],
fallback: {
https: require.resolve('https-browserify'),
http: require.resolve('stream-http'),
'get-port-please': false,
net: false,
fs: false,
os: false,
path: false,
events: require.resolve('events/'),
buffer: require.resolve('buffer/'),
stream: require.resolve('readable-stream'),
crypto: require.resolve('crypto-browserify'),
constants: require.resolve('constants-browserify'),
zlib: require.resolve('browserify-zlib'),
dns: false,
tls: false,
process: false,
child_process: false
},
plugins: [new TsconfigPathsPlugin({ configFile: 'src/tsconfig.json' })]
},
plugins: [
new IgnorePlugin({
checkResource(resource) {
return /.*\/wordlists\/(?!english).*\.json/.test(resource);
}
}),
new IgnorePlugin({
resourceRegExp: /\/(tests|test|__tests__|mocks)(\/|$)/,
contextRegExp: /.*/
}),
new IgnorePlugin({ resourceRegExp: /^\.\/wordlists\/(?!english)/, contextRegExp: /bip39\/src$/ }),
new NormalModuleReplacementPlugin(/blake2b$/, 'blake2b-no-wasm'),
new NormalModuleReplacementPlugin(/@emurgo\/cip14-js/, path.join(__dirname, './src/utils/cip14.js')),
new NormalModuleReplacementPlugin(
/@emurgo\/cardano-message-signing-nodejs/,
'@emurgo/cardano-message-signing-browser'
),
new ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser'
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: 'src/tsconfig.json'
}
}),
new Dotenv({
path: '.env',
safe: false,
silent: false,
defaults: process.env.BUILD_DEV_PREVIEW === 'true' ? '.env.developerpreview' : true,
systemvars: true,
allowEmptyValues: true
}),
new EnvironmentPlugin(envsToExpose),
new SubresourceIntegrityPlugin()
]
};
};