2021-08-07 02:35:43 +00:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2023-06-12 19:05:11 +00:00
|
|
|
import webpack from 'webpack';
|
2024-08-14 23:51:22 +00:00
|
|
|
import { resolve } from 'node:path';
|
|
|
|
|
import { DEFAULT_ES_VERSION, addCopyrightBannerPlugin } from '../webpack.shared.mjs';
|
2021-04-16 08:33:10 +00:00
|
|
|
|
|
|
|
|
function buildConfig({
|
2024-08-14 23:51:22 +00:00
|
|
|
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'
|
2021-04-16 08:33:10 +00:00
|
|
|
}) {
|
2023-06-12 19:05:11 +00:00
|
|
|
// 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;
|
|
|
|
|
|
2021-04-16 08:33:10 +00:00
|
|
|
return {
|
2023-06-12 19:05:11 +00:00
|
|
|
target: [target, esVersion],
|
|
|
|
|
entry: resolve('./lib/index.ts'),
|
2021-04-16 08:33:10 +00:00
|
|
|
output: {
|
2023-06-12 19:05:11 +00:00
|
|
|
path: resolve('./dist'),
|
|
|
|
|
filename,
|
2024-08-14 23:51:22 +00:00
|
|
|
library: { name: exportName, type: format },
|
2023-06-12 19:05:11 +00:00
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
extensions: ['.ts', '.js'],
|
2024-08-14 23:51:22 +00:00
|
|
|
extensionAlias: { '.js': ['.ts', '.js'] },
|
2021-04-16 08:33:10 +00:00
|
|
|
},
|
2021-05-10 18:50:39 +00:00
|
|
|
plugins: [
|
2024-08-14 23:51:22 +00:00
|
|
|
new webpack.WatchIgnorePlugin({ paths: [/\.js$/, /\.d\.ts$/] }),
|
2023-06-12 19:05:11 +00:00
|
|
|
addCopyrightBannerPlugin(mode, 'common', esVersion),
|
2021-05-10 18:50:39 +00:00
|
|
|
],
|
2021-04-16 08:33:10 +00:00
|
|
|
module: {
|
2024-08-14 23:51:22 +00:00
|
|
|
rules: [
|
|
|
|
|
{
|
|
|
|
|
test: /\.ts$/,
|
|
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'ts-loader',
|
|
|
|
|
options: { compilerOptions: { target: esVersion } },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
2021-04-16 08:33:10 +00:00
|
|
|
},
|
2023-06-12 19:05:11 +00:00
|
|
|
mode,
|
|
|
|
|
devtool,
|
2021-04-16 08:33:10 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-12 19:05:11 +00:00
|
|
|
export default (env, argv) => {
|
2021-04-16 08:33:10 +00:00
|
|
|
return [
|
2024-08-14 23:51:22 +00:00
|
|
|
buildConfig({ suffix: '.es5.min.js', target: 'web', esVersion: 'es5' }),
|
|
|
|
|
buildConfig({ suffix: '.min.js' }),
|
|
|
|
|
buildConfig({ mode: 'development', devtool: 'inline-source-map' }),
|
2023-06-12 19:05:11 +00:00
|
|
|
buildConfig({
|
|
|
|
|
suffix: '.node.cjs',
|
|
|
|
|
target: 'node',
|
|
|
|
|
format: 'commonjs',
|
|
|
|
|
}),
|
2021-04-16 08:33:10 +00:00
|
|
|
];
|
|
|
|
|
};
|