-
Notifications
You must be signed in to change notification settings - Fork 12
/
webpack.config.mjs
164 lines (156 loc) · 3.8 KB
/
webpack.config.mjs
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import path from 'path'
import { createRequire } from 'module'
import webpack from 'webpack'
import { fileURLToPath } from 'url'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
import TerserPlugin from 'terser-webpack-plugin'
import CopyWebpackPlugin from 'copy-webpack-plugin'
const require = createRequire(import.meta.url)
const pkgjson = require('./package.json')
const {
name,
title,
description,
version,
readme,
devDependencies: {
aframe,
},
} = pkgjson
const pkginfo = {
name: name,
title: title,
description: description,
version: version,
readme: readme,
}
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const docsmetaopts = {
...pkginfo,
meta: {
viewport: 'width=device-width, initial-scale=1, maximum-scale=1',
'theme-color': '#373e47',
robots: 'index,follow',
googlebot: 'index,follow',
generator: `${name}-example`,
subject: description,
rating: 'General',
}
}
const examples = [
'entities.html',
'primitives.html',
'primitives-with-multiple-sources.html',
'primitives-using-mediastream.html',
'using-obj-model-as-room.html',
'multiple-rooms.html',
].map(example => {
return new HtmlWebpackPlugin({
inject: false,
...docsmetaopts,
filename: example,
template: path.resolve(__dirname, `./docs/examples/${example}`),
chunks: [
'assets/docscss',
'assets/docsjs',
'aframe-resonance-audio-component',
],
})
})
const pkgconfig = {
mode: 'production',
target: ['web', 'es2020'],
devtool: 'source-map',
entry: {
'aframe-resonance-audio-component': './src/index.js',
'aframe-resonance-audio-component.min': './src/index.js',
'assets/docsjs': './docs/docs.js',
'assets/docscss': './docs/docs.scss',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
resolve: {
extensions: ['.js'],
},
plugins: [
new webpack.ProgressPlugin(),
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [
'dist/**',
'!dist/assets/aframe/**',
'!dist/assets/static/**',
],
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, 'node_modules/aframe/dist/aframe-*'),
to: path.resolve(__dirname, 'dist/assets/aframe/[name][ext]'),
},
{
context: 'docs/static/',
from: './**',
to: 'assets/static/',
}
],
}),
new webpack.DefinePlugin({
pkginfo: (() => {
const defs = {}
Object.keys(pkginfo).forEach(key => {
defs[key] = JSON.stringify(pkginfo[key])
})
return defs
})(),
}),
new HtmlWebpackPlugin({
inject: false,
...docsmetaopts,
filename: 'index.html',
template: path.resolve(__dirname, './docs/index.html'),
chunks: [
'assets/docscss',
'assets/docsjs',
],
}),
...examples,
new HtmlWebpackPlugin({
inject: false,
minify: false,
filename: path.resolve(__dirname, './README.md'),
template: path.resolve(__dirname, './docs/readme.tmpl.md'),
templateParameters: {
version: version,
links: {},
images: {
'aframe-badge': `https://img.shields.io/badge/a--frame-${aframe}-FC3164.svg?style=flat-square`,
},
}
})
],
optimization: {
minimize: true,
minimizer: [new TerserPlugin({
include: /\.min\.js$/,
})],
},
module: {
rules: [
{
test: /\.scss$/i,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
"sass-loader",
],
},
],
},
}
export default pkgconfig