forked from joule-labs/webln-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
103 lines (98 loc) · 2.25 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
const path = require('path');
const webpack = require('webpack');
// webpack plugins
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const isDev = process.env.NODE_ENV !== 'production';
const src = path.join(__dirname, 'src');
const dist = path.join(__dirname, 'dist');
const staticDir = path.join(__dirname, 'static');
const typescriptLoader = {
test: /\.tsx?$/,
use: [
{
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-class-properties',
],
presets: [
'@babel/react',
['@babel/env', {
useBuiltIns: 'entry',
corejs: 2,
}],
],
},
},
{
loader: 'ts-loader',
options: { transpileOnly: isDev },
},
],
};
const cssLoader = {
test: /\.css$/,
use: [
isDev && 'style-loader',
!isDev && MiniCssExtractPlugin.loader,
'css-loader',
].filter(Boolean),
};
const lessLoader = {
test: /\.less$/,
use: [
...cssLoader.use,
{
loader: 'less-loader',
options: { javascriptEnabled: true },
},
],
};
const markdownLoader = {
test: /\.md$/,
use: ['raw-loader'],
};
module.exports = {
mode: isDev ? 'development' : 'production',
name: 'main',
target: 'web',
devtool: 'cheap-module-inline-source-map',
entry: path.join(src, 'index.tsx'),
output: {
path: dist,
filename: 'script.js',
publicPath: isDev ? '/' : '.',
chunkFilename: isDev ? '[name].chunk.js' : '[name].[chunkhash:8].chunk.js',
},
module: {
rules: [
typescriptLoader,
lessLoader,
cssLoader,
markdownLoader,
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.mjs', '.json'],
modules: [src, path.join(__dirname, 'node_modules')],
},
plugins: [
new MiniCssExtractPlugin({
filename: isDev ? '[name].css' : '[name].[hash:8].css',
}),
new HtmlWebpackPlugin({
template: `${src}/index.html`,
inject: true,
}),
new CopyPlugin([{
from: staticDir,
to: dist,
}, {
from: path.join(__dirname, 'CNAME'),
to: dist,
}]),
],
};