Skip to content

Commit 6bfc055

Browse files
committed
initial commit
0 parents  commit 6bfc055

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

LICENSE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright © 2017-present Wolfgang
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

bin/index.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env node
2+
3+
const get = prop => value => value[prop];
4+
const flatten = (others, next) => others.concat(next);
5+
const getLoadersFromRules = (rules, path, loaderName) =>
6+
rules
7+
.filter(get(path))
8+
.map(get(path))
9+
.reduce(flatten, [])
10+
.filter(get("loader"))
11+
.filter(({ loader }) => loader.includes(loaderName));
12+
13+
const script = process.argv[2] || "start";
14+
process.env.NODE_ENV = script === "build" ? "production" : "development";
15+
16+
const webpackConfigPath = `react-scripts/config/webpack.config.${
17+
script === "build" ? "prod" : "dev"
18+
}`;
19+
20+
// load original configs
21+
const webpackConfig = require(webpackConfigPath);
22+
if (!webpackConfig) {
23+
throw new Error(`no Webpack config found for: ${webpackConfigPath}`);
24+
}
25+
const { module: { rules = [] } = {} } = webpackConfig;
26+
27+
const eslintLoaders = getLoadersFromRules(rules, "use", "eslint");
28+
if (!eslintLoaders.length) {
29+
throw new Error(
30+
`missing ESLint config in webpack config: ${webpackConfigPath}`
31+
);
32+
}
33+
const eslintConfig = eslintLoaders[0].options.baseConfig;
34+
35+
const babelLoaders = getLoadersFromRules(rules, "oneOf", "babel");
36+
if (!babelLoaders.length) {
37+
throw new Error(
38+
`missing Babel config in webpack config: ${webpackConfigPath}`
39+
);
40+
}
41+
const babelOptions = babelLoaders[0].options;
42+
43+
// override ESLint rules to allow using JSX with Hyperapp
44+
eslintConfig.rules = Object.assign(eslintConfig.rules || {}, {
45+
"react/react-in-jsx-scope": "off",
46+
"no-unused-vars": [
47+
"warn",
48+
{
49+
varsIgnorePattern: "^h$"
50+
}
51+
]
52+
});
53+
54+
// configure babel to allow using JSX with Hyperapp
55+
babelOptions.plugins = (babelOptions.plugins || []).concat([
56+
["transform-react-jsx", { pragma: "h", useBuiltIns: true }]
57+
]);
58+
59+
// override config in cache
60+
require.cache[require.resolve(webpackConfigPath)].exports = webpackConfig;
61+
62+
// call original react script
63+
require(`react-scripts/scripts/${script}.js`);

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "cra-hyperapp",
3+
"version": "0.0.1",
4+
"description": "Hyperapp expansion pack for create-react-app",
5+
"bin": {
6+
"hyperapp-scripts": "./bin/index.js"
7+
},
8+
"scripts": {
9+
"format": "npx prettier --write **/*.js"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/okwolf/cra-hyperapp.git"
14+
},
15+
"author": "Wolfgang Wedemeyer <wolf@okwolf.com>",
16+
"license": "MIT",
17+
"bugs": {
18+
"url": "https://github.com/okwolf/cra-hyperapp/issues"
19+
},
20+
"homepage": "https://github.com/okwolf/cra-hyperapp"
21+
}

0 commit comments

Comments
 (0)