Skip to content

Commit

Permalink
feat: Add isNotCheckHTML& overridePaths options.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Feb 22, 2022
1 parent 1bac5e7 commit 64d26fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 5 additions & 1 deletion packages/react-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"keywords": [
"kkt",
"react",
"framework"
"framework",
"cra",
"build-tools",
"create-react-app",
"zero-configuration"
],
"license": "MIT",
"files": [
Expand Down
22 changes: 15 additions & 7 deletions packages/react-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path';
import fs from 'fs-extra';
import { Configuration } from 'webpack';
import CssMinimizerPlugin, { BasePluginOptions, DefinedDefaultMinimizerAndOptions } from 'css-minimizer-webpack-plugin';
import { overridePaths, LoaderConfOptions, MiniCssExtractPlugin } from 'kkt';
import { overridePaths, Paths, LoaderConfOptions, MiniCssExtractPlugin } from 'kkt';
import './overridesCheckRequiredFiles';
import { checkRequiredFiles } from './checkRequiredFiles';
import TerserPlugin, {
Expand All @@ -14,7 +14,9 @@ export type ReactLibraryOptions = LoaderConfOptions & {
mini?: boolean;
name?: string;
module?: string;
main?: string;
isNotCheckHTML?: boolean;
overridePaths?: Partial<Paths>;
main: string;
outputDir?: string;
dependencies?: Configuration['externals'];
cssMinimizerPluginOptions?: BasePluginOptions & DefinedDefaultMinimizerAndOptions<any>;
Expand Down Expand Up @@ -46,21 +48,25 @@ process.on('beforeExit', () => {
});

export default (conf: Configuration, env: string, options = {} as ReactLibraryOptions): Configuration => {
const { isNotCheckHTML = false } = options;
if (!conf) {
throw Error('KKT:ConfigPaths: there is no config file found');
}
if (!options.main) {
throw Error('KKT:ConfigPaths: main Required option.');
}
if (!options.bundle && options.paths) {
/**
* Remove validation first, then add validation
* Warn and crash if required files are missing
*/
if (!checkRequiredFiles([options.paths.appHtml, options.paths.appIndexJs], false)) {
if (!checkRequiredFiles([options.paths.appHtml, options.paths.appIndexJs], isNotCheckHTML)) {
process.exit(1);
}
}

if (options.bundle) {
if (options.paths.appPath) {
if (options.paths && options.paths.appPath) {
publicPath = path.join(options.paths.appPath, 'public');
if (fs.existsSync(publicPath)) {
publicPath = '';
Expand All @@ -73,9 +79,9 @@ export default (conf: Configuration, env: string, options = {} as ReactLibraryOp

/** 确保缓存目录存在 */
fs.ensureDirSync(buildCacheDir);
overridePaths(undefined, { appBuild: buildCacheDir });
overridePaths(undefined, { appBuild: buildCacheDir, ...options.overridePaths });

const libraryName = path.basename(options.name);
const libraryName = path.basename(options.name || '');
const entryFile = options.module;
const outFile = path.basename(options.main);
let minfilename = outFile.split('.');
Expand All @@ -85,12 +91,14 @@ export default (conf: Configuration, env: string, options = {} as ReactLibraryOp
conf.entry = path.resolve(entryFile);
conf.devtool = false;
conf.output = {
library: libraryName,
// commonjs
libraryTarget: 'umd',
filename: outFile,
path: buildCacheDir,
};
if (libraryName) {
conf.output.library = libraryName;
}
conf.externals = options.dependencies;
/**
* Clear all plugins from CRA webpack conf
Expand Down

0 comments on commit 64d26fa

Please sign in to comment.