-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
167 lines (161 loc) · 3.68 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const path = require("path");
const webpack = require("webpack");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const merge = require("webpack-merge");
// Custom PurgeCSS extractor for Tailwind that allows special characters in
// class names.
//
// https://github.com/FullHuman/purgecss#extractor
class TailwindExtractor {
static extract(content) {
return content.match(/[A-Za-z0-9-_:\/]+/g) || [];
}
}
module.exports = env => {
switch (env) {
case "build":
return merge(commonConfig(), buildConfig());
case "interactive":
return merge(commonConfig(), interactiveConfig());
case "start":
default:
return merge(commonConfig(), developmentConfig());
}
};
function commonConfig() {
return {
stats: "minimal",
module: {
rules: [
{
test: /(\.bs|re\.)?\.js$/,
use: "babel-loader",
include: [
path.join(__dirname, "components"),
path.join(__dirname, "layouts"),
path.join(__dirname, "pages"),
path.join(__dirname, "data")
]
},
{
test: /\.woff(2)?|\.ttf$|\.eot$/,
use: [
{
loader: "url-loader",
options: {
limit: 5000
}
}
]
},
{
test: /\.gif$/,
use: "file-loader"
},
{
test: /\.jpg$/,
use: "file-loader"
},
{
test: /\.png$/,
use: "file-loader"
},
{
test: /\.svg$/,
use: "file-loader"
},
{
test: /\.txt$/,
use: "raw-loader"
},
{
test: /.mdx?$/,
use: ["babel-loader", "@mdx-js/loader"]
},
{
test: /\.md$/,
use: "raw-loader"
},
{
// Prevent webpack from interpreting Reason files
test: /.re$/,
loader: "./scripts/ignore-loader"
}
]
},
resolve: {
alias: {
assets: path.resolve(__dirname, "assets"),
config: path.resolve(__dirname, "antwar.config.js"),
components: path.resolve(__dirname, "components"),
utils: path.resolve(__dirname, "utils")
}
}
};
}
function interactiveConfig() {
return {
module: {
rules: [
{
test: /\.css$/,
include: [path.resolve(__dirname, "styles")],
use: ExtractTextPlugin.extract({
use: ["css-loader", "postcss-loader"],
fallback: "style-loader"
})
}
],
},
// resolve: {
// alias: {
// react: "preact-compat/dist/preact-compat.min.js",
// "react-dom": "preact-compat/dist/preact-compat.min.js"
// }
// },
plugins: [
new ExtractTextPlugin({
filename: "[name].[chunkhash].css",
allChunks: true
})
]
};
}
function developmentConfig() {
return {
module: {
rules: [
{
test: /\.css$/,
include: [path.resolve(__dirname, "styles")],
use: ["style-loader", "css-loader", "postcss-loader"]
}
]
}
};
}
function buildConfig() {
return {
module: {
rules: [
{
test: /\.css$/,
include: [path.resolve(__dirname, "styles")],
use: ExtractTextPlugin.extract({
use: ["css-loader", "postcss-loader"],
fallback: "style-loader"
})
}
]
},
plugins: [
new ExtractTextPlugin({
filename: "[name].[chunkhash].css",
allChunks: true
}),
//new webpack.DefinePlugin({
//window: `false`
//})
]
};
}