-
Notifications
You must be signed in to change notification settings - Fork 45
/
rspack.config.cosmos.js
104 lines (100 loc) · 2.79 KB
/
rspack.config.cosmos.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
import rspack from '@rspack/core';
import { createRequire } from 'node:module';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
const require = createRequire(import.meta.url);
const pjson = require('./package.json');
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// This separate rspack config is needed because react-cosmos doesn't support
// rspack configurations that export multiple configurations:
//
// https://webpack.js.org/configuration/configuration-types/#exporting-multiple-configurations
const config = {
mode: 'development',
module: {
rules: [
{
test: /\.css$/,
use: [
{ loader: rspack.CssExtractRspackPlugin.loader },
{
loader: 'css-loader',
options: { url: false, sourceMap: false },
},
'postcss-loader',
],
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: 'builtin:swc-loader',
/** @type {import('@rspack/core').SwcLoaderOptions} */
options: {
sourceMap: true,
jsc: {
parser: { syntax: 'typescript' },
target: 'es2020',
},
},
},
type: 'javascript/auto',
},
{
test: /\.tsx$/,
exclude: /node_modules/,
use: {
loader: 'builtin:swc-loader',
/** @type {import('@rspack/core').SwcLoaderOptions} */
options: {
sourceMap: true,
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
},
transform: {
react: {
runtime: 'automatic',
throwIfNamespace: true,
useBuiltins: true,
},
},
target: 'es2020',
},
},
},
type: 'javascript/auto',
},
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
],
},
resolve: {
alias: {
react: 'preact/compat',
'react-dom/test-utils': 'preact/test-utils',
'react-dom': 'preact/compat',
},
extensions: ['.ts', '.tsx', '.js'],
},
plugins: [
new rspack.DefinePlugin({
__ACTIVE_TAB_ONLY__: false,
__SUPPORTS_SVG_ICONS__: false,
__SUPPORTS_TAB_CONTEXT_TYPE__: false,
__VERSION__: `'${pjson.version}'`,
}),
new rspack.NormalModuleReplacementPlugin(
/\/i18n$/,
path.resolve(__dirname, 'src', 'common', 'i18n.polyfill.tsx')
),
new rspack.HtmlRspackPlugin({
template: './src/options/options.html',
}),
new rspack.CssExtractRspackPlugin(),
new rspack.CopyRspackPlugin({
patterns: ['css/*', 'fonts/*', 'images/*'],
}),
],
};
export default config;