oc-template-react-compiler 5.2.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/lib/compile.d.ts +3 -0
- package/dist/lib/compile.js +36 -0
- package/dist/lib/htmlTemplate.d.ts +10 -0
- package/dist/lib/htmlTemplate.js +51 -0
- package/dist/lib/reactOCProviderTemplate.d.ts +3 -0
- package/dist/lib/reactOCProviderTemplate.js +56 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/useData.d.ts +7 -0
- package/dist/utils/useData.js +31 -0
- package/package.json +37 -47
- package/scaffold/src/.eslintrc.json +3 -0
- package/scaffold/src/package.json +29 -11
- package/scaffold/src/public/logo.png +0 -0
- package/scaffold/src/src/App.test.tsx +39 -0
- package/scaffold/src/src/App.tsx +52 -0
- package/scaffold/src/src/oc-app.d.ts +1 -0
- package/scaffold/src/src/server.ts +37 -0
- package/scaffold/src/src/setupTests.js +1 -0
- package/scaffold/src/src/styles.css +30 -0
- package/scaffold/src/src/types.ts +15 -0
- package/scaffold/src/tsconfig.json +26 -0
- package/scaffold/src/vite.config.ts +11 -0
- package/index.js +0 -11
- package/lib/compile.js +0 -26
- package/lib/compileServer.js +0 -100
- package/lib/compileView.js +0 -135
- package/lib/higherOrderServerTemplate.js +0 -32
- package/lib/reactOCProviderTemplate.js +0 -54
- package/lib/to-abstract-base-template-utils/font-family-unicode-parser.js +0 -25
- package/lib/to-abstract-base-template-utils/oc-webpack/index.js +0 -9
- package/lib/to-abstract-base-template-utils/oc-webpack/lib/compiler/index.js +0 -42
- package/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/client/index.js +0 -120
- package/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/createExcludeRegex.js +0 -6
- package/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/index.js +0 -9
- package/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/server/index.js +0 -93
- package/lib/viewTemplate.js +0 -35
- package/scaffold/src/app.js +0 -11
- package/scaffold/src/server.js +0 -4
- package/scaffold/src/styles.css +0 -4
- package/utils/index.js +0 -4
- package/utils/withDataProvider.js +0 -21
- package/utils/withSettingProvider.js +0 -21
package/index.js
DELETED
package/lib/compile.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const createCompile = require("oc-generic-template-compiler").createCompile;
|
|
4
|
-
const compileStatics = require("oc-statics-compiler");
|
|
5
|
-
const getInfo = require("oc-template-react").getInfo;
|
|
6
|
-
|
|
7
|
-
const compileServer = require("./compileServer");
|
|
8
|
-
const compileView = require("./compileView");
|
|
9
|
-
|
|
10
|
-
// OPTIONS
|
|
11
|
-
// =======
|
|
12
|
-
// componentPath
|
|
13
|
-
// componentPackage,
|
|
14
|
-
// logger,
|
|
15
|
-
// minify
|
|
16
|
-
// ocPackage
|
|
17
|
-
// publishPath
|
|
18
|
-
// verbose,
|
|
19
|
-
// watch,
|
|
20
|
-
// production
|
|
21
|
-
module.exports = createCompile({
|
|
22
|
-
compileServer,
|
|
23
|
-
compileStatics,
|
|
24
|
-
compileView,
|
|
25
|
-
getInfo
|
|
26
|
-
});
|
package/lib/compileServer.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const async = require("async");
|
|
4
|
-
const fs = require("fs-extra");
|
|
5
|
-
const hashBuilder = require("oc-hash-builder");
|
|
6
|
-
const MemoryFS = require("memory-fs");
|
|
7
|
-
const path = require("path");
|
|
8
|
-
const reactComponentWrapper = require("oc-react-component-wrapper");
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
compiler,
|
|
12
|
-
configurator: { server: webpackConfigurator }
|
|
13
|
-
} = require("./to-abstract-base-template-utils/oc-webpack");
|
|
14
|
-
const higherOrderServerTemplate = require("./higherOrderServerTemplate");
|
|
15
|
-
|
|
16
|
-
module.exports = (options, callback) => {
|
|
17
|
-
const serverFileName = options.componentPackage.oc.files.data;
|
|
18
|
-
let serverPath = path.join(options.componentPath, serverFileName);
|
|
19
|
-
if (process.platform === "win32") {
|
|
20
|
-
serverPath = serverPath.split("\\").join("\\\\");
|
|
21
|
-
}
|
|
22
|
-
const publishFileName = options.publishFileName || "server.js";
|
|
23
|
-
const publishPath = options.publishPath;
|
|
24
|
-
const stats = options.verbose ? "verbose" : "errors-only";
|
|
25
|
-
const dependencies = options.componentPackage.dependencies || {};
|
|
26
|
-
const componentName = options.componentPackage.name;
|
|
27
|
-
const componentVersion = options.componentPackage.version;
|
|
28
|
-
const production = options.production;
|
|
29
|
-
|
|
30
|
-
const higherOrderServerContent = higherOrderServerTemplate({
|
|
31
|
-
serverPath,
|
|
32
|
-
componentName,
|
|
33
|
-
componentVersion,
|
|
34
|
-
bundleHashKey: options.compiledViewInfo.bundle.hashKey
|
|
35
|
-
});
|
|
36
|
-
const tempFolder = path.join(serverPath, "../temp");
|
|
37
|
-
const higherOrderServerPath = path.join(
|
|
38
|
-
tempFolder,
|
|
39
|
-
"__oc_higherOrderServer.js"
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const config = webpackConfigurator({
|
|
43
|
-
serverPath: higherOrderServerPath,
|
|
44
|
-
publishFileName,
|
|
45
|
-
dependencies,
|
|
46
|
-
stats,
|
|
47
|
-
production
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
async.waterfall(
|
|
51
|
-
[
|
|
52
|
-
next =>
|
|
53
|
-
fs.outputFile(higherOrderServerPath, higherOrderServerContent, next),
|
|
54
|
-
next => compiler(config, next),
|
|
55
|
-
(data, next) => {
|
|
56
|
-
const basePath = path.join(serverPath, "../temp/build");
|
|
57
|
-
const memory = new MemoryFS(data);
|
|
58
|
-
const getCompiled = fileName =>
|
|
59
|
-
memory.readFileSync(`${basePath}/${fileName}`, "UTF8");
|
|
60
|
-
|
|
61
|
-
return fs.ensureDir(publishPath, err => {
|
|
62
|
-
if (err) return next(err);
|
|
63
|
-
const result = { "server.js": getCompiled(config.output.filename) };
|
|
64
|
-
|
|
65
|
-
if (!production) {
|
|
66
|
-
try {
|
|
67
|
-
result["server.js.map"] = getCompiled(
|
|
68
|
-
`${config.output.filename}.map`
|
|
69
|
-
);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
// skip sourcemap if it doesn't exist
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
next(null, result);
|
|
76
|
-
});
|
|
77
|
-
},
|
|
78
|
-
(compiledFiles, next) =>
|
|
79
|
-
async.eachOf(
|
|
80
|
-
compiledFiles,
|
|
81
|
-
(fileContent, fileName, next) =>
|
|
82
|
-
fs.writeFile(path.join(publishPath, fileName), fileContent, next),
|
|
83
|
-
err =>
|
|
84
|
-
next(
|
|
85
|
-
err,
|
|
86
|
-
err
|
|
87
|
-
? null
|
|
88
|
-
: {
|
|
89
|
-
type: "node.js",
|
|
90
|
-
hashKey: hashBuilder.fromString(
|
|
91
|
-
compiledFiles[publishFileName]
|
|
92
|
-
),
|
|
93
|
-
src: publishFileName
|
|
94
|
-
}
|
|
95
|
-
)
|
|
96
|
-
)
|
|
97
|
-
],
|
|
98
|
-
(err, data) => fs.remove(tempFolder, err2 => callback(err, data))
|
|
99
|
-
);
|
|
100
|
-
};
|
package/lib/compileView.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const async = require("async");
|
|
4
|
-
const fs = require("fs-extra");
|
|
5
|
-
const hashBuilder = require("oc-hash-builder");
|
|
6
|
-
const MemoryFS = require("memory-fs");
|
|
7
|
-
const minifyFile = require("oc-minify-file");
|
|
8
|
-
const ocViewWrapper = require("oc-view-wrapper");
|
|
9
|
-
const path = require("path");
|
|
10
|
-
const reactComponentWrapper = require("oc-react-component-wrapper");
|
|
11
|
-
const strings = require("oc-templates-messages");
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
compiler,
|
|
15
|
-
configurator: { client: webpackConfigurator }
|
|
16
|
-
} = require("./to-abstract-base-template-utils/oc-webpack");
|
|
17
|
-
|
|
18
|
-
const fontFamilyUnicodeParser = require("./to-abstract-base-template-utils/font-family-unicode-parser");
|
|
19
|
-
const reactOCProviderTemplate = require("./reactOCProviderTemplate");
|
|
20
|
-
const viewTemplate = require("./viewTemplate");
|
|
21
|
-
|
|
22
|
-
module.exports = (options, callback) => {
|
|
23
|
-
const viewFileName = options.componentPackage.oc.files.template.src;
|
|
24
|
-
let viewPath = path.join(options.componentPath, viewFileName);
|
|
25
|
-
if (process.platform === "win32") {
|
|
26
|
-
viewPath = viewPath.split("\\").join("\\\\");
|
|
27
|
-
}
|
|
28
|
-
const publishPath = options.publishPath;
|
|
29
|
-
const publishFileName = options.publishFileName || "template.js";
|
|
30
|
-
const componentPackage = options.componentPackage;
|
|
31
|
-
const { getInfo } = require("../index");
|
|
32
|
-
const externals = componentPackage.oc.files.template.externals || getInfo().externals;
|
|
33
|
-
const production = options.production;
|
|
34
|
-
|
|
35
|
-
const reactOCProviderContent = reactOCProviderTemplate({ viewPath });
|
|
36
|
-
const reactOCProviderName = "reactOCProvider.js";
|
|
37
|
-
const reactOCProviderPath = path.join(
|
|
38
|
-
publishPath,
|
|
39
|
-
"temp",
|
|
40
|
-
reactOCProviderName
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const compile = (options, cb) => {
|
|
44
|
-
const config = webpackConfigurator({
|
|
45
|
-
viewPath: options.viewPath,
|
|
46
|
-
externals: externals.reduce((externals, dep) => {
|
|
47
|
-
externals[dep.name] = dep.global;
|
|
48
|
-
return externals;
|
|
49
|
-
}, {}),
|
|
50
|
-
publishFileName,
|
|
51
|
-
production,
|
|
52
|
-
buildIncludes: componentPackage.oc.files.template.buildIncludes || []
|
|
53
|
-
});
|
|
54
|
-
compiler(config, (err, data) => {
|
|
55
|
-
if (err) {
|
|
56
|
-
return cb(err);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const memoryFs = new MemoryFS(data);
|
|
60
|
-
const bundle = memoryFs.readFileSync(
|
|
61
|
-
`/build/${config.output.filename}`,
|
|
62
|
-
"UTF8"
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
const bundleHash = hashBuilder.fromString(bundle);
|
|
66
|
-
const bundleName = "react-component";
|
|
67
|
-
const bundlePath = path.join(publishPath, `${bundleName}.js`);
|
|
68
|
-
const wrappedBundle = reactComponentWrapper(bundleHash, bundle);
|
|
69
|
-
fs.outputFileSync(bundlePath, wrappedBundle);
|
|
70
|
-
|
|
71
|
-
let css = null;
|
|
72
|
-
if (data.build["main.css"]) {
|
|
73
|
-
// This is an awesome hack by KimTaro that will blow your mind.
|
|
74
|
-
// Remove it once this get merged: https://github.com/webpack-contrib/css-loader/pull/523
|
|
75
|
-
css = fontFamilyUnicodeParser(
|
|
76
|
-
memoryFs.readFileSync(`/build/main.css`, "UTF8")
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
// We convert single quotes to double quotes in order to
|
|
80
|
-
// support the viewTemplate's string interpolation
|
|
81
|
-
css = minifyFile(".css", css).replace(/\'/g, '"');
|
|
82
|
-
const cssPath = path.join(publishPath, `styles.css`);
|
|
83
|
-
fs.outputFileSync(cssPath, css);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const reactRoot = `oc-reactRoot-${componentPackage.name}`;
|
|
87
|
-
const templateString = viewTemplate({
|
|
88
|
-
reactRoot,
|
|
89
|
-
css,
|
|
90
|
-
externals,
|
|
91
|
-
bundleHash,
|
|
92
|
-
bundleName
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const templateStringCompressed = production
|
|
96
|
-
? templateString.replace(/\s+/g, " ")
|
|
97
|
-
: templateString;
|
|
98
|
-
const hash = hashBuilder.fromString(templateStringCompressed);
|
|
99
|
-
const view = ocViewWrapper(hash, templateStringCompressed);
|
|
100
|
-
return cb(null, {
|
|
101
|
-
template: { view, hash },
|
|
102
|
-
bundle: { hash: bundleHash }
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
async.waterfall(
|
|
108
|
-
[
|
|
109
|
-
next => fs.outputFile(reactOCProviderPath, reactOCProviderContent, next),
|
|
110
|
-
next => compile({ viewPath: reactOCProviderPath }, next),
|
|
111
|
-
(compiled, next) =>
|
|
112
|
-
fs.remove(reactOCProviderPath, err => next(err, compiled)),
|
|
113
|
-
(compiled, next) => fs.ensureDir(publishPath, err => next(err, compiled)),
|
|
114
|
-
(compiled, next) =>
|
|
115
|
-
fs.writeFile(
|
|
116
|
-
path.join(publishPath, publishFileName),
|
|
117
|
-
compiled.template.view,
|
|
118
|
-
err => next(err, compiled)
|
|
119
|
-
)
|
|
120
|
-
],
|
|
121
|
-
(err, compiled) => {
|
|
122
|
-
if (err) {
|
|
123
|
-
return callback(strings.errors.compilationFailed(viewFileName, err));
|
|
124
|
-
}
|
|
125
|
-
callback(null, {
|
|
126
|
-
template: {
|
|
127
|
-
type: options.componentPackage.oc.files.template.type,
|
|
128
|
-
hashKey: compiled.template.hash,
|
|
129
|
-
src: publishFileName
|
|
130
|
-
},
|
|
131
|
-
bundle: { hashKey: compiled.bundle.hash }
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const higherOrderServerTemplate = ({
|
|
2
|
-
serverPath,
|
|
3
|
-
bundleHashKey,
|
|
4
|
-
componentName,
|
|
5
|
-
componentVersion
|
|
6
|
-
}) => `
|
|
7
|
-
import { data as dataProvider } from '${serverPath}';
|
|
8
|
-
export const data = (context, callback) => {
|
|
9
|
-
dataProvider(context, (error, model) => {
|
|
10
|
-
if (error) {
|
|
11
|
-
return callback(error);
|
|
12
|
-
}
|
|
13
|
-
const props = Object.assign({}, model, {
|
|
14
|
-
_staticPath: context.staticPath,
|
|
15
|
-
_baseUrl: context.baseUrl,
|
|
16
|
-
_componentName: "${componentName}",
|
|
17
|
-
_componentVersion: "${componentVersion}"
|
|
18
|
-
});
|
|
19
|
-
const srcPathHasProtocol = context.staticPath.indexOf("http") === 0;
|
|
20
|
-
const srcPath = srcPathHasProtocol ? context.staticPath : ("https:" + context.staticPath);
|
|
21
|
-
return callback(null, Object.assign({}, {
|
|
22
|
-
reactComponent: {
|
|
23
|
-
key: "${bundleHashKey}",
|
|
24
|
-
src: srcPath + "react-component.js",
|
|
25
|
-
props
|
|
26
|
-
}
|
|
27
|
-
}));
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
|
-
module.exports = higherOrderServerTemplate;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
const reactOCProviderTemplate = ({ viewPath }) => `
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import View from '${viewPath}';
|
|
5
|
-
|
|
6
|
-
class OCProvider extends React.Component {
|
|
7
|
-
componentDidMount(){
|
|
8
|
-
const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = this.props;
|
|
9
|
-
window.oc.events.fire('oc:componentDidMount', rest);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
getChildContext() {
|
|
13
|
-
const getData = (parameters, cb) => {
|
|
14
|
-
return window.oc.getData({
|
|
15
|
-
name: this.props._componentName,
|
|
16
|
-
version: this.props._componentVersion,
|
|
17
|
-
baseUrl: this.props._baseUrl,
|
|
18
|
-
parameters
|
|
19
|
-
}, (err, data) => {
|
|
20
|
-
if (err) {
|
|
21
|
-
return cb(err);
|
|
22
|
-
}
|
|
23
|
-
const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = data.reactComponent.props;
|
|
24
|
-
cb(null, rest, data.reactComponent.props);
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
const getSetting = setting => {
|
|
28
|
-
const settingHash = {
|
|
29
|
-
name: this.props._componentName,
|
|
30
|
-
version: this.props._componentVersion,
|
|
31
|
-
baseUrl: this.props._baseUrl,
|
|
32
|
-
staticPath: this.props._staticPath
|
|
33
|
-
};
|
|
34
|
-
return settingHash[setting];
|
|
35
|
-
};
|
|
36
|
-
return { getData, getSetting };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
render() {
|
|
40
|
-
const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = this.props;
|
|
41
|
-
return (
|
|
42
|
-
<View {...rest} />
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
OCProvider.childContextTypes = {
|
|
48
|
-
getData: PropTypes.func,
|
|
49
|
-
getSetting: PropTypes.func
|
|
50
|
-
};
|
|
51
|
-
export default OCProvider
|
|
52
|
-
`;
|
|
53
|
-
|
|
54
|
-
module.exports = reactOCProviderTemplate;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const RE_FONT_FAMILY = /font-family\s*:\s*([^;\n]+)[;\n]/g;
|
|
2
|
-
const RE_FONT_NAMES = /(?:(?:'|(?:\\"))?([(?:\\\\)\w\d _-]+)(?:'|(?:\\"))?(,\s*)?)/g;
|
|
3
|
-
const RE_DOUBLE_COUTE = /"/g;
|
|
4
|
-
const RE_SPACE = /[ ]+/g;
|
|
5
|
-
const RE_UNICODE = /\\([\d\w]{4})/g;
|
|
6
|
-
|
|
7
|
-
module.exports = function(source) {
|
|
8
|
-
source = source.replace(RE_FONT_FAMILY, (str, fontNames) => {
|
|
9
|
-
const strFontNames = fontNames
|
|
10
|
-
.replace(RE_DOUBLE_COUTE, "'")
|
|
11
|
-
.replace(RE_FONT_NAMES, (match, fontName, sep) => {
|
|
12
|
-
if (match.includes("'")) {
|
|
13
|
-
const replacement = fontName
|
|
14
|
-
.replace(RE_SPACE, " ")
|
|
15
|
-
.replace(RE_UNICODE, (m, unicode) =>
|
|
16
|
-
String.fromCharCode(parseInt(unicode, 16))
|
|
17
|
-
);
|
|
18
|
-
return `'${replacement}'${sep || ""}`;
|
|
19
|
-
}
|
|
20
|
-
return match;
|
|
21
|
-
});
|
|
22
|
-
return `font-family: ${strFontNames};`;
|
|
23
|
-
});
|
|
24
|
-
return source;
|
|
25
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
4
|
-
const MinifyPlugin = require("babel-minify-webpack-plugin");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const webpack = require("webpack");
|
|
7
|
-
const _ = require("lodash");
|
|
8
|
-
|
|
9
|
-
const createExcludeRegex = require("../createExcludeRegex");
|
|
10
|
-
|
|
11
|
-
module.exports = options => {
|
|
12
|
-
const buildPath = options.buildPath || "/build";
|
|
13
|
-
const production = options.production;
|
|
14
|
-
const buildIncludes = options.buildIncludes.concat(
|
|
15
|
-
"oc-template-react-compiler/utils"
|
|
16
|
-
);
|
|
17
|
-
const excludeRegex = createExcludeRegex(buildIncludes);
|
|
18
|
-
const localIdentName = !production
|
|
19
|
-
? "oc__[path][name]-[ext]__[local]__[hash:base64:8]"
|
|
20
|
-
: "[local]__[hash:base64:8]";
|
|
21
|
-
|
|
22
|
-
const cssLoader = {
|
|
23
|
-
test: /\.css$/,
|
|
24
|
-
use: [
|
|
25
|
-
MiniCssExtractPlugin.loader,
|
|
26
|
-
{
|
|
27
|
-
loader: require.resolve("css-loader"),
|
|
28
|
-
options: {
|
|
29
|
-
importLoaders: 1,
|
|
30
|
-
modules: true,
|
|
31
|
-
localIdentName,
|
|
32
|
-
camelCase: true
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
loader: require.resolve("postcss-loader"),
|
|
37
|
-
options: {
|
|
38
|
-
ident: "postcss",
|
|
39
|
-
plugins: [
|
|
40
|
-
require("postcss-import"),
|
|
41
|
-
require("postcss-extend"),
|
|
42
|
-
require("postcss-icss-values"),
|
|
43
|
-
require("autoprefixer")
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
let plugins = [
|
|
51
|
-
new MiniCssExtractPlugin({
|
|
52
|
-
filename: "[name].css",
|
|
53
|
-
allChunks: true,
|
|
54
|
-
ignoreOrder: true
|
|
55
|
-
}),
|
|
56
|
-
new webpack.DefinePlugin({
|
|
57
|
-
"process.env.NODE_ENV": JSON.stringify(
|
|
58
|
-
production ? "production" : "development"
|
|
59
|
-
)
|
|
60
|
-
})
|
|
61
|
-
];
|
|
62
|
-
if (production) {
|
|
63
|
-
plugins = plugins.concat(new MinifyPlugin());
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const cacheDirectory = !production;
|
|
67
|
-
const polyfills = ["Object.assign"];
|
|
68
|
-
|
|
69
|
-
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
|
-
},
|
|
77
|
-
entry: options.viewPath,
|
|
78
|
-
output: {
|
|
79
|
-
path: buildPath,
|
|
80
|
-
filename: options.publishFileName
|
|
81
|
-
},
|
|
82
|
-
externals: _.omit(options.externals, polyfills),
|
|
83
|
-
module: {
|
|
84
|
-
rules: [
|
|
85
|
-
cssLoader,
|
|
86
|
-
{
|
|
87
|
-
test: /\.jsx?$/,
|
|
88
|
-
exclude: excludeRegex,
|
|
89
|
-
use: [
|
|
90
|
-
{
|
|
91
|
-
loader: require.resolve("babel-loader"),
|
|
92
|
-
options: {
|
|
93
|
-
cacheDirectory,
|
|
94
|
-
babelrc: false,
|
|
95
|
-
presets: [
|
|
96
|
-
[
|
|
97
|
-
require.resolve("babel-preset-env"),
|
|
98
|
-
{ modules: false, loose: true }
|
|
99
|
-
],
|
|
100
|
-
[require.resolve("babel-preset-react")]
|
|
101
|
-
],
|
|
102
|
-
plugins: [
|
|
103
|
-
[require.resolve("babel-plugin-transform-object-rest-spread")]
|
|
104
|
-
]
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
]
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
},
|
|
111
|
-
plugins,
|
|
112
|
-
resolve: {
|
|
113
|
-
alias: {
|
|
114
|
-
react: path.join(__dirname, "../../node_modules/react"),
|
|
115
|
-
"react-dom": path.join(__dirname, "../../node_modules/react-dom"),
|
|
116
|
-
"prop-types": path.join(__dirname, "../../node_modules/prop-types")
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/*jshint camelcase:false */
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
const MinifyPlugin = require("babel-minify-webpack-plugin");
|
|
5
|
-
const externalDependenciesHandlers = require("oc-external-dependencies-handler");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
const webpack = require("webpack");
|
|
8
|
-
|
|
9
|
-
module.exports = function webpackConfigGenerator(options) {
|
|
10
|
-
const production =
|
|
11
|
-
options.production !== undefined ? options.production : "true";
|
|
12
|
-
|
|
13
|
-
const sourceMaps = !production;
|
|
14
|
-
const devtool = sourceMaps ? "#source-map" : "";
|
|
15
|
-
|
|
16
|
-
const jsLoaders = [
|
|
17
|
-
{
|
|
18
|
-
loader: require.resolve("babel-loader"),
|
|
19
|
-
options: {
|
|
20
|
-
cacheDirectory: true,
|
|
21
|
-
retainLines: true,
|
|
22
|
-
sourceMaps,
|
|
23
|
-
sourceRoot: path.join(options.serverPath, ".."),
|
|
24
|
-
babelrc: false,
|
|
25
|
-
presets: [
|
|
26
|
-
[
|
|
27
|
-
require.resolve("babel-preset-env"),
|
|
28
|
-
{
|
|
29
|
-
modules: false,
|
|
30
|
-
targets: {
|
|
31
|
-
node: 6
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
],
|
|
35
|
-
[
|
|
36
|
-
require.resolve("babel-preset-react")
|
|
37
|
-
]
|
|
38
|
-
],
|
|
39
|
-
plugins: [
|
|
40
|
-
[require.resolve("babel-plugin-transform-object-rest-spread")]
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
];
|
|
45
|
-
|
|
46
|
-
const plugins = [
|
|
47
|
-
new webpack.DefinePlugin({
|
|
48
|
-
"process.env.NODE_ENV": JSON.stringify(
|
|
49
|
-
production ? "production" : "development"
|
|
50
|
-
)
|
|
51
|
-
})
|
|
52
|
-
];
|
|
53
|
-
|
|
54
|
-
if (production) {
|
|
55
|
-
jsLoaders.unshift({
|
|
56
|
-
loader: require.resolve("infinite-loop-loader")
|
|
57
|
-
});
|
|
58
|
-
plugins.unshift(new MinifyPlugin());
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
mode: production ? "production" : "development",
|
|
63
|
-
optimization: {
|
|
64
|
-
// https://webpack.js.org/configuration/optimization/
|
|
65
|
-
// Override production mode optimization for minification
|
|
66
|
-
// As it currently breakes the build, still rely on babel-minify-webpack-plugin instead
|
|
67
|
-
minimize: false
|
|
68
|
-
},
|
|
69
|
-
devtool,
|
|
70
|
-
entry: options.serverPath,
|
|
71
|
-
target: "node",
|
|
72
|
-
output: {
|
|
73
|
-
path: path.join(options.serverPath, "../build"),
|
|
74
|
-
filename: options.publishFileName,
|
|
75
|
-
libraryTarget: "commonjs2",
|
|
76
|
-
devtoolModuleFilenameTemplate: "[absolute-resource-path]",
|
|
77
|
-
devtoolFallbackModuleFilenameTemplate: "[absolute-resource-path]?[hash]"
|
|
78
|
-
},
|
|
79
|
-
externals: externalDependenciesHandlers(options.dependencies),
|
|
80
|
-
module: {
|
|
81
|
-
rules: [
|
|
82
|
-
{
|
|
83
|
-
test: /\.js$/,
|
|
84
|
-
exclude: /node_modules/,
|
|
85
|
-
use: jsLoaders
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
},
|
|
89
|
-
plugins,
|
|
90
|
-
logger: options.logger || console,
|
|
91
|
-
stats: options.stats
|
|
92
|
-
};
|
|
93
|
-
};
|