-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.ts
100 lines (94 loc) · 3.22 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
// This webpack builds the examples, the library dist files are built with tsc
import path from 'path';
import webpack, {Configuration} from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import {TsconfigPathsPlugin} from 'tsconfig-paths-webpack-plugin';
import * as React from 'react';
const webpackConfig = (env): Configuration => {
let reactMajorVersion = +React.version.split('.')[0];
if (reactMajorVersion >= 18) {
console.log('React 18 detected');
} else {
console.log('React 16/17 detected');
}
const conf: Configuration = {
entry: reactMajorVersion >= 18 ? './examples/index-react18.tsx' : './examples/index.tsx',
...(env.production || !env.development ? {} : {devtool: 'eval-source-map'}),
resolve: {
alias: {
'react-edit-list': path.resolve(__dirname, 'src')
},
extensions: ['.ts', '.tsx', '.js'],
//TODO waiting on https://github.com/dividab/tsconfig-paths-webpack-plugin/issues/61
//@ts-ignore
plugins: [new TsconfigPathsPlugin()]
},
output: {
path: path.join(__dirname, '/docs'),
filename: 'bundle.js'
},
// https://github.com/TypeStrong/ts-loader/issues/751
ignoreWarnings: [{message: /export .* was not found in/}],
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
transpileOnly: true,
configFile: 'examples/tsconfig.json'
}
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
},
{
test: /\.svg$/,
loader: 'svg-url-loader'
},
{
test: /\.md$/,
use: ['html-loader', 'markdown-loader']
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './examples/index.html'
}),
new webpack.DefinePlugin({
process: {
env: {
DEBUG: !env.production || env.development
}
},
VERSION: JSON.stringify(require('./package.json').version),
MAPBOX_TOKEN: JSON.stringify(process.env.MAPBOX_TOKEN)
})
],
devServer: {
port: 8030
}
};
if (reactMajorVersion < 18) {
// This is needed for React 16/17 as otherwise ts-loader
// will pick `index-react18.tsx` and will fail transpiling it
conf.module.rules.unshift({
test: /index-react18\.tsx?$/,
loader: 'null-loader'
});
}
if (!env.development) {
conf.plugins.push(
new ForkTsCheckerWebpackPlugin({
eslint: {
files: './{src,examples}/**/*.{ts,tsx,js}'
}
})
);
}
return conf;
};
export default webpackConfig;