UNPKG

2.12 kBPlain TextView Raw
1// Copyright (c) Jupyter Development Team.
2// Distributed under the terms of the Modified BSD License.
3import * as webpack from 'webpack';
4import miniSVGDataURI from 'mini-svg-data-uri';
5
6const rules = [
7 { test: /\.raw\.css$/, type: 'asset/source' },
8 { test: /(?<!\.raw)\.css$/, use: ['style-loader', 'css-loader'] },
9 { test: /\.txt$/, type: 'asset/source' },
10 { test: /\.md$/, type: 'asset/source' },
11 { test: /\.(jpg|png|gif)$/, type: 'asset/resource' },
12 { test: /\.js.map$/, type: 'asset/resource' },
13 {
14 test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
15 type: 'asset/resource'
16 },
17 {
18 test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
19 type: 'asset/resource'
20 },
21 {
22 test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
23 type: 'asset/resource'
24 },
25 { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, type: 'asset/resource' },
26 {
27 // In .css files, svg is loaded as a data URI.
28 test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
29 issuer: /\.css$/,
30 type: 'asset',
31 generator: {
32 dataUrl: (content: any) => miniSVGDataURI(content.toString())
33 }
34 },
35 {
36 // In .ts and .tsx files (both of which compile to .js), svg files
37 // must be loaded as a raw string instead of data URIs.
38 test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
39 issuer: /\.js$/,
40 type: 'asset/source'
41 },
42 {
43 test: /\.m?js$/,
44 type: 'javascript/auto'
45 },
46 {
47 test: /\.m?js/,
48 resolve: {
49 fullySpecified: false
50 }
51 },
52 {
53 test: /\.c?js/,
54 resolve: {
55 fullySpecified: false
56 }
57 }
58];
59
60const watch = process.argv.includes('--watch');
61
62module.exports = {
63 bail: !watch,
64 module: { rules },
65 resolve: {
66 fallback: {
67 url: false,
68 buffer: false,
69 crypto: false,
70 // See https://github.com/webpack/webpack/blob/3471c776059ac2d26593ea39f9c47c1874253dbb/lib/ModuleNotFoundError.js#L13-L42
71 path: require.resolve('path-browserify'),
72 process: require.resolve('process/browser')
73 }
74 },
75 watchOptions: {
76 poll: 500,
77 aggregateTimeout: 1000
78 },
79 output: {
80 hashFunction: 'sha256'
81 },
82 plugins: [
83 new webpack.ProvidePlugin({
84 process: 'process/browser'
85 })
86 ]
87};