-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathwebpack.config.js
More file actions
89 lines (86 loc) · 3.47 KB
/
webpack.config.js
File metadata and controls
89 lines (86 loc) · 3.47 KB
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
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const path = require('path');
const webpack = require('webpack');
const packageJson = require('./package.json');
// UMD browser bundle. The node entry point is the plain `tsc` output (lib/index.js);
// this config produces only the browser bundle (umd/template-engine.js). Node-only paths
// — Template.fromDirectory/fromUrl, child-process logic evaluation, disk output — are not
// available in the browser; use Template.fromArchive + the in-process evaluator instead.
module.exports = {
target: 'web',
mode: 'production',
entry: path.resolve(__dirname, 'lib', 'index.js'),
output: {
clean: false,
path: path.resolve(__dirname, 'umd'),
filename: 'template-engine.js',
library: {
name: 'template-engine',
type: 'umd',
},
globalObject: 'self',
},
// No source map: the published browser bundle bundles concerto/markdown/typescript,
// so the map balloons to ~30MB. Behaviour-only e2e tests don't need it.
devtool: false,
resolve: {
extensions: ['.js'],
mainFields: ['browser', 'module', 'main'],
alias: {
// Force the concerto-core CJS/browser entry so webpack can apply fallbacks.
'@accordproject/concerto-core': require.resolve('@accordproject/concerto-core/dist/concerto-core.js'),
'node:events': require.resolve('events/'),
},
fallback: {
fs: false,
net: false,
tls: false,
child_process: false,
os: false,
util: false,
vm: false,
assert: false,
path: require.resolve('path-browserify'),
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer/'),
events: require.resolve('events/'),
},
},
module: {
rules: [
{ test: /\.js$/, loader: 'source-map-loader', exclude: /node_modules/ },
],
},
plugins: [
// getWorkerPath() does require.resolve('@accordproject/template-engine') on the
// node-only child-process evaluation path, which is unreachable in the browser
// (the default in-process evaluator is used instead). Ignore the self-reference so
// the bundle builds.
new webpack.IgnorePlugin({ resourceRegExp: /^@accordproject\/template-engine$/ }),
new webpack.BannerPlugin(
`Accord Project Template Engine v${packageJson.version} — browser build\n` +
'Licensed under the Apache License, Version 2.0'
),
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify('production') },
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser',
}),
],
};