Skip to content

Commit 6455421

Browse files
committed
update app-rewire, update repository url to jsdevkr
1 parent 89f1b86 commit 6455421

16 files changed

+287
-170
lines changed

config-overrides.js

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
1-
const rewireReactHotLoader = require('react-app-rewire-hot-loader');
2-
const overrideTsLoader = require('./react-app-rewire-typescript-hmr');
3-
const rewireCssModules = require('react-app-rewire-css-modules');
4-
const rewireLess = require('react-app-rewire-less');
5-
const path = require('path');
1+
const overrideJsTsLoader = require('./react-app-rewire-js-ts');
2+
const rewireCssModules = require('./react-app-rewire-css');
63

74
/* config-overrides.js */
85
module.exports = function override(config, env) {
9-
if (env === 'development') {
10-
// (config, env)
11-
config = rewireReactHotLoader(config, env);
6+
// (config, env, babelPlugins = [])
7+
config = overrideJsTsLoader(config, env);
128

13-
// (config, env, babelPlugins = [])
14-
config = overrideTsLoader(config, env);
15-
}
9+
// polyfills
10+
config.entry = ['babel-polyfill', ...config.entry];
1611

17-
// sass-loader
12+
// css, sass, less
1813
config = rewireCssModules(config, env);
1914

20-
// less-loader
21-
config = rewireLess.withLoaderOptions({
22-
javascriptEnabled: true,
23-
// less 구문중에 inline javascript로 처리 되는 구문이 있어 옵션 추가
24-
// 그렇지 않으면 https://github.com/ant-design/ant-motion/issues/44 이와 같은 오류가 발생됨.
25-
})(config, env);
15+
// ForkTsCheckerWebpackPlugin overide
16+
config.plugins.forEach((plugin, idx) => {
17+
try {
18+
const objectName = plugin.constructor.name;
19+
if (objectName === 'ForkTsCheckerWebpackPlugin') {
20+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
21+
config.plugins[idx] = new ForkTsCheckerWebpackPlugin({
22+
...plugin.options,
23+
workers: ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE,
24+
memoryLimit: 2048,
25+
});
26+
}
27+
} catch (error) {}
28+
});
29+
30+
// webpack-bundle-analyzer
31+
if (process.env.WEBPACK_ANALYZER) {
32+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
33+
.BundleAnalyzerPlugin;
34+
config.plugins.push(new BundleAnalyzerPlugin());
35+
}
2636

2737
return config;
2838
};

dist/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
"description": "DataGrid, DataSheet for React",
55
"jsnext:main": "es6/index.js",
66
"main": "commonjs/index.js",
7-
"repository": "https://github.com/axui/datagrid",
7+
"repository": "https://github.com/jsdevkr/datagrid",
88
"website": "http://axui-datagrid.axisj.com/",
99
"author": "tom@axisj.com",
1010
"license": "MIT",
11-
"keywords": [
12-
"datagrid, react-datagrid, react-component, typescript"
13-
],
11+
"keywords": ["datagrid, react-datagrid, react-component, typescript"],
1412
"peerDependencies": {
1513
"react": "^16.4.0",
1614
"react-dom": "^16.4.0"

package.json

+22-32
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
"description": "",
55
"jsnext:main": "dist/es6/index.js",
66
"main": "dist/commonjs/index.js",
7-
"repository": "https://github.com/axui/datagrid",
7+
"repository": "https://github.com/jsdevkr/datagrid",
88
"website": "http://axui-datagrid.axisj.com/",
99
"author": "tom@axisj.com",
1010
"license": "MIT",
11-
"keywords": [
12-
"datagrid, react-datagrid, react-component, typescript"
13-
],
11+
"keywords": ["datagrid, react-datagrid, react-component, typescript"],
1412
"dependencies": {},
1513
"devDependencies": {
1614
"@types/jest": "^22.2.2",
@@ -27,12 +25,16 @@
2725
"enzyme": "^3.3.0",
2826
"enzyme-adapter-react-16": "^1.1.1",
2927
"file-loader": "^1.1.11",
28+
"history": "^4.7.2",
29+
"babel-polyfill": "^6.26.0",
30+
"babel-preset-env": "^1.7.0",
3031
"less": "^3.5.3",
3132
"less-loader": "^4.1.0",
3233
"node-sass": "^4.8.3",
3334
"raw-loader": "^0.5.1",
3435
"react": "^16.4.0",
35-
"react-app-rewire-css-modules": "github:codebandits/react-app-rewire-css-modules",
36+
"react-app-rewire-css-modules":
37+
"github:codebandits/react-app-rewire-css-modules",
3638
"react-app-rewire-hot-loader": "^1.0.1",
3739
"react-app-rewire-less": "^2.1.2",
3840
"react-app-rewired": "^1.5.0",
@@ -54,17 +56,22 @@
5456
},
5557
"scripts": {
5658
"start": "react-app-rewired start --scripts-version react-scripts-ts",
57-
"build": "better-npm-run build:common && better-npm-run build:es5 && better-npm-run build:es6",
58-
"docs": "react-app-rewired build --scripts-version react-scripts-ts && rm -rf ./docs && mv build ./docs && cp ./src/CNAME ./docs/CNAME && cp ./src/404.html ./docs/404.html && git add -A",
59+
"build":
60+
"better-npm-run build:common && better-npm-run build:es5 && better-npm-run build:es6",
61+
"docs":
62+
"react-app-rewired build --scripts-version react-scripts-ts && rm -rf ./docs && mv build ./docs && cp ./src/CNAME ./docs/CNAME && cp ./src/404.html ./docs/404.html && git add -A",
5963
"test": "NODE_ENV=test jest",
6064
"test-watch": "NODE_ENV=test jest --watch",
6165
"tslint-check": "tslint-config-prettier-check ./tslint.json",
6266
"prepublish": "npm run test",
63-
"publish-by-patch": "cd dist && npm version patch && cp ./package.json ../src/package.json && cd .. && npm run docs",
64-
"publish-by-minor": "cd dist && npm version minor && cp ./package.json ../src/package.json && cd .. && npm run docs"
67+
"publish-by-patch":
68+
"cd dist && npm version patch && cp ./package.json ../src/package.json && cd .. && npm run docs",
69+
"publish-by-minor":
70+
"cd dist && npm version minor && cp ./package.json ../src/package.json && cd .. && npm run docs"
6571
},
6672
"betterScripts": {
67-
"build:common": "node-sass ./src/axui-datagrid/style.scss dist/style.css --output-style compressed && cp ./src/axui-datagrid/style.scss ./dist/style.scss && cp -R ./src/axui-datagrid/scss ./dist/scss && cp ./README.md ./dist/README.md",
73+
"build:common":
74+
"node-sass ./src/axui-datagrid/style.scss dist/style.css --output-style compressed && cp ./src/axui-datagrid/style.scss ./dist/style.scss && cp -R ./src/axui-datagrid/scss ./dist/scss && cp ./README.md ./dist/README.md",
6875
"build:es5": "rm -rf ./dist/commonjs && tsc --p tsconfig.es5.json",
6976
"build:es6": "rm -rf ./dist/es6 && tsc --p tsconfig.es6.json"
7077
},
@@ -79,32 +86,15 @@
7986
"<rootDir>/test/**/*.{js,jsx,ts,tsx}",
8087
"!<rootDir>/.tsOutput/"
8188
],
82-
"setupFiles": [
83-
"./tests/test-shim.js",
84-
"./tests/test-setup.js"
85-
],
89+
"setupFiles": ["./tests/test-shim.js", "./tests/test-setup.js"],
8690
"transform": {
8791
"^.+\\.tsx?$": "ts-jest",
8892
"^.+\\.jsx?$": "babel-jest"
8993
},
9094
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
91-
"testPathIgnorePatterns": [
92-
"/.tsOutput/"
93-
],
94-
"moduleFileExtensions": [
95-
"ts",
96-
"tsx",
97-
"js",
98-
"jsx",
99-
"json",
100-
"node"
101-
],
102-
"modulePaths": [
103-
"src"
104-
],
105-
"moduleDirectories": [
106-
"node_modules",
107-
"src"
108-
]
95+
"testPathIgnorePatterns": ["/.tsOutput/"],
96+
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
97+
"modulePaths": ["src"],
98+
"moduleDirectories": ["node_modules", "src"]
10999
}
110100
}

react-app-rewire-css.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const path = require('path');
2+
const cloneDeep = require('lodash.clonedeep');
3+
4+
const ruleChildren = loader =>
5+
loader.use ||
6+
loader.oneOf ||
7+
(Array.isArray(loader.loader) && loader.loader) ||
8+
[];
9+
10+
const findIndexAndRules = (rulesSource, ruleMatcher) => {
11+
let result = undefined;
12+
const rules = Array.isArray(rulesSource)
13+
? rulesSource
14+
: ruleChildren(rulesSource);
15+
rules.some(
16+
(rule, index) =>
17+
(result = ruleMatcher(rule)
18+
? { index, rules }
19+
: findIndexAndRules(ruleChildren(rule), ruleMatcher)),
20+
);
21+
return result;
22+
};
23+
24+
const findRule = (rulesSource, ruleMatcher) => {
25+
const { index, rules } = findIndexAndRules(rulesSource, ruleMatcher);
26+
return rules[index];
27+
};
28+
29+
const cssRuleMatcher = rule =>
30+
rule.test && String(rule.test) === String(/\.css$/);
31+
32+
const createLoaderMatcher = loader => rule =>
33+
rule.loader && rule.loader.indexOf(`${path.sep}${loader}${path.sep}`) !== -1;
34+
const cssLoaderMatcher = createLoaderMatcher('css-loader');
35+
const postcssLoaderMatcher = createLoaderMatcher('postcss-loader');
36+
const fileLoaderMatcher = createLoaderMatcher('file-loader');
37+
38+
const addAfterRule = (rulesSource, ruleMatcher, value) => {
39+
const { index, rules } = findIndexAndRules(rulesSource, ruleMatcher);
40+
rules.splice(index + 1, 0, value);
41+
};
42+
43+
const addBeforeRule = (rulesSource, ruleMatcher, value) => {
44+
const { index, rules } = findIndexAndRules(rulesSource, ruleMatcher);
45+
rules.splice(index, 0, value);
46+
};
47+
48+
module.exports = function(config, env) {
49+
const cssRule = findRule(config.module.rules, cssRuleMatcher);
50+
51+
// sass
52+
const sassRule = cloneDeep(cssRule);
53+
sassRule.test = /\.s[ac]ss$/;
54+
addAfterRule(sassRule, postcssLoaderMatcher, require.resolve('sass-loader'));
55+
addBeforeRule(config.module.rules, fileLoaderMatcher, sassRule);
56+
57+
// less
58+
const lessRule = cloneDeep(cssRule);
59+
lessRule.test = /\.less$/;
60+
addAfterRule(lessRule, postcssLoaderMatcher, {
61+
loader: require.resolve('less-loader'),
62+
options: { javascriptEnabled: true },
63+
});
64+
addBeforeRule(config.module.rules, fileLoaderMatcher, lessRule);
65+
66+
return config;
67+
};

react-app-rewire-js-ts.js

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
const path = require('path');
2+
3+
const tsLoaderMatcher = function(rule) {
4+
return rule.test && rule.test.toString() === /\.(ts|tsx)$/.toString();
5+
};
6+
7+
const jsLoaderMatcher = function(rule) {
8+
return (
9+
rule.loader &&
10+
rule.loader.indexOf(`${path.sep}babel-loader${path.sep}`) !== -1
11+
);
12+
};
13+
14+
const getLoader = function(rules, matcher) {
15+
let loader;
16+
17+
rules.some(rule => {
18+
return (loader = matcher(rule)
19+
? rule
20+
: getLoader(rule.use || rule.oneOf || [], matcher));
21+
});
22+
23+
return loader;
24+
};
25+
26+
const getTsLoader = function(rules) {
27+
return getLoader(rules, tsLoaderMatcher);
28+
};
29+
30+
const getJsLoader = function(rules) {
31+
return getLoader(rules, jsLoaderMatcher);
32+
};
33+
34+
function tsConfig(config, env, babelPlugins) {
35+
const tsLoader = getTsLoader(config.module.rules);
36+
if (!tsLoader) {
37+
console.log('ts-loader not found');
38+
return config;
39+
}
40+
41+
delete tsLoader.loader;
42+
delete tsLoader.options;
43+
44+
// Replace loader with array of loaders with use: []
45+
tsLoader.use = [
46+
{
47+
loader: require.resolve('babel-loader'),
48+
options: {
49+
cacheDirectory: true,
50+
babelrc: false,
51+
compact: true,
52+
presets:
53+
env === 'production'
54+
? [require.resolve('babel-preset-react-app')]
55+
: [],
56+
plugins:
57+
env === 'production'
58+
? [...babelPlugins]
59+
: [require.resolve('react-hot-loader/babel'), ...babelPlugins],
60+
},
61+
},
62+
{
63+
loader: require.resolve('ts-loader'),
64+
options: {
65+
transpileOnly: true,
66+
configFile:
67+
env === 'production' ? 'tsconfig.json' : 'tsconfig.dev.json',
68+
},
69+
},
70+
];
71+
}
72+
73+
function jsConfig(config, env, babelPlugins) {
74+
const jsLoader = getJsLoader(config.module.rules);
75+
if (!jsLoader) {
76+
console.log('js-loader not found');
77+
return config;
78+
}
79+
80+
delete jsLoader.loader;
81+
delete jsLoader.options;
82+
83+
if (env === 'production') {
84+
jsLoader.include = [/node_modules/];
85+
}
86+
87+
// Replace loader with array of loaders with use: []
88+
jsLoader.use = [
89+
{
90+
loader: require.resolve('babel-loader'),
91+
options: {
92+
cacheDirectory: true,
93+
babelrc: false,
94+
compact: true,
95+
presets: [
96+
[
97+
require.resolve('babel-preset-env'),
98+
{
99+
targets: {
100+
browsers: ['>= 1%', 'chrome >= 45', 'Explorer 11'],
101+
},
102+
},
103+
],
104+
require.resolve('babel-preset-react-app'),
105+
],
106+
plugins:
107+
env === 'production'
108+
? [...babelPlugins]
109+
: [require.resolve('react-hot-loader/babel'), ...babelPlugins],
110+
},
111+
},
112+
];
113+
}
114+
115+
module.exports = (config, env, babelPlugins = []) => {
116+
// Typescript
117+
tsConfig(config, env, babelPlugins);
118+
119+
// JavaScript
120+
jsConfig(config, env, babelPlugins);
121+
122+
return config;
123+
};

0 commit comments

Comments
 (0)