This repository has been archived by the owner on Jan 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.js
97 lines (94 loc) · 2.54 KB
/
webpack.config.js
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
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const WorkboxPlugin = require('workbox-webpack-plugin')
const path = require('path')
module.exports = env => {
const production = !!(env || {}).production
const cssLoaders = modules => [
production ? MiniCssExtractPlugin.loader : 'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 2,
...(modules
? {
modules: { localIdentName: '[hash:base64:5]' },
localsConvention: 'camelCaseOnly',
}
: {}),
},
},
'postcss-loader',
{
loader: 'sass-loader',
options: {
data: modules && '@import "initialization";',
includePaths: [path.join(__dirname, 'style')],
},
},
]
return {
devServer: {
contentBase: path.join(__dirname, 'public'),
},
devtool: production ? false : 'cheap-module-source-map',
entry: { index: './index.js' },
mode: production ? 'production' : 'development',
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.worker\.[jt]sx?$/,
exclude: /node_modules/,
loader: ['worker-loader', 'babel-loader'],
},
{
test: /\.module\.(sa|sc|c)ss$/,
use: cssLoaders(true),
},
{
test: /\.(sa|sc|c)ss$/,
exclude: /\.module\.(sa|sc|c)ss$/,
use: cssLoaders(false),
},
{
test: /\.(png|gif|jpe?g|svg|woff2?|eot|ttf)$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
name: 'assets/[name].[hash:8].[ext]',
},
},
},
],
},
plugins: [
new MiniCssExtractPlugin(),
production &&
new WorkboxPlugin.GenerateSW({
cacheId: 'marp-web',
globDirectory: production ? './dist' : './public',
globPatterns: ['index.html', '**/*.{png,svg}'],
}),
].filter(p => p),
resolve: {
alias: {
'incremental-dom$': path.resolve(
__dirname,
'node_modules/incremental-dom/dist/incremental-dom-min.js'
),
// Stop bundling a huge and unnecessary esprima module
// https://github.com/nodeca/js-yaml/pull/435
'js-yaml$': path.resolve(
__dirname,
'node_modules/js-yaml/dist/js-yaml.min.js'
),
},
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
}
}