Skip to content

Commit 604a4cd

Browse files
Jack Zhaogaearon
Jack Zhao
authored andcommitted
Webpack4 (facebook#4490)
* - [x] Upgrade to webpack 4.8.X - [x] Utilize webpack 4 development and production modes - [x] Upgrade webpack dev server - [x] Webpack 4 compatible release of thread-loader - [x] Webpack 4 compatible release of HtmlWebpackPlugin - [x] Webpack 4 compatible release of SwPrecacheWebpackPlugin - [x] Webpack 4 compatible release of WebpackManifestPlugin - [x] Update README - [x] Update WebpackDevServerUtils - [x] Update InterpolateHtmlPlugin - [x] Update ModuleScopePlugin - [x] Update WatchMissingNodeModulesPlugin - [x] Move UglifyJS options to webpack 4 optimize - [x] Move InterpolateHtmlPlugin to make it tapable on HtmlWebpackPlugin - [x] vendor splitting via splitChunks.splitChunks (https://twitter.com/wSokra/status/969633336732905474) - [x] long term caching via splitChunks.runtimeChunk (https://twitter.com/wSokra/status/969679223278505985) - [x] Make sure process.env.NODE_ENV is proxied correctly to `react-error-overlay` - [x] Implicit webpack.NamedModulesPlugin in dev config as its default in webpack 4 - [x] Disable webpack performance hints as we have our own filesize reporter - [x] Replace ExtractTextPlugin with MiniCssExtractPlugin - [x] Switch to css whole file minification via OptimizeCSSAssetsPlugin rather than per module css minification to gain performance * disable module concatenation * fix cleanup * fix optimization * restore tmp removal * preserve * fix css tests * fix test run * fix svg test * revert tmp dir * fix import * fix import * help debugging * fix tests * fix sass test * restore cleanup
1 parent ea4dc6f commit 604a4cd

File tree

3 files changed

+46
-65
lines changed

3 files changed

+46
-65
lines changed

config/webpack.config.prod.js

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ module.exports = {
115115
.replace(/\\/g, '/'),
116116
},
117117
optimization: {
118+
// webpack-manifest-plugin currently does not play well with ConcatenatedModule
119+
concatenateModules: false,
118120
minimizer: [
119121
new UglifyJsPlugin({
120122
uglifyOptions: {

fixtures/kitchensink/integration/initDOM.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const path = require('path');
1212
const { expect } = require('chai');
1313

1414
let getMarkup;
15-
let resourceLoader;
15+
export let resourceLoader;
1616

1717
if (process.env.E2E_FILE) {
1818
const file = path.isAbsolute(process.env.E2E_FILE)
@@ -47,25 +47,18 @@ if (process.env.E2E_FILE) {
4747

4848
resourceLoader = (resource, callback) => resource.defaultFetch(callback);
4949
} else {
50-
it.only(
51-
'can run jsdom (at least one of "E2E_FILE" or "E2E_URL" environment variables must be provided)',
52-
() => {
53-
expect(
54-
new Error("This isn't the error you are looking for.")
55-
).to.be.undefined();
56-
}
57-
);
50+
it.only('can run jsdom (at least one of "E2E_FILE" or "E2E_URL" environment variables must be provided)', () => {
51+
expect(
52+
new Error("This isn't the error you are looking for.")
53+
).to.be.undefined();
54+
});
5855
}
5956

6057
export default feature =>
6158
new Promise(async resolve => {
6259
const markup = await getMarkup();
6360
const host = process.env.E2E_URL || 'http://www.example.org/spa:3000';
6461
const doc = jsdom.jsdom(markup, {
65-
features: {
66-
FetchExternalResources: ['script', 'css'],
67-
ProcessExternalResources: ['script'],
68-
},
6962
created: (_, win) =>
7063
win.addEventListener('ReactFeatureDidMount', () => resolve(doc), true),
7164
deferClose: true,

fixtures/kitchensink/integration/webpack.test.js

+38-52
Original file line numberDiff line numberDiff line change
@@ -6,78 +6,68 @@
66
*/
77

88
import { expect } from 'chai';
9-
import initDOM from './initDOM';
9+
import initDOM, { resourceLoader } from './initDOM';
10+
import url from 'url';
11+
12+
const matchCSS = (doc, regexes) => {
13+
if (process.env.E2E_FILE) {
14+
const elements = doc.getElementsByTagName('link');
15+
let href = "";
16+
for (const elem of elements) {
17+
if (elem.rel === 'stylesheet') {
18+
href = elem.href;
19+
}
20+
}
21+
resourceLoader(
22+
{ url: url.parse(href) },
23+
(_, textContent) => {
24+
for (const regex of regexes) {
25+
expect(textContent).to.match(regex);
26+
}
27+
}
28+
);
29+
30+
} else {
31+
for (let i = 0; i < regexes.length; ++i) {
32+
expect(doc.getElementsByTagName('style')[i].textContent.replace(/\s/g, '')).to.match(regexes[i]);
33+
}
34+
}
35+
}
1036

1137
describe('Integration', () => {
1238
describe('Webpack plugins', () => {
1339
it('css inclusion', async () => {
1440
const doc = await initDOM('css-inclusion');
15-
16-
expect(
17-
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
18-
).to.match(/html\{/);
19-
expect(
20-
doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '')
21-
).to.match(/#feature-css-inclusion\{background:.+;color:.+}/);
41+
matchCSS(doc, [/html\{/, /#feature-css-inclusion\{background:.+;color:.+}/]);
2242
});
2343

2444
it('css modules inclusion', async () => {
2545
const doc = await initDOM('css-modules-inclusion');
26-
27-
expect(
28-
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
29-
).to.match(/.+style_cssModulesInclusion__.+\{background:.+;color:.+}/);
30-
expect(
31-
doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '')
32-
).to.match(
33-
/.+assets_cssModulesIndexInclusion__.+\{background:.+;color:.+}/
34-
);
46+
matchCSS(doc, [/.+style_cssModulesInclusion__.+\{background:.+;color:.+}/,
47+
/.+assets_cssModulesIndexInclusion__.+\{background:.+;color:.+}/]);
3548
});
3649

3750
it('scss inclusion', async () => {
3851
const doc = await initDOM('scss-inclusion');
39-
40-
expect(
41-
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
42-
).to.match(/#feature-scss-inclusion\{background:.+;color:.+}/);
52+
matchCSS(doc, [/#feature-scss-inclusion\{background:.+;color:.+}/]);
4353
});
4454

4555
it('scss modules inclusion', async () => {
4656
const doc = await initDOM('scss-modules-inclusion');
47-
48-
expect(
49-
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
50-
).to.match(
51-
/.+scss-styles_scssModulesInclusion.+\{background:.+;color:.+}/
52-
);
53-
expect(
54-
doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '')
55-
).to.match(
56-
/.+assets_scssModulesIndexInclusion.+\{background:.+;color:.+}/
57-
);
57+
matchCSS(doc, [/.+scss-styles_scssModulesInclusion.+\{background:.+;color:.+}/,
58+
/.+assets_scssModulesIndexInclusion.+\{background:.+;color:.+}/]);
59+
5860
});
5961

6062
it('sass inclusion', async () => {
6163
const doc = await initDOM('sass-inclusion');
62-
63-
expect(
64-
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
65-
).to.match(/#feature-sass-inclusion\{background:.+;color:.+}/);
64+
matchCSS(doc, [/#feature-sass-inclusion\{background:.+;color:.+}/]);
6665
});
6766

6867
it('sass modules inclusion', async () => {
6968
const doc = await initDOM('sass-modules-inclusion');
70-
71-
expect(
72-
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
73-
).to.match(
74-
/.+sass-styles_sassModulesInclusion.+\{background:.+;color:.+}/
75-
);
76-
expect(
77-
doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '')
78-
).to.match(
79-
/.+assets_sassModulesIndexInclusion.+\{background:.+;color:.+}/
80-
);
69+
matchCSS(doc, [/.+sass-styles_sassModulesInclusion.+\{background:.+;color:.+}/,
70+
/.+assets_sassModulesIndexInclusion.+\{background:.+;color:.+}/]);
8171
});
8272

8373
it('graphql files inclusion', async () => {
@@ -124,7 +114,6 @@ describe('Integration', () => {
124114

125115
it('svg inclusion', async () => {
126116
const doc = await initDOM('svg-inclusion');
127-
128117
expect(doc.getElementById('feature-svg-inclusion').src).to.match(
129118
/\/static\/media\/logo\..+\.svg$/
130119
);
@@ -140,10 +129,7 @@ describe('Integration', () => {
140129

141130
it('svg in css', async () => {
142131
const doc = await initDOM('svg-in-css');
143-
144-
expect(
145-
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
146-
).to.match(/\/static\/media\/logo\..+\.svg/);
132+
matchCSS(doc, [/\/static\/media\/logo\..+\.svg/]);
147133
});
148134

149135
it('unknown ext inclusion', async () => {

0 commit comments

Comments
 (0)