Skip to content

Commit 79b51c2

Browse files
authored
Merge pull request #40 from fs-webdev/hf
Support for HF
2 parents 63cb39a + ef7000e commit 79b51c2

File tree

4 files changed

+1738
-83
lines changed

4 files changed

+1738
-83
lines changed

packages/react-scripts/config/webpack.config.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const getClientEnvironment = require('./env');
3131
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
3232
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin-alt');
3333
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
34+
const CopyWebpackPlugin = require('copy-webpack-plugin');
35+
3436
// @remove-on-eject-begin
3537
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
3638
// @remove-on-eject-end
@@ -44,6 +46,9 @@ const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
4446
// Check if TypeScript is setup
4547
const useTypeScript = fs.existsSync(paths.appTsConfig);
4648

49+
// FS - check if hf is installed in root node_modules
50+
const isHF = fs.existsSync(path.join(paths.appNodeModules, 'hf/webpack.config.js'));
51+
4752
// style files regexes
4853
const cssRegex = /\.css$/;
4954
const cssModuleRegex = /\.module\.css$/;
@@ -237,12 +242,15 @@ module.exports = function(webpackEnv) {
237242
// https://twitter.com/wSokra/status/969633336732905474
238243
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
239244
splitChunks: {
240-
chunks: 'all',
245+
// FS - split chunks was causing issues for webpacked hf build, async fixes it so that it doesn't
246+
// try to use the same chunks for async/non-async assets
247+
chunks: isHF ? 'async' : 'all',
241248
name: false,
242249
},
243250
// Keep the runtime chunk separated to enable long term caching
244251
// https://twitter.com/wSokra/status/969679223278505985
245-
runtimeChunk: true,
252+
// FS - Turn off for hf since it causes issues with imports in hf js files.
253+
runtimeChunk: !isHF,
246254
},
247255
resolve: {
248256
// This allows you to set a fallback for where Webpack should look for modules.
@@ -512,12 +520,23 @@ module.exports = function(webpackEnv) {
512520
],
513521
},
514522
plugins: [
523+
// FS - copy over hf's webpack built files to /static/hf directory to be
524+
// used by snow.
525+
isHF &&
526+
new CopyWebpackPlugin([
527+
{
528+
from: path.join(paths.appNodeModules, `hf/dist/${isEnvProduction ? 'prod' : 'dev'}`),
529+
to: 'static/hf/[name].[ext]',
530+
toType: 'template',
531+
},
532+
]),
515533
// Generates an `index.html` file with the <script> injected.
516534
new HtmlWebpackPlugin(
517535
Object.assign(
518536
{},
519537
{
520538
inject: true,
539+
filename: isHF ? '_index.html' : 'index.html',
521540
template: paths.appHtml,
522541
},
523542
isEnvProduction

packages/react-scripts/config/webpackDevServer.config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMi
1414
const ignoredFiles = require('react-dev-utils/ignoredFiles');
1515
const paths = require('./paths');
1616
const fs = require('fs');
17+
const path = require('path');
1718

1819
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
1920
const host = process.env.HOST || '0.0.0.0';
2021

22+
const isHF = fs.existsSync(path.join(paths.appNodeModules, 'hf/webpack.config.js'));
23+
2124
module.exports = function(proxy, allowedHost) {
2225
return {
2326
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
@@ -36,8 +39,7 @@ module.exports = function(proxy, allowedHost) {
3639
// So we will disable the host check normally, but enable it if you have
3740
// specified the `proxy` setting. Finally, we let you override it if you
3841
// really know what you're doing with a special environment variable.
39-
disableHostCheck:
40-
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
42+
disableHostCheck: !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
4143
// Enable gzip compression of generated files.
4244
compress: true,
4345
// Silence WebpackDevServer's own logs since they're generally not useful.
@@ -108,5 +110,8 @@ module.exports = function(proxy, allowedHost) {
108110
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
109111
app.use(noopServiceWorkerMiddleware());
110112
},
113+
// FS - write to disk so that snow can serve assets
114+
// looking them up with the manifestMap provided by hf
115+
writeToDisk: isHF,
111116
};
112117
};

0 commit comments

Comments
 (0)