Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 865f54b

Browse files
authored
Merge pull request #202 from opencomponents/webpack-4.6.0-187.3.0
[DX-495] Update to webpack 4 (from 3.11.0 to 4.8.3)
2 parents 7eeeb1b + 12f8517 commit 865f54b

10 files changed

Lines changed: 107 additions & 47 deletions

File tree

acceptance-setup/__tests__/__snapshots__/acceptance.js.snap

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

packages/oc-template-react-compiler/__tests__/__snapshots__/compile.js.snap

Lines changed: 32 additions & 32 deletions
Large diffs are not rendered by default.

packages/oc-template-react-compiler/__tests__/__snapshots__/compileView.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
exports[`valid component 1`] = `
44
Object {
55
"bundle": Object {
6-
"hashKey": "940a68df39eb3b2449c6256781f660c857d3890b",
6+
"hashKey": "7d47a0c151221c3f6a285fe966a4ca07cd6446fe",
77
},
88
"template": Object {
9-
"hashKey": "7ac03b60828e1be5987fc925d4a0bd1d05dc09d5",
9+
"hashKey": "31e3e6ab4d9dc8a8406a22dc7ae640256ecc3185",
1010
"src": "template.js",
1111
"type": "oc-template-react",
1212
},
1313
}
1414
`;
1515

16-
exports[`valid component 2`] = `"var oc=oc||{};oc.components=oc.components||{};oc.components['7ac03b60828e1be5987fc925d4a0bd1d05dc09d5']=function(model){ var modelHTML = model.__html ? model.__html : ''; var staticPath = model.reactComponent.props._staticPath; var props = JSON.stringify(model.reactComponent.props); return '<div id=\\"oc-reactRoot-react-component\\" class=\\"oc-reactRoot-react-component\\">' + modelHTML + '</div>' + '' + '<script>' + 'window.oc = window.oc || {};' + 'oc.cmd = oc.cmd || [];' + 'oc.cmd.push(function(oc){' + '' + 'oc.requireSeries([{\\"global\\":\\"PropTypes\\",\\"url\\":\\"https://unpkg.com/prop-types@15.6.1/prop-types.min.js\\",\\"name\\":\\"prop-types\\"},{\\"global\\":\\"React\\",\\"url\\":\\"https://unpkg.com/react@16.3.2/umd/react.production.min.js\\",\\"name\\":\\"react\\"},{\\"global\\":\\"ReactDOM\\",\\"url\\":\\"https://unpkg.com/react-dom@16.3.2/umd/react-dom.production.min.js\\",\\"name\\":\\"react-dom\\"}], function(){' + 'oc.require(' + '[\\"oc\\", \\"reactComponents\\", \\"940a68df39eb3b2449c6256781f660c857d3890b\\"],' + '\\"' + staticPath + 'react-component.js\\",' + 'function(ReactComponent){' + 'var targetNode = document.getElementById(\\"oc-reactRoot-react-component\\");' + 'targetNode.setAttribute(\\"id\\",\\"\\");' + 'ReactDOM.render(React.createElement(ReactComponent,' + props + '),targetNode);' + '}' + ');' + '});' + '});' + '</script>' }"`;
16+
exports[`valid component 2`] = `"var oc=oc||{};oc.components=oc.components||{};oc.components['31e3e6ab4d9dc8a8406a22dc7ae640256ecc3185']=function(model){ var modelHTML = model.__html ? model.__html : ''; var staticPath = model.reactComponent.props._staticPath; var props = JSON.stringify(model.reactComponent.props); return '<div id=\\"oc-reactRoot-react-component\\" class=\\"oc-reactRoot-react-component\\">' + modelHTML + '</div>' + '' + '<script>' + 'window.oc = window.oc || {};' + 'oc.cmd = oc.cmd || [];' + 'oc.cmd.push(function(oc){' + '' + 'oc.requireSeries([{\\"global\\":\\"PropTypes\\",\\"url\\":\\"https://unpkg.com/prop-types@15.6.1/prop-types.min.js\\",\\"name\\":\\"prop-types\\"},{\\"global\\":\\"React\\",\\"url\\":\\"https://unpkg.com/react@16.3.2/umd/react.production.min.js\\",\\"name\\":\\"react\\"},{\\"global\\":\\"ReactDOM\\",\\"url\\":\\"https://unpkg.com/react-dom@16.3.2/umd/react-dom.production.min.js\\",\\"name\\":\\"react-dom\\"}], function(){' + 'oc.require(' + '[\\"oc\\", \\"reactComponents\\", \\"7d47a0c151221c3f6a285fe966a4ca07cd6446fe\\"],' + '\\"' + staticPath + 'react-component.js\\",' + 'function(ReactComponent){' + 'var targetNode = document.getElementById(\\"oc-reactRoot-react-component\\");' + 'targetNode.setAttribute(\\"id\\",\\"\\");' + 'ReactDOM.render(React.createElement(ReactComponent,' + props + '),targetNode);' + '}' + ');' + '});' + '});' + '</script>' }"`;

packages/oc-template-react-compiler/__tests__/createExcludeRegex.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const createExcludeRegex = require("../lib/to-abstract-base-template-utils/createExcludeRegex");
1+
const createExcludeRegex = require("../lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/createExcludeRegex");
22

33
test("should create a regex that match against any node module set aside given ones", () => {
44
const regex = createExcludeRegex([

packages/oc-template-react-compiler/lib/compileView.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

33
const async = require("async");
4-
const compiler = require("oc-webpack").compiler;
54
const fs = require("fs-extra");
65
const hashBuilder = require("oc-hash-builder");
76
const MemoryFS = require("memory-fs");
@@ -11,7 +10,11 @@ const path = require("path");
1110
const reactComponentWrapper = require("oc-react-component-wrapper");
1211
const strings = require("oc-templates-messages");
1312

14-
const webpackConfigurator = require("./to-abstract-base-template-utils/webpackConfigurator");
13+
const {
14+
compiler,
15+
configurator: webpackConfigurator
16+
} = require("./to-abstract-base-template-utils/oc-webpack");
17+
1518
const fontFamilyUnicodeParser = require("./to-abstract-base-template-utils/font-family-unicode-parser");
1619
const reactOCProviderTemplate = require("./reactOCProviderTemplate");
1720
const viewTemplate = require("./viewTemplate");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
const compiler = require("./lib/compiler");
4+
const configurator = require("./lib/configurator");
5+
6+
module.exports = {
7+
compiler,
8+
configurator
9+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use strict";
2+
3+
const MemoryFS = require("memory-fs");
4+
const webpack = require("webpack");
5+
6+
const memoryFs = new MemoryFS();
7+
8+
module.exports = function compiler(config, callback) {
9+
const logger = config.logger;
10+
delete config.logger;
11+
12+
const compiler = webpack(config);
13+
compiler.outputFileSystem = memoryFs;
14+
15+
compiler.run((error, stats) => {
16+
let softError;
17+
let warning;
18+
19+
// handleFatalError
20+
if (error) {
21+
return callback(error);
22+
}
23+
24+
const info = stats.toJson();
25+
// handleSoftErrors
26+
if (stats.hasErrors()) {
27+
softError = info.errors.toString();
28+
return callback(softError);
29+
}
30+
// handleWarnings
31+
if (stats.hasWarnings()) {
32+
warning = info.warnings.toString();
33+
}
34+
35+
const log = stats.toString(config.stats || "errors-only");
36+
37+
if (log) {
38+
logger.log(log);
39+
}
40+
callback(null, memoryFs.data);
41+
});
42+
};

packages/oc-template-react-compiler/lib/to-abstract-base-template-utils/createExcludeRegex.js renamed to packages/oc-template-react-compiler/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/createExcludeRegex.js

File renamed without changes.

packages/oc-template-react-compiler/lib/to-abstract-base-template-utils/webpackConfigurator.js renamed to packages/oc-template-react-compiler/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const ExtractTextPlugin = require("extract-text-webpack-plugin");
44
const MinifyPlugin = require("babel-minify-webpack-plugin");
55
const externalDependenciesHandlers = require("oc-external-dependencies-handler");
66
const path = require("path");
7-
const webpack = require("oc-webpack").webpack;
7+
const webpack = require("webpack");
88

99
const createExcludeRegex = require("./createExcludeRegex");
1010

11-
module.exports = function webpackConfigGenerator(options) {
11+
module.exports = options => {
1212
const buildPath = options.buildPath || "/build";
1313
const production = options.production;
1414
const buildIncludes = options.buildIncludes.concat(
@@ -67,6 +67,13 @@ module.exports = function webpackConfigGenerator(options) {
6767
const cacheDirectory = !production;
6868

6969
return {
70+
mode: production ? "production" : "development",
71+
optimization: {
72+
// https://webpack.js.org/configuration/optimization/
73+
// Override production mode optimization for minification
74+
// As it currently breakes the build, still rely on babel-minify-webpack-plugin instead
75+
minimize: false
76+
},
7077
entry: options.viewPath,
7178
output: {
7279
path: buildPath,

packages/oc-template-react-compiler/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
"license": "MIT",
2525
"dependencies": {
2626
"async": "^2.4.1",
27-
"autoprefixer": "8.4.1",
27+
"autoprefixer": "^8.5.0",
2828
"babel-loader": "^7.1.2",
2929
"babel-minify-webpack-plugin": "0.3.1",
3030
"babel-plugin-transform-object-rest-spread": "^6.26.0",
3131
"babel-preset-env": "^1.6.0",
3232
"babel-preset-react": "^6.24.1",
3333
"css-loader": "^0.28.5",
34-
"extract-text-webpack-plugin": "^3.0.0",
34+
"extract-text-webpack-plugin": "^4.0.0-beta.0",
3535
"fs-extra": "6.0.1",
3636
"infinite-loop-loader": "^1.0.3",
3737
"lodash": "^4.17.4",
@@ -47,14 +47,13 @@
4747
"oc-template-react": "2.0.9",
4848
"oc-templates-messages": "1.0.2",
4949
"oc-view-wrapper": "1.0.3",
50-
"oc-webpack": "2.3.2",
5150
"postcss-extend": "^1.0.5",
5251
"postcss-icss-values": "^2.0.1",
5352
"postcss-import": "^11.0.0",
5453
"postcss-loader": "^2.0.9",
5554
"prop-types": "15.6.1",
5655
"react": "16.3.2",
57-
"webpack": "^3.5.5"
56+
"webpack": "^4.8.3"
5857
},
5958
"files": [
6059
"index.js",

0 commit comments

Comments
 (0)