Skip to content

Commit 197280f

Browse files
committed
feat: output bundle file.
1 parent a107bd5 commit 197280f

File tree

3 files changed

+80
-61
lines changed

3 files changed

+80
-61
lines changed

.kktrc.ts

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,55 @@
11
import path from 'path';
2-
import webpack, { Configuration } from 'webpack';
3-
import { LoaderConfOptions } from 'kkt';
2+
import webpack from 'webpack';
3+
import { LoaderConfOptions, WebpackConfiguration } from 'kkt';
44
import lessModules from '@kkt/less-modules';
55
import rawModules from '@kkt/raw-modules';
66
import scopePluginOptions from '@kkt/scope-plugin-options';
77
import pkg from './package.json';
88

9-
export default (conf: Configuration, env: string, options: LoaderConfOptions) => {
10-
conf = rawModules(conf, env, { ...options });
9+
export default (conf: WebpackConfiguration, env: 'production' | 'development', options: LoaderConfOptions) => {
1110
conf = lessModules(conf, env, options);
12-
conf = scopePluginOptions(conf, env, {
13-
...options,
14-
allowedFiles: [path.resolve(process.cwd(), 'README.md')],
15-
});
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.output = { ...conf.output, publicPath: './' };
24-
conf.optimization = {
25-
...conf.optimization,
26-
splitChunks: {
27-
cacheGroups: {
28-
reactvendor: {
29-
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
30-
name: 'react-vendor',
31-
chunks: 'all',
32-
},
33-
prismjs: {
34-
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
35-
name: 'refractor-vendor',
36-
chunks: 'all',
37-
},
38-
},
11+
if (options.bundle) {
12+
conf.output!.library = '@uiw/react-markdown-preview';
13+
conf.externals = {
14+
react: {
15+
root: 'React',
16+
commonjs2: 'react',
17+
commonjs: 'react',
18+
amd: 'react',
3919
},
4020
};
21+
} else {
22+
conf = rawModules(conf, env, { ...options });
23+
conf = scopePluginOptions(conf, env, {
24+
...options,
25+
allowedFiles: [path.resolve(process.cwd(), 'README.md')],
26+
});
27+
// Get the project version.
28+
conf.plugins!.push(
29+
new webpack.DefinePlugin({
30+
VERSION: JSON.stringify(pkg.version),
31+
}),
32+
);
33+
if (env === 'production') {
34+
conf.output = { ...conf.output, publicPath: './' };
35+
conf.optimization = {
36+
...conf.optimization,
37+
splitChunks: {
38+
cacheGroups: {
39+
reactvendor: {
40+
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
41+
name: 'react-vendor',
42+
chunks: 'all',
43+
},
44+
prismjs: {
45+
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
46+
name: 'refractor-vendor',
47+
chunks: 'all',
48+
},
49+
},
50+
},
51+
};
52+
}
4153
}
4254

4355
return conf;

package.json

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"css:build": "compile-less -d src -o esm",
1313
"css:watch": "compile-less -d src -o esm --watch",
1414
"css:build:dist": "compile-less -d src --combine markdown.css --rm-global",
15+
"bundle": "ncc build src/index.tsx --target web --filename markdown",
16+
"bundle:min": "ncc build src/index.tsx --target web --filename markdown --minify",
1517
"watch": "tsbb watch & npm run css:watch",
1618
"build": "tsbb build && npm run css:build && npm run css:build:dist",
1719
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
@@ -26,6 +28,7 @@
2628
"author": "kenny wang <[email protected]>",
2729
"license": "MIT",
2830
"files": [
31+
"dist",
2932
"lib",
3033
"esm",
3134
"markdown.css",
@@ -38,6 +41,10 @@
3841
"react-markdown"
3942
],
4043
"jest": {
44+
"coverageReporters": [
45+
"lcov",
46+
"json-summary"
47+
],
4148
"transformIgnorePatterns": [
4249
"<rootDir>/node_modules/?!(.*)"
4350
]
@@ -47,37 +54,38 @@
4754
"react-dom": ">=16.8.0"
4855
},
4956
"dependencies": {
50-
"@babel/runtime": "7.16.7",
51-
"@mapbox/rehype-prism": "0.8.0",
52-
"@uiw/copy-to-clipboard": "1.0.12",
53-
"react-markdown": "7.1.2",
54-
"rehype-attr": "2.0.7",
55-
"rehype-autolink-headings": "6.1.1",
56-
"rehype-raw": "6.1.1",
57-
"rehype-rewrite": "3.0.4",
58-
"rehype-slug": "5.0.1",
59-
"remark-gfm": "3.0.1"
57+
"@babel/runtime": "^7.17.2",
58+
"@mapbox/rehype-prism": "~0.8.0",
59+
"@uiw/copy-to-clipboard": "~1.0.12",
60+
"react-markdown": "~8.0.0",
61+
"rehype-attr": "~2.0.7",
62+
"rehype-autolink-headings": "~6.1.1",
63+
"rehype-raw": "~6.1.1",
64+
"rehype-rewrite": "~3.0.4",
65+
"rehype-slug": "~5.0.1",
66+
"remark-gfm": "~3.0.1"
6067
},
6168
"devDependencies": {
62-
"@kkt/less-modules": "7.0.5",
63-
"@kkt/raw-modules": "7.0.5",
64-
"@kkt/scope-plugin-options": "7.0.5",
65-
"@types/react": "17.0.38",
66-
"@types/react-dom": "17.0.11",
67-
"@types/react-test-renderer": "17.0.1",
68-
"@uiw/react-codesandbox": "1.1.4",
69-
"@uiw/react-github-corners": "1.5.3",
70-
"@uiw/react-shields": "1.1.2",
71-
"@uiw/reset.css": "1.0.5",
72-
"compile-less-cli": "1.8.11",
73-
"husky": "7.0.4",
74-
"kkt": "7.0.5",
75-
"prettier": "2.5.1",
76-
"pretty-quick": "3.1.3",
77-
"react": "17.0.2",
78-
"react-dom": "17.0.2",
79-
"react-test-renderer": "17.0.2",
80-
"tsbb": "3.5.4"
69+
"@kkt/less-modules": "~7.1.1",
70+
"@kkt/ncc": "~1.0.8",
71+
"@kkt/raw-modules": "~7.1.1",
72+
"@kkt/scope-plugin-options": "~7.1.1",
73+
"@types/react": "~17.0.39",
74+
"@types/react-dom": "~17.0.11",
75+
"@types/react-test-renderer": "~17.0.1",
76+
"@uiw/react-codesandbox": "~1.1.4",
77+
"@uiw/react-github-corners": "~1.5.3",
78+
"@uiw/react-shields": "~1.1.2",
79+
"@uiw/reset.css": "~1.0.5",
80+
"compile-less-cli": "~1.8.11",
81+
"husky": "~7.0.4",
82+
"kkt": "~7.1.5",
83+
"prettier": "~2.5.1",
84+
"pretty-quick": "~3.1.3",
85+
"react": "~17.0.2",
86+
"react-dom": "~17.0.2",
87+
"react-test-renderer": "~17.0.2",
88+
"tsbb": "~3.7.0"
8189
},
8290
"eslintConfig": {
8391
"extends": "react-app"

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)