forked from InsightSoftwareConsortium/itk-wasm
/
webpack.config.cjs
114 lines (106 loc) · 2.89 KB
/
webpack.config.cjs
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
const path = require('path')
const webpack = require('webpack')
const ResolveTypeScriptPlugin = require("resolve-typescript-plugin")
const { config } = require('process')
const WebPackBar = require('webpackbar')
const entry = path.join(__dirname, 'src', 'browser', 'index.ts')
const outputPath = path.join(__dirname, 'dist', 'umd')
const configDevelopment = path.resolve(__dirname, 'dist', 'itkConfigDevelopment.js')
const configProduction = path.resolve(__dirname, 'dist', 'itkConfig.js')
const configDevServer = path.resolve(__dirname, 'src', 'itkConfigDevServer.js')
const library = {
type: 'umd',
name: 'itk'
}
const moduleConfig = {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: { presets: ['@babel/preset-env'] }
}
},
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
]
}
const fallback = { fs: false, path: false, url: false, module: false }
const modules = [path.resolve(__dirname, 'node_modules')]
const performance = {
maxAssetSize: 10000000
}
const stats = 'errors-only'
const devServer = {
port: 8083,
devMiddleware: {
writeToDisk: true,
},
static: [
{
publicPath: '/test-data',
directory: path.join(__dirname, 'build-emscripten', 'ExternalData', 'test', 'Input'),
staticOptions: {
dotfiles: 'allow',
},
},
{
publicPath: '/web-workers',
directory: path.join(__dirname, 'dist', 'web-workers'),
},
{
publicPath: '/image-io',
directory: path.join(__dirname, 'dist', 'image-io'),
},
{
publicPath: '/mesh-io',
directory: path.join(__dirname, 'dist', 'mesh-io'),
},
{
publicPath: '/pipelines',
directory: path.join(__dirname, 'dist', 'pipelines'),
},
{
publicPath: '/',
directory: path.join(__dirname, 'dist', 'umd'),
staticOptions: {
dotfiles: 'allow',
},
},
],
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
},
}
module.exports = (env, argv) => [
{
name: 'development',
mode: 'development',
stats,
entry,
output: {
path: outputPath,
filename: argv.mode === 'development' ? 'itk-wasm.js' : 'itk-wasm.min.js',
library
},
module: moduleConfig,
resolve: {
modules,
fallback,
alias: {
'../itkConfig.js': argv.mode === 'development' ? env.DEVSERVER ? configDevServer : configDevelopment : configProduction,
'../../itkConfig.js': argv.mode === 'development' ? env.DEVSERVER ? configDevServer : configDevelopment : configProduction,
},
plugins: [new ResolveTypeScriptPlugin()],
},
performance,
plugins: [new WebPackBar(),],
devtool: argv.mode === 'development' ? 'eval-cheap-module-source-map' : 'source-map',
devServer,
},
]