Skip to content

Commit 9c22451

Browse files
committed
feat: add output bundle file.
1 parent e172381 commit 9c22451

File tree

4 files changed

+57
-48
lines changed

4 files changed

+57
-48
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cjs
22
esm
33
build
4+
dist
45
coverage
56
node_modules
67
npm-debug.log*

.kktrc.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,42 @@ import scopePluginOptions from '@kkt/scope-plugin-options';
77
import pkg from './package.json';
88

99
export default (conf: Configuration, env: 'development' | 'production', options: LoaderConfOptions) => {
10-
conf = rawModules(conf, env, { ...options });
11-
conf = scopePluginOptions(conf, env, {
12-
...options,
13-
allowedFiles: [path.resolve(process.cwd(), 'README.md'), path.resolve(process.cwd(), 'src')],
14-
});
1510
conf = lessModules(conf, env, options);
16-
// Get the project version.
17-
conf.plugins!.push(
18-
new webpack.DefinePlugin({
19-
VERSION: JSON.stringify(pkg.version),
20-
}),
21-
);
22-
if (env === 'production') {
23-
conf.optimization = {
24-
...conf.optimization,
25-
splitChunks: {
26-
cacheGroups: {
27-
reactvendor: {
28-
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
29-
name: 'react-vendor',
30-
chunks: 'all',
31-
},
32-
prismjs: {
33-
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
34-
name: 'refractor-vendor',
35-
chunks: 'all',
11+
if (options.bundle) {
12+
conf.output!.library = '@uiw/react-run-web';
13+
conf.externals = ['react'];
14+
} else {
15+
conf = rawModules(conf, env, { ...options });
16+
conf = scopePluginOptions(conf, env, {
17+
...options,
18+
allowedFiles: [path.resolve(process.cwd(), 'README.md'), path.resolve(process.cwd(), 'src')],
19+
});
20+
// Get the project version.
21+
conf.plugins!.push(
22+
new webpack.DefinePlugin({
23+
VERSION: JSON.stringify(pkg.version),
24+
}),
25+
);
26+
if (env === 'production') {
27+
conf.optimization = {
28+
...conf.optimization,
29+
splitChunks: {
30+
cacheGroups: {
31+
reactvendor: {
32+
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
33+
name: 'react-vendor',
34+
chunks: 'all',
35+
},
36+
prismjs: {
37+
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
38+
name: 'refractor-vendor',
39+
chunks: 'all',
40+
},
3641
},
3742
},
38-
},
39-
};
40-
conf.output = { ...conf.output, publicPath: './' };
43+
};
44+
conf.output = { ...conf.output, publicPath: './' };
45+
}
4146
}
4247
return conf;
4348
};

package.json

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"start": "kkt start --app-src ./website",
1212
"watch": "tsbb watch",
1313
"build": "tsbb build",
14+
"bundle": "ncc build src/index.tsx --target web --filename run-web",
15+
"bundle:min": "ncc build src/index.tsx --target web --filename run-web --minify",
1416
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
1517
"test": "kkt test --env=jsdom --app-src=./website",
1618
"test:coverage": "kkt test --env=jsdom --coverage --app-src=./website"
@@ -22,6 +24,7 @@
2224
"author": "Kenny Wong <[email protected]>",
2325
"license": "MIT",
2426
"files": [
27+
"dist",
2528
"cjs",
2629
"esm",
2730
"src"
@@ -49,25 +52,26 @@
4952
"react-dom": ">=16.9.0"
5053
},
5154
"devDependencies": {
52-
"@kkt/less-modules": "7.0.5",
53-
"@kkt/raw-modules": "7.0.5",
54-
"@kkt/scope-plugin-options": "7.0.5",
55-
"@types/react": "17.0.38",
56-
"@types/react-dom": "17.0.11",
57-
"@types/react-test-renderer": "17.0.1",
58-
"@uiw/react-github-corners": "1.5.3",
59-
"@uiw/react-markdown-preview": "3.4.7",
60-
"@uiw/react-split": "5.8.5",
61-
"@uiw/react-textarea-code-editor": "1.4.15",
62-
"husky": "7.0.4",
63-
"kkt": "7.0.5",
64-
"lint-staged": "12.1.7",
65-
"prettier": "2.5.1",
66-
"react": "17.0.2",
67-
"react-dom": "17.0.2",
68-
"react-router-dom": "6.2.1",
69-
"react-test-renderer": "17.0.2",
70-
"tsbb": "3.5.4"
55+
"@kkt/less-modules": "~7.1.1",
56+
"@kkt/ncc": "~1.0.8",
57+
"@kkt/raw-modules": "~7.1.1",
58+
"@kkt/scope-plugin-options": "~7.1.1",
59+
"@types/react": "~17.0.39",
60+
"@types/react-dom": "~17.0.11",
61+
"@types/react-test-renderer": "~17.0.1",
62+
"@uiw/react-github-corners": "~1.5.3",
63+
"@uiw/react-markdown-preview": "~3.4.7",
64+
"@uiw/react-split": "~5.8.7",
65+
"@uiw/react-textarea-code-editor": "~1.5.1",
66+
"husky": "~7.0.4",
67+
"kkt": "~7.1.5",
68+
"lint-staged": "~12.3.4",
69+
"prettier": "~2.5.1",
70+
"react": "~17.0.2",
71+
"react-dom": "~17.0.2",
72+
"react-router-dom": "~6.2.1",
73+
"react-test-renderer": "~17.0.2",
74+
"tsbb": "~3.7.0"
7175
},
7276
"eslintConfig": {
7377
"extends": [

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"resolveJsonModule": true,
1414
"isolatedModules": true,
1515
"declaration": true,
16-
"baseUrl": "website",
1716
"jsx": "react-jsx",
1817
"noFallthroughCasesInSwitch": true,
1918
"noEmit": true

0 commit comments

Comments
 (0)