Skip to content

Commit

Permalink
fix: fix #412
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed May 27, 2023
1 parent 122f9da commit 40b5b73
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ jobs:
env:
NODE_AUTH_TOKEN: '${{ secrets.NPM_TOKEN }}'

- name: 📦 @kkt/resolve-fallback publish to NPM
run: npm publish --access public
working-directory: packages/resolve-fallback
continue-on-error: true
env:
NODE_AUTH_TOKEN: '${{ secrets.NPM_TOKEN }}'

- name: Compress uiw Example.
working-directory: zip
run: |
Expand Down
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
},
"dependencies": {
"@babel/register": "~7.17.7",
"@kkt/resolve-fallback": "^7.4.10",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^14.0.0",
Expand All @@ -55,7 +56,6 @@
"fs-extra": "~10.1.0",
"minimist": "~1.2.6",
"mocker-api": "~2.9.5",
"path-browserify": "^1.0.1",
"postcss": "^8.4.4",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-loader": "^6.2.1",
Expand Down
2 changes: 2 additions & 0 deletions core/src/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
process.env.NODE_ENV = 'production';

import { Configuration } from 'webpack';
import resolveFallback from '@kkt/resolve-fallback';
import { KKTRC, WebpackConfiguration, loaderConf } from '../utils/loaderConf';
import { reactScripts, isWebpackFactory, getConfPath } from '../utils/path';
import { overridePaths } from '../overrides/paths';
Expand Down Expand Up @@ -30,6 +31,7 @@ export default async function build(argvs: BuildArgs) {
};
let defaultWepack: WebpackConfiguration = createWebpackConfig('production');
defaultWepack = loadSourceMapWarnning(defaultWepack);
defaultWepack = resolveFallback(defaultWepack);
defaultWepack = miniCssExtractPlugin(defaultWepack, 'production');
defaultWepack = argvs.overridesWebpack
? argvs.overridesWebpack(defaultWepack, 'production', overrideOption)
Expand Down
2 changes: 2 additions & 0 deletions core/src/scripts/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import WebpackDevServer from 'webpack-dev-server';
import evalSourceMapMiddleware from 'react-dev-utils/evalSourceMapMiddleware';
import redirectServedPath from 'react-dev-utils/redirectServedPathMiddleware';
import clearConsole from 'react-dev-utils/clearConsole';
import resolveFallback from '@kkt/resolve-fallback';
import noopServiceWorkerMiddleware from 'react-dev-utils/noopServiceWorkerMiddleware';
import { KKTRC, DevServerConfigFunction, WebpackConfiguration, loaderConf } from '../utils/loaderConf';
import { reactScripts, isWebpackFactory, proxySetup, getConfPath } from '../utils/path';
Expand Down Expand Up @@ -60,6 +61,7 @@ export default async function start(argvs: StartArgs) {
: webpackConf;
webpackConf = loadSourceMapWarnning(webpackConf);
webpackConf = miniCssExtractPlugin(webpackConf, 'development');
webpackConf = resolveFallback(webpackConf);
if (overridesHandle && typeof overridesHandle === 'function') {
const overrideWebpackConf = kktrc.default
? await overridesHandle(webpackConf, 'development', overrideOption)
Expand Down
21 changes: 21 additions & 0 deletions packages/resolve-fallback/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<p align="center">
<a href="https://github.com/kktjs/kkt">
<img src="https://raw.githubusercontent.com/kktjs/kkt/d2bb00dc2d0bd9bb133f3a369d0ad2f5330ed4af/website/kkt.svg?sanitize=true" alt="KKT LOGO">
</a>
</p>

<p align="center">
<h1>@kkt/resolve-fallback</h1>
</p>

<p align="center">
<a href="https://www.npmjs.com/package/@kkt/resolve-fallback">
<img src="https://img.shields.io/npm/v/@kkt/resolve-fallback.svg" alt="npm version">
</a>
</p>

fix: https://github.com/kktjs/kkt/issues/412

### License

Licensed under the MIT License
34 changes: 34 additions & 0 deletions packages/resolve-fallback/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@kkt/resolve-fallback",
"version": "7.4.10",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"description": "This will modify the CRA ModuleScopePlugin plugin that prevents to import modules from outside the `src` directory.",
"author": "Kenny Wong <[email protected]> (https://github.com/jaywcjlove)",
"repository": "https://github.com/kktjs/kkt.git",
"keywords": [
"kkt",
"react",
"framework"
],
"license": "MIT",
"files": [
"lib",
"src"
],
"scripts": {
"watch": "tsbb watch --no-esm"
},
"devDependencies": {
"kkt": "^7.4.10"
},
"dependencies": {
"assert": "^2.0.0",
"crypto-browserify": "^3.12.0",
"https-browserify": "^1.0.0",
"os-browserify": "^0.3.0",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"url": "^0.11.0"
}
}
23 changes: 23 additions & 0 deletions packages/resolve-fallback/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import webpack, { Configuration } from 'webpack';

export default function resolveFallback(conf: Configuration): Configuration {
if (!conf) {
throw Error('KKT:@kkt/resolve-fallback: there is no config found');
}
conf.resolve.fallback = Object.assign(conf.resolve.fallback || {}, {
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
assert: require.resolve('assert'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
os: require.resolve('os-browserify'),
url: require.resolve('url'),
});
conf.plugins = (conf.plugins || []).concat([
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
}),
]);
return conf;
}
16 changes: 16 additions & 0 deletions packages/resolve-fallback/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"skipLibCheck": true,
"declaration": true,
"target": "es2017",
"noImplicitAny": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "lib",
"baseUrl": "./"
},
"include": ["src"]
}

0 comments on commit 40b5b73

Please sign in to comment.