-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
57 lines (57 loc) · 1.96 KB
/
webpack.config.js
File metadata and controls
57 lines (57 loc) · 1.96 KB
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
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
/**
* @type {import("webpack").Configuration}
*/
module.exports = {
//tell webpack where to look for source files
context: path.resolve(__dirname, 'src'),
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
}),
],
entry: {
//each entrypoint results in an output file
//so this results in an output file called 'main.js' which is built from src/index.ts
main: './index.ts',
},
output: {
path: path.resolve(__dirname, 'dist'),
// library means that the exports from the entry file can be accessed from outside, in this case from the global scope as window.TestApp
library: { type: 'umd', name: 'Alt1Libs' },
},
devtool: 'source-map',
mode: 'development',
// prevent webpack from bundling these imports (alt1 libs can use them when running in nodejs)
externals: ['sharp', 'canvas', 'electron/common'],
resolve: {
extensions: ['.wasm', '.tsx', '.ts', '.mjs', '.jsx', '.js'],
},
module: {
// The rules section tells webpack what to do with different file types when you import them from js/ts
rules: [
{ test: /\.tsx?$/, loader: 'ts-loader' },
{ test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] },
{ test: /\.scss$/, use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'] },
// type:"asset" means that webpack copies the file and gives you an url to them when you import them from js
{
test: /\.(png|jpg|jpeg|gif|webp)$/,
type: 'asset/resource',
generator: { filename: '[base]' },
},
{
test: /\.(html|json)$/,
type: 'asset/resource',
generator: { filename: '[base]' },
},
// file types useful for writing alt1 apps, make sure these two loader come after any other json or png loaders, otherwise they will be ignored
{
test: /\.data\.png$/,
loader: 'alt1/imagedata-loader',
type: 'javascript/auto',
},
{ test: /\.fontmeta.json/, loader: 'alt1/font-loader' },
],
},
};