-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.ts
147 lines (133 loc) · 4.42 KB
/
webpack.config.ts
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
import BundleTracker from "webpack-bundle-tracker";
import webpack from "webpack";
import WebpackAssetsManifest from "webpack-assets-manifest";
import path from "path";
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
const OUTPUT_PATH = './dist/';
module.exports = (env: any, argv: any) => {
const PUBLIC_PATH = argv.mode === 'production'
? "https://yoctoproject.github.io/bb-datastore-playground/" : "";
const plugins = [
new WebpackAssetsManifest({
entrypoints: true,
}),
new BundleTracker({path: __dirname, filename: 'webpack-stats.json'}),
];
if (argv.mode !== 'production') {
new webpack.SourceMapDevToolPlugin({
filename: 'sourcemaps/[file].map',
publicPath: PUBLIC_PATH,
});
//plugins.push(new BundleAnalyzerPlugin());
}
return {
context: __dirname,
devtool: "source-map",
entry: {
'main': './src/main/index',
},
optimization: {
splitChunks: {
chunks: "all"
}
},
output: {
path: path.resolve(__dirname, OUTPUT_PATH),
filename: "[name]-[contenthash].js",
chunkFilename: "[name]-[contenthash].js",
publicPath: PUBLIC_PATH,
environment: {
dynamicImport: true,
asyncFunction: true,
},
},
plugins: [
...plugins,
new webpack.ProgressPlugin(),
new HtmlWebpackPlugin({
filename: path.resolve(OUTPUT_PATH, "index.html"),
template: "src/main/index.html.ejs"
}),
new CopyWebpackPlugin({
patterns: [
{from: path.resolve(__dirname, 'assets/'), to: 'assets'},
{from: path.resolve(__dirname, "404.html"), to: ""},
]
}),
],
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.js$|jsx/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.css$/,
use: ["style-loader", 'css-loader', {
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
[
'autoprefixer',
{
// Options for autoprefixer
},
],
],
},
},
}],
},
{
test: /\.s[ac]ss$/i,
use: [
"style-loader",
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
[
'autoprefixer',
{
// Options for autoprefixer
},
],
],
},
},
},
// Compiles Sass to CSS
"sass-loader",
],
},
],
},
resolve: {
modules: ['node_modules'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
'node-fetch': 'isomorphic-fetch',
},
},
mode: "development",
watchOptions: {
aggregateTimeout: 2000,
},
externals: {
pyodide: 'pyodide'
},
devServer: {
historyApiFallback: true,
}
}
}