Skip to content

Commit 6425de2

Browse files
committed
Misc fixes
This version allows to compile dependent code, but HMR does not work, local module linking does not work, and some optimizations do not work.
1 parent 76d8c39 commit 6425de2

File tree

5 files changed

+83
-14
lines changed

5 files changed

+83
-14
lines changed

config/babel/webpack.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
const _ = require('lodash');
44

5-
const reactCssModulesPluginOps = {
6-
filetypes: {
7-
'.scss': {
8-
syntax: 'postcss-scss',
9-
},
10-
},
11-
};
12-
135
const config = {
146
presets: [
157
'@babel/env',
@@ -26,22 +18,35 @@ const config = {
2618
'@babel/syntax-dynamic-import',
2719
'inline-react-svg',
2820
'@babel/transform-runtime',
29-
['react-css-modules', reactCssModulesPluginOps],
21+
['react-css-modules', {
22+
filetypes: {
23+
'.scss': {
24+
syntax: 'postcss-scss',
25+
},
26+
},
27+
}],
3028
],
3129
};
3230

3331
function getPreset(babel) {
32+
const res = _.cloneDeep(config);
33+
34+
const reactCssModulePluginOptions = res.plugins.find(
35+
([name]) => name === 'react-css-modules',
36+
)[1];
37+
3438
switch (babel.getEnv()) {
3539
case 'development':
36-
reactCssModulesPluginOps.generateScopedName = '[path][name]___[local]___[hash:base64:6]';
37-
config.plugins.push('react-hot-loader/babel');
40+
reactCssModulePluginOptions
41+
.generateScopedName = '[path][name]___[local]___[hash:base64:6]';
42+
res.plugins.push('react-hot-loader/babel');
3843
break;
3944
case 'production':
40-
reactCssModulesPluginOps.generateScopedName = '[hash:base64:6]';
45+
reactCssModulePluginOptions.generateScopedName = '[hash:base64:6]';
4146
break;
4247
default:
4348
}
44-
return _.cloneDeep(config);
49+
return res;
4550
}
4651

4752
module.exports = getPreset;

config/jest/default.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
const path = require('path');
2+
3+
const globalLibDir = path.resolve(process.execPath, '../../lib/node_modules');
4+
15
module.exports = {
26
collectCoverage: true,
37
collectCoverageFrom: [
48
'src/**/*.{js,jsx}',
59
],
610
coverageDirectory: '__coverage__',
11+
moduleDirectories: [
12+
'node_modules',
13+
globalLibDir,
14+
],
715
moduleNameMapper: {
816
'\\.(scss|css)$': 'identity-obj-proxy',
917
},

config/webpack/app-base.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module.exports = function configFactory(ops) {
9494
}
9595

9696
entry.polyfills = _.union(entry.polyfills, [
97-
'babel-polyfill',
97+
'@babel/polyfill',
9898
'nodelist-foreach-polyfill',
9999
]);
100100

@@ -168,6 +168,7 @@ module.exports = function configFactory(ops) {
168168
loader: 'babel-loader',
169169
options: {
170170
babelrc: false,
171+
configFile: false,
171172
envName: o.babelEnv,
172173
presets: ['topcoder-react-utils/config/babel/webpack'],
173174
},

package-lock.json

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@babel/polyfill": "^7.2.3",
5050
"@babel/preset-env": "^7.2.3",
5151
"@babel/preset-react": "^7.0.0",
52+
"@babel/register": "^7.0.0",
5253
"autoprefixer": "^9.4.3",
5354
"babel-core": "^7.0.0-bridge.0",
5455
"babel-eslint": "^10.0.1",

0 commit comments

Comments
 (0)