Skip to content

Commit d759030

Browse files
committed
upgrade to react-script@2
1 parent 2af66b1 commit d759030

File tree

8 files changed

+5373
-2436
lines changed

8 files changed

+5373
-2436
lines changed

package.json

+13-8
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"babel-plugin-transform-decorators-legacy": "^1.3.4",
7-
"monkey-react-scripts": "0.1.1",
8-
"node-sass": "^4.7.2",
6+
"@babel/plugin-proposal-decorators": "^7.1.0",
7+
"monkey-react-scripts": "0.1.2",
8+
"node-sass": "^4.9.3",
99
"postcss-inline-rtl": "^0.9.8",
10-
"react": "^16.2.0",
11-
"react-dom": "^16.2.0",
12-
"react-scripts": "1.1.4",
13-
"sass-loader": "^7.1.0",
10+
"react": "^16.5.2",
11+
"react-dom": "^16.5.2",
12+
"react-scripts": "2.0.3",
1413
"webpack-visualizer-plugin": "^0.1.11"
1514
},
1615
"scripts": {
1716
"start": "monkey-react-scripts start",
1817
"build": "monkey-react-scripts build",
1918
"test": "monkey-react-scripts test --env=jsdom"
20-
}
19+
},
20+
"browserslist": [
21+
">0.2%",
22+
"not dead",
23+
"not ie <= 11",
24+
"not op_mini all"
25+
]
2126
}

src/SampleDecorator.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ function withRedBorder(Cmp) {
1616
}
1717

1818
@withRedBorder
19-
export class Sample extends Component {
19+
class Sample extends Component {
2020
render () {
2121
return (<div>Sample With Decorator</div>)
2222
}
2323
}
2424

2525
Sample.propTypes = {}
26+
27+
export {Sample}

webpack-helpers/babelPatch.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ const {findRule} = require('./utils');
33
module.exports.babelPatch = function babelPatch(webpackConfig, isDevelopment) {
44
// find babel rule
55
const babelRule = findRule(webpackConfig, (rule) => {
6-
return ('' + rule.test === '' + /\.(js|jsx|mjs)$/)
6+
return ('' + rule.test === '' + /\.(js|jsx)$/)
77
});
88
const plugins = babelRule.options.plugins || [];
9-
babelRule.options.plugins = [...plugins, 'transform-decorators-legacy']
9+
babelRule.options.plugins = [
10+
...plugins,
11+
["@babel/plugin-proposal-decorators", {legacy: true}],
12+
]
1013
};

webpack-helpers/cssPatch.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const {findRules} = require('./utils')
2+
3+
module.exports.cssPatch = function cssPatch(webpackConfig, isDevelopment) {
4+
const cssRules = findRules(webpackConfig, (rule) => {
5+
return (
6+
'' + rule.test === '' + /\.css$/ ||
7+
'' + rule.test === '' + /\.module\.css$/ ||
8+
'' + rule.test === '' + /\.(scss|sass)$/ ||
9+
'' + rule.test === '' + /\.module\.(scss|sass)$/
10+
)
11+
});
12+
13+
cssRules.forEach((cssRule) => {
14+
const cssLoaders = isDevelopment ? cssRule.use : cssRule.loader
15+
cssLoaders.forEach((loader) => {
16+
if (loader.options && loader.options.ident === 'postcss') {
17+
const postCssLoader = loader
18+
const postCssFunction = postCssLoader.options.plugins
19+
postCssLoader.options.plugins = () => {
20+
return [...postCssFunction(), require('postcss-inline-rtl')]
21+
}
22+
}
23+
});
24+
});
25+
}

webpack-helpers/sassPatch.js

-30
This file was deleted.

webpack-helpers/utils.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
module.exports.findRule = function findRule(webpackConfig, callback) {
2-
const rules = webpackConfig.module.rules[1].oneOf;
2+
const rules = webpackConfig.module.rules[3].oneOf;
33
const index = rules.findIndex(callback);
44
if (index === -1) throw Error('Loader not found');
55
return rules[index]
66
};
77

8-
module.exports.addRule = function addRule (webpackConfig, rule) {
8+
module.exports.findRules = function findRule(webpackConfig, callback) {
9+
const rules = webpackConfig.module.rules[3].oneOf;
10+
return rules.filter(callback);
11+
};
12+
13+
module.exports.addRule = function addRule(webpackConfig, rule) {
914
const rules = webpackConfig.module.rules[1].oneOf
1015
rules.splice(rules.length - 1, 0, rule) // add before exclude rule
1116
}

webpack.monkey.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const {pluginsPatch} = require('./webpack-helpers/pluginsPatch');
22
const {babelPatch} = require('./webpack-helpers/babelPatch');
3-
const {sassPatch} = require('./webpack-helpers/sassPatch');
3+
const {cssPatch} = require('./webpack-helpers/cssPatch');
44

55
module.exports = function (webpackConfig, isDevelopment) {
66
pluginsPatch(webpackConfig, isDevelopment)
77
babelPatch(webpackConfig, isDevelopment)
8-
sassPatch(webpackConfig, isDevelopment)
8+
cssPatch(webpackConfig, isDevelopment)
99
};

0 commit comments

Comments
 (0)