[js/web] fix webpack config for onnxruntime-web (#7785)

* fix webpack config for onnxruntime-web

* fix regex of .worker.js file

* fix regex

* fix for testrunner

* fix require('..') in test-main
This commit is contained in:
Yulong Wang 2021-05-21 19:18:22 -07:00 committed by GitHub
parent ee29330cab
commit 21ff8fabe9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 18 deletions

View file

@ -73,12 +73,5 @@
"jsdelivr": "dist/ort.min.js",
"unpkg": "dist/ort.min.js",
"module": "./lib/index.js",
"browser": {
"fs": false,
"path": false,
"util": false,
"worker_threads": false,
"perf_hooks": false,
"os": false
}
"browser": "dist/ort-web.min.js"
}

View file

@ -43,7 +43,20 @@ function buildConfig({ filename, format, target, mode, devtool }) {
type: format
}
},
resolve: { extensions: ['.ts', '.js'] },
resolve: {
extensions: ['.ts', '.js'],
alias: {
"util": false,
},
fallback: {
"fs": false,
"path": false,
"util": false,
"os": false,
"worker_threads": false,
"perf_hooks": false,
}
},
plugins: [new webpack.WatchIgnorePlugin({ paths: [/\.js$/, /\.d\.ts$/] })],
module: {
rules: [{
@ -57,7 +70,7 @@ function buildConfig({ filename, format, target, mode, devtool }) {
}
]
}, {
test: /\.worker.js$/,
test: /ort-wasm.*\.worker\.js$/,
type: 'asset/source'
}]
},
@ -66,10 +79,9 @@ function buildConfig({ filename, format, target, mode, devtool }) {
};
if (mode === 'production') {
config.resolve.alias = {
'./binding/ort-wasm-threaded.js': './binding/ort-wasm-threaded.min.js',
'./binding/ort-wasm-threaded.worker.js': './binding/ort-wasm-threaded.min.worker.js'
};
config.resolve.alias['./binding/ort-wasm-threaded.js'] = './binding/ort-wasm-threaded.min.js';
config.resolve.alias['./binding/ort-wasm-threaded.worker.js'] = './binding/ort-wasm-threaded.min.worker.js';
const options = defaultTerserPluginOptions();
options.terserOptions.format.preamble = COPYRIGHT_BANNER;
config.plugins.push(new TerserPlugin(options));
@ -90,8 +102,6 @@ function buildOrtConfig({
const config = buildConfig({ filename: `ort${suffix}.js`, format: 'umd', target, mode, devtool });
// set global name 'ort'
config.output.library.name = 'ort';
// do not use those node builtin modules in browser
config.resolve.fallback = { path: false, fs: false, util: false };
return config;
}
@ -150,8 +160,11 @@ function buildTestRunnerConfig({
'../../node': '../../node'
},
resolve: {
alias: {
// make sure to refer to original source files instead of generated bundle in test-main.
'..$': '../lib/index'
},
extensions: ['.ts', '.js'],
aliasFields: [],
fallback: {
'./binding/ort-wasm.js': false,
'./binding/ort-wasm-threaded.js': false,
@ -174,7 +187,7 @@ function buildTestRunnerConfig({
}
]
}, {
test: /\.worker\.js$/,
test: /ort-wasm.*\.worker\.js$/,
type: 'asset/source'
}]
},