Skip to content

Commit 84069cf

Browse files
committed
feat: output bundle file.
1 parent 7456983 commit 84069cf

File tree

3 files changed

+71
-57
lines changed

3 files changed

+71
-57
lines changed

.kktrc.ts

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,54 @@ 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, test: /\.(txt|md)$/i });
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-
refractor: {
33-
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
34-
name: 'refractor-vendor',
35-
chunks: 'all',
36-
},
37-
codeexample: {
38-
test: /[\\/]node_modules[\\/](code-example)[\\/]/,
39-
name: 'code-example-vendor',
40-
chunks: 'async',
41-
},
42-
},
11+
if (options.bundle) {
12+
conf.output!.library = '@uiw/react-textarea-code-editor';
13+
conf.externals = {
14+
react: {
15+
root: 'React',
16+
commonjs2: 'react',
17+
commonjs: 'react',
18+
amd: 'react',
4319
},
4420
};
45-
conf.output = { ...conf.output, publicPath: './' };
21+
} else {
22+
conf = rawModules(conf, env, { ...options, test: /\.(txt|md)$/i });
23+
conf = scopePluginOptions(conf, env, {
24+
...options,
25+
allowedFiles: [path.resolve(process.cwd(), 'README.md'), path.resolve(process.cwd(), 'src')],
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.optimization = {
35+
...conf.optimization,
36+
splitChunks: {
37+
cacheGroups: {
38+
reactvendor: {
39+
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
40+
name: 'react-vendor',
41+
chunks: 'all',
42+
},
43+
refractor: {
44+
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
45+
name: 'refractor-vendor',
46+
chunks: 'all',
47+
},
48+
codeexample: {
49+
test: /[\\/]node_modules[\\/](code-example)[\\/]/,
50+
name: 'code-example-vendor',
51+
chunks: 'async',
52+
},
53+
},
54+
},
55+
};
56+
conf.output = { ...conf.output, publicPath: './' };
57+
}
4658
}
4759
return conf;
4860
};

package.json

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"css:build": "compile-less -d src -o esm",
1515
"css:watch": "compile-less -d src -o esm --watch",
1616
"css:build:dist": "compile-less -d src --combine dist.css --rm-global",
17+
"bundle": "ncc build src/index.tsx --target web --filename heat-map",
18+
"bundle:min": "ncc build src/index.tsx --target web --filename heat-map --minify",
1719
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,css,md,json}\"",
1820
"test": "kkt test --env=jsdom --app-src=./website",
1921
"test:coverage": "kkt test --env=jsdom --coverage --app-src=./website --bail"
@@ -65,30 +67,31 @@
6567
"react-dom": ">=16.9.0"
6668
},
6769
"dependencies": {
68-
"@babel/runtime": "7.16.7",
69-
"@mapbox/rehype-prism": "0.8.0",
70-
"rehype": "12.0.0"
70+
"@babel/runtime": "~7.17.2",
71+
"@mapbox/rehype-prism": "~0.8.0",
72+
"rehype": "~12.0.1"
7173
},
7274
"devDependencies": {
73-
"@kkt/less-modules": "7.0.7",
74-
"@kkt/raw-modules": "7.0.7",
75-
"@kkt/scope-plugin-options": "7.0.7",
76-
"@types/react": "17.0.39",
77-
"@types/react-dom": "17.0.11",
78-
"@types/react-test-renderer": "17.0.1",
79-
"@uiw/react-github-corners": "1.5.3",
80-
"@uiw/react-markdown-preview": "3.4.7",
81-
"@uiw/react-loader": "4.10.3",
82-
"code-example": "3.3.1",
83-
"compile-less-cli": "1.8.11",
84-
"husky": "7.0.4",
85-
"kkt": "7.0.7",
86-
"lint-staged": "12.3.3",
87-
"prettier": "2.5.1",
88-
"react": "17.0.2",
89-
"react-dom": "17.0.2",
90-
"react-test-renderer": "17.0.2",
91-
"tsbb": "3.5.5"
75+
"@kkt/less-modules": "~7.1.1",
76+
"@kkt/ncc": "~1.0.8",
77+
"@kkt/raw-modules": "~7.1.1",
78+
"@kkt/scope-plugin-options": "~7.1.1",
79+
"@types/react": "~17.0.39",
80+
"@types/react-dom": "~17.0.11",
81+
"@types/react-test-renderer": "~17.0.1",
82+
"@uiw/react-github-corners": "~1.5.3",
83+
"@uiw/react-markdown-preview": "~3.4.7",
84+
"@uiw/react-loader": "~4.12.2",
85+
"code-example": "~3.3.1",
86+
"compile-less-cli": "~1.8.11",
87+
"husky": "~7.0.4",
88+
"kkt": "~7.1.5",
89+
"lint-staged": "~12.3.4",
90+
"prettier": "~2.5.1",
91+
"react": "~17.0.2",
92+
"react-dom": "~17.0.2",
93+
"react-test-renderer": "~17.0.2",
94+
"tsbb": "~3.7.0"
9295
},
9396
"eslintConfig": {
9497
"extends": [

tsconfig.json

Lines changed: 1 addition & 2 deletions
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
"noUnusedLocals": true,
@@ -23,5 +22,5 @@
2322
"forceConsistentCasingInFileNames": true,
2423
"noEmit": true
2524
},
26-
"include": ["src", "website", ".kktrc.ts", "react-app-env.d.ts"]
25+
"include": ["src", "website", ".kktrc.ts"]
2726
}

0 commit comments

Comments
 (0)