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
| // Copyright (c) Microsoft Corporation. All rights reserved.
| // Licensed under the MIT License.
|
| 'use strict';
|
| import webpack from 'webpack';
| import { resolve } from 'node:path';
| import { DEFAULT_ES_VERSION, addCopyrightBannerPlugin } from '../webpack.shared.mjs';
|
| function buildConfig({
| suffix = '.js', // '.js', '.min.js', ...
| format = 'umd', // 'umd', 'commonjs'
| target = 'web', // 'web', 'node'
| esVersion = DEFAULT_ES_VERSION, // 'es5', 'es6', ...
| mode = 'production', // 'development', 'production'
| devtool = 'source-map', // 'inline-source-map', 'source-map'
| }) {
| // output file name
| const filename = `ort-common${suffix}`;
|
| // variable name of the exported object.
| // - set to 'ort' when building 'umd' format.
| // - set to undefined when building other formats (commonjs/module)
| const exportName = format === 'umd' ? 'ort' : undefined;
|
| return {
| target: [target, esVersion],
| entry: resolve('./lib/index.ts'),
| output: {
| path: resolve('./dist'),
| filename,
| library: { name: exportName, type: format },
| },
| resolve: {
| extensions: ['.ts', '.js'],
| extensionAlias: { '.js': ['.ts', '.js'] },
| },
| plugins: [
| new webpack.WatchIgnorePlugin({ paths: [/\.js$/, /\.d\.ts$/] }),
| addCopyrightBannerPlugin(mode, 'common', esVersion),
| ],
| module: {
| rules: [
| {
| test: /\.ts$/,
| use: [
| {
| loader: 'ts-loader',
| options: { compilerOptions: { target: esVersion } },
| },
| ],
| },
| ],
| },
| mode,
| devtool,
| };
| }
|
| export default (env, argv) => {
| return [
| buildConfig({ suffix: '.es5.min.js', target: 'web', esVersion: 'es5' }),
| buildConfig({ suffix: '.min.js' }),
| buildConfig({ mode: 'development', devtool: 'inline-source-map' }),
| buildConfig({
| suffix: '.node.cjs',
| target: 'node',
| format: 'commonjs',
| }),
| ];
| };
|
|