Skip to content

Commit ba01097

Browse files
committed
feat: Add bundled version. #267
1 parent 0d49d00 commit ba01097

File tree

4 files changed

+80
-47
lines changed

4 files changed

+80
-47
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
- run: npm install
2727
- run: npm run build
2828
- run: npm run coverage
29+
- run: npm run bundle
30+
- run: npm run bundle:min
2931
- run: npm run doc
3032

3133
- run: npm i coverage-badges-cli -g

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build
2+
dist
23
cjs
34
esm
45
node_modules

.kktrc.ts

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,76 @@ import webpack, { Configuration } from 'webpack';
33
import { LoaderConfOptions } from 'kkt';
44
import lessModules from '@kkt/less-modules';
55
import rawModules from '@kkt/raw-modules';
6+
import reactLibrary from '@kkt/react-library';
67
import scopePluginOptions from '@kkt/scope-plugin-options';
78
import pkg from './package.json';
89

910
export default (conf: Configuration, env: 'development' | 'production', options: LoaderConfOptions) => {
10-
conf = rawModules(conf, env, {
11-
...options,
12-
test: /\.(txt|md)$/i,
13-
esModule: true,
14-
});
15-
conf = scopePluginOptions(conf, env, {
16-
...options,
17-
allowedFiles: [path.resolve(process.cwd(), 'src'), path.resolve(process.cwd(), 'README.md')],
18-
});
19-
conf = lessModules(conf, env, options);
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-
refractor: {
37-
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
38-
name: 'refractor-vendor',
39-
chunks: 'all',
40-
},
41-
codemirror: {
42-
test: /[\\/]node_modules[\\/](@codemirror)[\\/]/,
43-
name: 'codemirror-vendor',
44-
chunks: 'all',
45-
},
11+
if (options.bundle) {
12+
conf = lessModules(conf, env, options);
13+
conf = reactLibrary(conf, env, {
14+
...options,
15+
...pkg,
16+
name: 'codemirror',
17+
main: 'dist/codemirror.js',
18+
// webpack externals options
19+
dependencies: {
20+
react: {
21+
root: 'React',
22+
commonjs2: 'react',
23+
commonjs: 'react',
24+
amd: 'react',
25+
},
26+
'react-dom': {
27+
root: 'ReactDOM',
28+
commonjs2: 'react-dom',
29+
commonjs: 'react-dom',
30+
amd: 'react-dom',
4631
},
4732
},
48-
};
49-
conf.output = { ...conf.output, publicPath: './' };
33+
});
34+
} else {
35+
conf = rawModules(conf, env, {
36+
...options,
37+
test: /\.(txt|md)$/i,
38+
esModule: true,
39+
});
40+
conf = scopePluginOptions(conf, env, {
41+
...options,
42+
allowedFiles: [path.resolve(process.cwd(), 'src'), path.resolve(process.cwd(), 'README.md')],
43+
});
44+
conf = lessModules(conf, env, options);
45+
// Get the project version.
46+
conf.plugins!.push(
47+
new webpack.DefinePlugin({
48+
VERSION: JSON.stringify(pkg.version),
49+
}),
50+
);
51+
if (env === 'production') {
52+
conf.optimization = {
53+
...conf.optimization,
54+
splitChunks: {
55+
cacheGroups: {
56+
reactvendor: {
57+
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
58+
name: 'react-vendor',
59+
chunks: 'all',
60+
},
61+
refractor: {
62+
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
63+
name: 'refractor-vendor',
64+
chunks: 'all',
65+
},
66+
codemirror: {
67+
test: /[\\/]node_modules[\\/](@codemirror)[\\/]/,
68+
name: 'codemirror-vendor',
69+
chunks: 'all',
70+
},
71+
},
72+
},
73+
};
74+
conf.output = { ...conf.output, publicPath: './' };
75+
}
5076
}
5177
return conf;
5278
};

package.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"prepare": "husky install && npm run build",
1414
"watch": "tsbb watch",
1515
"build": "tsbb build",
16+
"bundle": "kkt build --bundle",
17+
"bundle:min": "kkt build --bundle --mini --no-emptyDir",
1618
"test": "tsbb test --env=jsdom",
1719
"coverage": "tsbb test --coverage --bail",
1820
"doc": "kkt build --app-src ./website",
@@ -34,6 +36,7 @@
3436
"code"
3537
],
3638
"files": [
39+
"dist",
3740
"src",
3841
"esm",
3942
"cjs"
@@ -68,20 +71,21 @@
6871
"@codemirror/lang-cpp": "0.19.1",
6972
"@codemirror/lang-html": "0.19.4",
7073
"@codemirror/lang-java": "0.19.1",
71-
"@codemirror/lang-javascript": "0.19.6",
74+
"@codemirror/lang-javascript": "0.19.7",
7275
"@codemirror/lang-json": "0.19.1",
7376
"@codemirror/lang-lezer": "0.19.1",
74-
"@codemirror/lang-markdown": "0.19.4",
77+
"@codemirror/lang-markdown": "0.19.6",
7578
"@codemirror/lang-php": "0.19.1",
7679
"@codemirror/lang-python": "0.19.4",
7780
"@codemirror/lang-rust": "0.19.1",
7881
"@codemirror/lang-sql": "0.19.4",
7982
"@codemirror/lang-xml": "0.19.2",
8083
"@codemirror/legacy-modes": "0.19.0",
81-
"@codemirror/stream-parser": "0.19.4",
82-
"@kkt/less-modules": "7.0.7",
83-
"@kkt/raw-modules": "7.0.7",
84-
"@kkt/scope-plugin-options": "7.0.7",
84+
"@codemirror/stream-parser": "0.19.5",
85+
"@kkt/less-modules": "7.1.0",
86+
"@kkt/raw-modules": "7.1.0",
87+
"@kkt/react-library": "7.1.0",
88+
"@kkt/scope-plugin-options": "7.1.0",
8589
"@types/react": "17.0.38",
8690
"@types/react-dom": "17.0.11",
8791
"@types/react-test-renderer": "17.0.1",
@@ -91,13 +95,13 @@
9195
"@uiw/reset.css": "1.0.5",
9296
"code-example": "3.3.1",
9397
"husky": "7.0.4",
94-
"kkt": "7.0.7",
95-
"lint-staged": "12.3.1",
98+
"kkt": "7.1.0",
99+
"lint-staged": "12.3.4",
96100
"prettier": "2.5.1",
97101
"react": "17.0.2",
98102
"react-dom": "17.0.2",
99103
"react-test-renderer": "17.0.2",
100-
"tsbb": "3.5.5"
104+
"tsbb": "3.5.6"
101105
},
102106
"browserslist": {
103107
"production": [

0 commit comments

Comments
 (0)