Skip to content

Commit

Permalink
feat: add output bundle file.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Feb 28, 2022
1 parent e172381 commit 9c22451
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 48 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cjs
esm
build
dist
coverage
node_modules
npm-debug.log*
Expand Down
61 changes: 33 additions & 28 deletions .kktrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,42 @@ import scopePluginOptions from '@kkt/scope-plugin-options';
import pkg from './package.json';

export default (conf: Configuration, env: 'development' | 'production', options: LoaderConfOptions) => {
conf = rawModules(conf, env, { ...options });
conf = scopePluginOptions(conf, env, {
...options,
allowedFiles: [path.resolve(process.cwd(), 'README.md'), path.resolve(process.cwd(), 'src')],
});
conf = lessModules(conf, env, options);
// Get the project version.
conf.plugins!.push(
new webpack.DefinePlugin({
VERSION: JSON.stringify(pkg.version),
}),
);
if (env === 'production') {
conf.optimization = {
...conf.optimization,
splitChunks: {
cacheGroups: {
reactvendor: {
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
name: 'react-vendor',
chunks: 'all',
},
prismjs: {
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
name: 'refractor-vendor',
chunks: 'all',
if (options.bundle) {
conf.output!.library = '@uiw/react-run-web';
conf.externals = ['react'];
} else {
conf = rawModules(conf, env, { ...options });
conf = scopePluginOptions(conf, env, {
...options,
allowedFiles: [path.resolve(process.cwd(), 'README.md'), path.resolve(process.cwd(), 'src')],
});
// Get the project version.
conf.plugins!.push(
new webpack.DefinePlugin({
VERSION: JSON.stringify(pkg.version),
}),
);
if (env === 'production') {
conf.optimization = {
...conf.optimization,
splitChunks: {
cacheGroups: {
reactvendor: {
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
name: 'react-vendor',
chunks: 'all',
},
prismjs: {
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
name: 'refractor-vendor',
chunks: 'all',
},
},
},
},
};
conf.output = { ...conf.output, publicPath: './' };
};
conf.output = { ...conf.output, publicPath: './' };
}
}
return conf;
};
42 changes: 23 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"start": "kkt start --app-src ./website",
"watch": "tsbb watch",
"build": "tsbb build",
"bundle": "ncc build src/index.tsx --target web --filename run-web",
"bundle:min": "ncc build src/index.tsx --target web --filename run-web --minify",
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
"test": "kkt test --env=jsdom --app-src=./website",
"test:coverage": "kkt test --env=jsdom --coverage --app-src=./website"
Expand All @@ -22,6 +24,7 @@
"author": "Kenny Wong <wowohoo@qq.com>",
"license": "MIT",
"files": [
"dist",
"cjs",
"esm",
"src"
Expand Down Expand Up @@ -49,25 +52,26 @@
"react-dom": ">=16.9.0"
},
"devDependencies": {
"@kkt/less-modules": "7.0.5",
"@kkt/raw-modules": "7.0.5",
"@kkt/scope-plugin-options": "7.0.5",
"@types/react": "17.0.38",
"@types/react-dom": "17.0.11",
"@types/react-test-renderer": "17.0.1",
"@uiw/react-github-corners": "1.5.3",
"@uiw/react-markdown-preview": "3.4.7",
"@uiw/react-split": "5.8.5",
"@uiw/react-textarea-code-editor": "1.4.15",
"husky": "7.0.4",
"kkt": "7.0.5",
"lint-staged": "12.1.7",
"prettier": "2.5.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-router-dom": "6.2.1",
"react-test-renderer": "17.0.2",
"tsbb": "3.5.4"
"@kkt/less-modules": "~7.1.1",
"@kkt/ncc": "~1.0.8",
"@kkt/raw-modules": "~7.1.1",
"@kkt/scope-plugin-options": "~7.1.1",
"@types/react": "~17.0.39",
"@types/react-dom": "~17.0.11",
"@types/react-test-renderer": "~17.0.1",
"@uiw/react-github-corners": "~1.5.3",
"@uiw/react-markdown-preview": "~3.4.7",
"@uiw/react-split": "~5.8.7",
"@uiw/react-textarea-code-editor": "~1.5.1",
"husky": "~7.0.4",
"kkt": "~7.1.5",
"lint-staged": "~12.3.4",
"prettier": "~2.5.1",
"react": "~17.0.2",
"react-dom": "~17.0.2",
"react-router-dom": "~6.2.1",
"react-test-renderer": "~17.0.2",
"tsbb": "~3.7.0"
},
"eslintConfig": {
"extends": [
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"resolveJsonModule": true,
"isolatedModules": true,
"declaration": true,
"baseUrl": "website",
"jsx": "react-jsx",
"noFallthroughCasesInSwitch": true,
"noEmit": true
Expand Down

0 comments on commit 9c22451

Please sign in to comment.