forked from source-academy/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcraco.config.js
158 lines (148 loc) · 5.48 KB
/
craco.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
// eslint-disable-next-line @typescript-eslint/no-var-requires
const webpack = require('webpack');
const cracoConfig = (module.exports = {
webpack: {
configure: webpackConfig => {
// avoid the entire process.env being inserted into the service worker
// if SW_EXCLUDE_REGEXES is unset
const definePlugin = webpackConfig.plugins.find(
plugin => plugin.constructor.name === 'DefinePlugin'
);
const inlineProcessEnv = definePlugin.definitions['process.env'];
if (!inlineProcessEnv.REACT_APP_SW_EXCLUDE_REGEXES) {
inlineProcessEnv.REACT_APP_SW_EXCLUDE_REGEXES = undefined;
}
const injectManifestPlugin = webpackConfig.plugins.find(
plugin => plugin.constructor.name === 'InjectManifest'
);
if (injectManifestPlugin) {
injectManifestPlugin.config.maximumFileSizeToCacheInBytes = 15 * 1024 * 1024;
}
// add rules to pack WASM (for Sourceror)
const wasmExtensionRegExp = /\.wasm$/;
webpackConfig.resolve.extensions.push('.wasm');
webpackConfig.module.rules.forEach(rule => {
(rule.oneOf || []).forEach(oneOf => {
if (oneOf.type === 'asset/resource') {
oneOf.exclude.push(wasmExtensionRegExp);
}
});
});
// See https://webpack.js.org/configuration/experiments/#experiments.
webpackConfig.experiments = {
syncWebAssembly: true
};
webpackConfig.output.webassemblyModuleFilename = 'static/[hash].module.wasm';
// Polyfill Node.js core modules.
// An empty implementation (false) is provided when there is no browser equivalent.
webpackConfig.resolve.fallback = {
'child_process': false,
'constants': require.resolve('constants-browserify'),
'fs': false,
'http': require.resolve('stream-http'),
'https': require.resolve('https-browserify'),
'os': require.resolve('os-browserify/browser'),
'path/posix': require.resolve('path-browserify'),
'stream': require.resolve('stream-browserify'),
'timers': require.resolve('timers-browserify'),
'url': require.resolve('url/')
};
// workaround .mjs files by Acorn
webpackConfig.module.rules.push({
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
resolve: {
fullySpecified: false
},
});
// Ignore warnings for dependencies that do not ship with a source map.
// This is because we cannot do anything about our dependencies.
webpackConfig.ignoreWarnings = [{
module: /node_modules/,
message: /Failed to parse source map/
}];
webpackConfig.plugins = [
...webpackConfig.plugins,
// Make environment variables available in the browser by polyfilling the 'process' Node.js module.
new webpack.ProvidePlugin({
process: 'process/browser',
}),
// Make the 'buffer' Node.js module available in the browser.
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
})
];
// Workaround to suppress warnings caused by ts-morph in js-slang
webpackConfig.module.noParse = /node_modules\/@ts-morph\/common\/dist\/typescript\.js$/;
return webpackConfig;
}
},
jest: {
configure: jestConfig => {
jestConfig.transformIgnorePatterns = [
// Will give something like
// '[/\\\\]node_modules[/\\\\]
// (?!
// ( @ion-phaser[/\\\\]react[/\\\\.*] )|
// ( js-slang[/\\\\.*] )|
// ( array-move[/\\\\.*] )|
// ...
// ( comma-separated-tokens[/\\\\.*] )
// ).*.(js|jsx|ts|tsx)$'
ignoreModulePaths(
'@ion-phaser/react',
'js-slang',
'array-move',
'konva',
'react-konva',
'react-debounce-render',
'devlop',
'hastscript',
'hast-to-hyperscript',
'hast-util-.+',
'mdast-util-.+',
'micromark',
'micromark-.+',
'vfile',
'vfile-message',
'unist-util-.+',
'web-namespaces',
'rehype-react',
'unified',
'bail',
'is-plain-obj',
'trough',
'decode-named-character-reference',
'character-entities',
'trim-lines',
'property-information',
'space-separated-tokens',
'comma-separated-tokens'
),
'^.+\\.module\\.(css|sass|scss)$'
];
jestConfig.moduleNameMapper['ace-builds'] = '<rootDir>/node_modules/ace-builds';
jestConfig.moduleNameMapper['unist-util-visit-parents/do-not-use-color'] =
'<rootDir>/node_modules/unist-util-visit-parents/lib';
jestConfig.moduleNameMapper['vfile/do-not-use-conditional-minpath'] =
'<rootDir>/node_modules/vfile/lib';
jestConfig.moduleNameMapper['vfile/do-not-use-conditional-minproc'] =
'<rootDir>/node_modules/vfile/lib';
jestConfig.moduleNameMapper['vfile/do-not-use-conditional-minurl'] =
'<rootDir>/node_modules/vfile/lib';
return jestConfig;
}
}
});
const ignoreModulePaths = (...paths) => {
const moduleRoot = replaceSlashes('/node_modules/');
const modulePaths = paths
.map(replaceSlashes)
.map(path => `(${path}[/\\\\.*])`)
.join('|');
return moduleRoot + '(?!' + modulePaths + ').*.(js|jsx|ts|tsx)$';
};
const replaceSlashes = target => {
return target.replaceAll('/', '[/\\\\]');
};