forked from cytoscape/cytoscape-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
71 lines (70 loc) · 1.99 KB
/
webpack.config.js
File metadata and controls
71 lines (70 loc) · 1.99 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const ESLintPlugin = require('eslint-webpack-plugin')
module.exports = {
entry: './src/index.tsx',
devtool: 'inline-source-map',
module: {
rules: [
// look for tsx files to transform into the bundle
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
// look for css files to transform into the bundle
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
// load all other assets using webpacks default loader
{
test: /\.(png|jpg|jpeg|gif|svg)$/i,
type: 'asset/resource',
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx'], // need .js and .jsx for dependency files
},
// use content hash for cache busting
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
clean: true,
},
// watch the dist file for changes when using the dev server
devServer: {
static: './dist',
},
plugins: [
// generate css files from the found css files in the source
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
}),
// generate html that points to the bundle with the updated hash
new HtmlWebpackPlugin({
template: './index.html',
}),
// lint all js/jsx/ts/tsx files
new ESLintPlugin({
extensions: ['ts', 'tsx'],
}),
],
// split bundle into two chunks, node modules(vendor code) in one bundle and app source code in the other
// when source code changes, only the source code bundle will need to be updated, not the vendor code
optimization: {
moduleIds: 'deterministic',
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
}