-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathwebpack.themes.config.js
More file actions
106 lines (92 loc) · 2.46 KB
/
webpack.themes.config.js
File metadata and controls
106 lines (92 loc) · 2.46 KB
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
// webpack.themes.config.js
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const THEME_ENV_KEY = 'AWESOME_THEME';
const themeName = process.env[THEME_ENV_KEY];
if (!themeName || !String(themeName).trim()) {
throw new Error(
`[webpack.themes.config] Missing ${THEME_ENV_KEY} env var. Example: ${THEME_ENV_KEY}=theme-blue`
);
}
const theme = String(themeName).trim();
const format = String(process.env.AWESOME_THEME_FORMAT || 'esm').toLowerCase();
const isEsm = format === 'esm';
module.exports = {
mode: 'production',
target: isEsm ? ['web', 'es2020'] : 'node',
// ✅ needed for output.module / library.type='module'
experiments: isEsm ? { outputModule: true } : undefined,
entry: {
styles: [path.resolve(__dirname, `src/styles/themes/${theme}/index.ts`)],
},
output: {
path: path.resolve(__dirname, 'dist/themes'),
filename: `${theme}.${isEsm ? 'mjs' : 'js'}`,
clean: false,
globalObject: 'this',
...(isEsm
? {
module: true,
library: { type: 'module' },
}
: {
library: { type: 'commonjs2', export: 'default' },
}),
},
optimization: { sideEffects: false },
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: { loader: 'ts-loader', options: { transpileOnly: true } },
},
{
test: /\.scss$/i,
sideEffects: true,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 2,
esModule: true,
modules: {
auto: /\.module\.scss$/i,
exportLocalsConvention: 'asIs',
},
},
},
'postcss-loader',
'sass-loader',
],
},
{
test: /\.css$/i,
sideEffects: true,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 1,
esModule: true,
modules: {
auto: /\.module\.css$/i,
exportLocalsConvention: 'asIs',
},
},
},
'postcss-loader',
],
},
],
},
resolve: { extensions: ['.ts', '.tsx', '.js', '.mjs'] },
plugins: [
new MiniCssExtractPlugin({
filename: `${theme}.css`,
}),
],
stats: 'errors-warnings',
};