Skip to content

Commit f0fd135

Browse files
committed
Merge branch 'v0.7.0' into develop
2 parents 1a16971 + 79beb74 commit f0fd135

File tree

13 files changed

+234
-137
lines changed

13 files changed

+234
-137
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Topcoder React Utils Changelog
22

3+
### v0.7.0
4+
Fixes various sins left in the previous version.
5+
36
### v0.6.0
47
- A better way to build the library: both dev and prod builds are created; and
58
the proper version is selected depending on `NODE_ENV` value at the buildtime

__tests__/server/renderer.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const TEST_HTTP_REQUEST = {
3636
const TEST_WEBPACK_CONFIG = {
3737
context: TEST_CONTEXT,
3838
output: {
39+
path: '/test/path',
3940
publicPath: '/test/public/path/',
4041
},
4142
};
@@ -76,6 +77,19 @@ async function coreTest(webpackConfig, options) {
7677
try {
7778
let render = '';
7879
await renderer(_.clone(TEST_HTTP_REQUEST), {
80+
locals: {
81+
webpackStats: {
82+
toJson: () => ({
83+
assetsByChunkName: {
84+
'test-chunk-a': 'test-chunk-a-1511941200000.css',
85+
'test-chunk-b': [
86+
'test-chunk-b-1511941200000.js',
87+
'test-chunk-b-1511941200000.css',
88+
],
89+
},
90+
}),
91+
},
92+
},
7993
send: (x) => { render += x; },
8094
status: (x) => { render += `HTTP STATUS: ${x}\n`; },
8195
});

bin/topcoder-lib-setup

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ const OPTIONS = [{
1616
alias: 'h',
1717
description: 'Shows usage instructions',
1818
type: Boolean,
19+
}, {
20+
name: 'just-fix-deps',
21+
description: 'Skips installation of libraries, just fixes dependencies',
22+
type: Boolean,
1923
}, {
2024
name: 'libraries',
2125
defaultOption: true,
@@ -46,7 +50,7 @@ const HELP = [{
4650
* into NPM's install command.
4751
*/
4852
function generateTargetPackage(entry) {
49-
if (entry[1].match(/^(git\+)?https?:\/\//)) return entry[1];
53+
if (entry[1].match(/^(git\+)?(file|https)?:\/\//)) return entry[1];
5054
if (entry[1].match(/^[\^~]/)) return `${entry[0]}@${entry[1].slice(1)}`;
5155
return `${entry[0]}@${entry[1]}`;
5256
}
@@ -137,7 +141,7 @@ if (options.help) showHelp();
137141
else {
138142
const hostData = getHostPackageJson();
139143
options.libraries.forEach((library) => {
140-
install(library);
144+
if (!options['just-fix-deps']) install(library);
141145
const libData = getPackageJson(library);
142146
adoptDevDependencies(libData, hostData);
143147
updateProdDependencies(libData, hostData);

config/eslint/default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"components": [],
1010
"specialLink": ["hrefLeft", "hrefRight"],
1111
"aspects": ["invalidHref", "noHref", "preferButton"]
12-
}]
12+
}],
13+
"react/jsx-one-expression-per-line": false
1314
}
1415
}

config/webpack/app-base.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
const _ = require('lodash');
88
const autoprefixer = require('autoprefixer');
9-
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
9+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
1010
const forge = require('node-forge');
1111
const fs = require('fs');
1212
const moment = require('moment');
1313
const path = require('path');
14+
const { StatsWriterPlugin } = require('webpack-stats-plugin');
1415
const webpack = require('webpack');
1516

1617
/**
@@ -97,27 +98,23 @@ module.exports = function configFactory(ops) {
9798
fs: 'empty',
9899
},
99100
mode: o.mode,
100-
/* TODO: We have to disable these optimizations, otherwise they will break
101-
* our code-splitting functionality. Once the code-splitting setup is fixed,
102-
* these optimizations can be enabled again. */
103-
optimization: {
104-
removeEmptyChunks: false,
105-
splitChunks: false,
106-
},
107101
output: {
108102
chunkFilename: `[name]-${now.valueOf()}.js`,
109103
filename: `[name]-${now.valueOf()}.js`,
110104
path: path.resolve(__dirname, o.context, 'build'),
111105
publicPath: `${o.publicPath}/`,
112106
},
113107
plugins: [
114-
new ExtractCssChunks({
108+
new MiniCssExtractPlugin({
115109
chunkFilename: `[name]-${now.valueOf()}.css`,
116110
filename: `[name]-${now.valueOf()}.css`,
117111
}),
118112
new webpack.DefinePlugin({
119113
BUILD_INFO: JSON.stringify(buildInfo),
120114
}),
115+
new StatsWriterPlugin({
116+
filename: '__stats__.json',
117+
}),
121118
],
122119
resolve: {
123120
alias: {
@@ -165,7 +162,7 @@ module.exports = function configFactory(ops) {
165162
/* Loads SCSS stylesheets. */
166163
test: /\.scss/,
167164
use: [
168-
ExtractCssChunks.loader, {
165+
MiniCssExtractPlugin.loader, {
169166
loader: 'css-loader',
170167
options: {
171168
localIdentName: o.cssLocalIdent,
@@ -188,10 +185,16 @@ module.exports = function configFactory(ops) {
188185
* from dependencies, as we use SCSS inside our own code. */
189186
test: /\.css$/,
190187
use: [
191-
ExtractCssChunks.loader,
188+
MiniCssExtractPlugin.loader,
192189
'css-loader',
193190
],
194191
}],
195192
},
193+
optimization: {
194+
/* TODO: Dynamic chunk splitting does not play along with server-side
195+
* rendering of split chunks. Probably there is a way to achieve that,
196+
* but it is not a priority now. */
197+
splitChunks: false,
198+
},
196199
};
197200
};

config/webpack/app-production.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ module.exports = function configFactory(ops) {
4040
NODE_ENV: JSON.stringify('production'),
4141
},
4242
}),
43-
4443
new OptimizeCssAssetsPlugin({
4544
cssProcessorOptions: {
4645
/* Due to the way our styles are organized, these dangerous

config/webpack/lib-base.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
const autoprefixer = require('autoprefixer');
8-
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
8+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
99
const path = require('path');
1010
const webpack = require('webpack');
1111

@@ -37,14 +37,15 @@ module.exports = function configFactory(ops) {
3737
context: ops.context,
3838
entry: ops.entry,
3939
externals: [
40-
'babel-runtime',
40+
/babel-runtime/,
4141
'lodash',
4242
'moment',
4343
'prop-types',
4444
'react',
4545
'react-css-super-themr',
46-
'react-dom',
46+
/react-dom/,
4747
'react-helmet',
48+
/react-hot-loader/,
4849
'react-redux',
4950
'react-router-dom',
5051
'redux',
@@ -77,7 +78,7 @@ module.exports = function configFactory(ops) {
7778
NODE_ENV: JSON.stringify(ops.babelEnv),
7879
},
7980
}),
80-
new ExtractCssChunks({
81+
new MiniCssExtractPlugin({
8182
filename: 'style.css',
8283
}),
8384
],
@@ -117,7 +118,7 @@ module.exports = function configFactory(ops) {
117118
test: /\.scss/,
118119
exclude: /node_modules/,
119120
use: [
120-
ExtractCssChunks.loader, {
121+
MiniCssExtractPlugin.loader, {
121122
loader: 'css-loader',
122123
options: {
123124
importLoaders: 3,
@@ -143,7 +144,7 @@ module.exports = function configFactory(ops) {
143144
* from dependencies, as we use SCSS inside our own code. */
144145
test: /\.css$/,
145146
use: [
146-
ExtractCssChunks.loader,
147+
MiniCssExtractPlugin.loader,
147148
'css-loader',
148149
],
149150
}],

config/webpack/lib-production.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
* Development Webpack configuration for ReactJS libraries.
33
*/
44

5+
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
56
const path = require('path');
7+
const webpackMerge = require('webpack-merge');
68
const baseFactory = require('./lib-base');
79

810
/**
@@ -21,11 +23,24 @@ const baseFactory = require('./lib-base');
2123
* @return {Object} Webpack configuration.
2224
*/
2325
module.exports = function configFactory(ops) {
24-
return baseFactory({
26+
const baseConfig = baseFactory({
2527
...ops,
2628
babelEnv: 'production',
2729
cssLocalIdent: '[hash:base64:6]',
2830
mode: 'production',
2931
outputPath: path.resolve(__dirname, ops.context, 'dist/prod'),
3032
});
33+
return webpackMerge(baseConfig, {
34+
plugins: [
35+
new OptimizeCssAssetsPlugin({
36+
cssProcessorOptions: {
37+
/* Due to the way our styles are organized, these dangerous
38+
* optimizations can break our styles, thus they are disabled. */
39+
discardUnused: false,
40+
reduceIdents: false,
41+
zindex: false,
42+
},
43+
}),
44+
],
45+
});
3146
};

0 commit comments

Comments
 (0)