-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathwebpack.scss.config.js
More file actions
110 lines (99 loc) · 2.6 KB
/
Copy pathwebpack.scss.config.js
File metadata and controls
110 lines (99 loc) · 2.6 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
107
108
109
110
// webpack.scss.config.js
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
module.exports = {
mode: 'production',
entry: {
// keep your current entry orchestration
styles: [path.resolve(__dirname, 'src/styles/index.ts')],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js', // dist/styles.js (you already delete it after)
clean: false,
},
// ✅ Critical: don’t let webpack prune "side-effect-only" imports (like SCSS)
optimization: {
sideEffects: false,
},
module: {
rules: [
// JS handling (only needed if your TS entry imports JS)
{
test: /\.(js|jsx|mjs)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: { cacheDirectory: true },
},
},
// TS handling for the entry
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
options: {
// faster + avoids typechecking noise in a pure style build
transpileOnly: true,
},
},
},
// SCSS
{
test: /\.scss$/i,
// ✅ Critical: mark as side-effectful regardless of package.json sideEffects list
sideEffects: true,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 2,
// safe default: only treat *.module.scss as CSS Modules
modules: { auto: /\.module\.scss$/i },
},
},
{
loader: 'postcss-loader',
options: {
// keep it deterministic even without a postcss.config.js
postcssOptions: { plugins: [require('autoprefixer')] },
},
},
'sass-loader',
],
},
// CSS
{
test: /\.css$/i,
sideEffects: true,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: { auto: /\.module\.css$/i },
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: { plugins: [require('autoprefixer')] },
},
},
],
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.scss', '.css'],
},
plugins: [
new MiniCssExtractPlugin({
filename: 'styles.css', // dist/styles.css
}),
],
stats: 'errors-warnings',
};