-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.config.js
97 lines (90 loc) · 2.87 KB
/
webpack.config.js
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
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const pack = require('./package.json');
module.exports = (env, argv) => ({
entry: './src/main.ts',
mode: argv.mode == 'development' ? 'development' : 'production',
devtool: argv.mode == 'development' ? 'source-map' : undefined,
output: {
filename: !env.minimize ? 'encantar.js' : 'encantar.min.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist/',
library: {
name: 'AR',
type: 'umd',
export: 'default',
},
},
resolve: {
extensions: [ '.ts', '.js' ],
symlinks: false,
modules: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, '../node_modules'),
'node_modules',
],
},
plugins: [
new webpack.BannerPlugin({
banner: ((({ author, version, year, homepage, description, date }) => ([
`encantar.js version ${version}`,
`${description}`,
`Copyright ${year} ${author}`,
`${homepage}`,
``,
`@license LGPL-3.0-or-later`,
`Date: ${date}`,
].join('\n')))({
...pack,
'date': new Date().toISOString(),
'year': [2022, new Date().getFullYear()].join('-'),
'author': pack.author.replace('@', '(at)'),
}))
}),
new webpack.DefinePlugin({
'__AR_VERSION__': JSON.stringify(pack.version),
'__AR_DEVELOPMENT_MODE__': argv.mode == 'development',
'__AR_WEBSITE__': JSON.stringify(pack.homepage),
}),
new webpack.IgnorePlugin({
resourceRegExp: /\.ignore\./i,
}),
],
module: {
rules: [{
test: /\.ts$/,
include: path.resolve(__dirname, 'src'),
exclude: /node_modules/,
use: [{
loader: 'ts-loader',
options: {
// improve the build time when using the dev server
transpileOnly: env.PORT !== undefined,
},
}],
}],
},
devServer: {
server: 'https',
host: env.HOST || '0.0.0.0',
port: env.PORT || 8000,
static: ['demos', 'plugins', 'tests'].map(dir => ({
directory: path.resolve(__dirname, dir),
publicPath: `/${dir}/`,
})),
//host: '0.0.0.0',
//host: 'local-ip',
},
optimization: !env.minimize ? { minimize: false } : {
minimize: true,
minimizer: [new TerserPlugin({
terserOptions: {
format: {
comments: /@license/i,
},
},
extractComments: false,
})],
},
});