Skip to content

Commit

Permalink
chore: Update dependencies & fix bundle import issue (#267).
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Feb 24, 2022
1 parent 2a5b7c5 commit 7484096
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 85 deletions.
132 changes: 62 additions & 70 deletions .kktrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,74 @@ import webpack, { Configuration } from 'webpack';
import { LoaderConfOptions } from 'kkt';
import lessModules from '@kkt/less-modules';
import rawModules from '@kkt/raw-modules';
import reactLibrary from '@kkt/react-library';
import scopePluginOptions from '@kkt/scope-plugin-options';
import pkg from './package.json';

export default (conf: Configuration, env: 'development' | 'production', options: LoaderConfOptions) => {
conf = lessModules(conf, env, options);
if (options.bundle) {
conf = lessModules(conf, env, options);
conf = reactLibrary(conf, env, {
...options,
...pkg,
name: 'codemirror',
main: 'dist/codemirror.js',
// webpack externals options
dependencies: {
'@codemirror/basic-setup': {
root: ['CM', '@codemirror/basic-setup'],
commonjs: '@codemirror/basic-setup',
commonjs2: '@codemirror/basic-setup',
},
'@codemirror/state': {
root: ['CM', '@codemirror/state'],
commonjs: '@codemirror/state',
commonjs2: '@codemirror/state',
},
'@codemirror/view': {
root: ['CM', '@codemirror/view'],
commonjs: '@codemirror/view',
commonjs2: '@codemirror/view',
},
'@codemirror/theme-one-dark': {
root: ['CM', '@codemirror/theme-one-dark'],
commonjs: '@codemirror/theme-one-dark',
commonjs2: '@codemirror/theme-one-dark',
},
oneDark: {
root: ['CM', '@codemirror/theme-one-dark', 'oneDark'],
},
basicSetup: {
root: ['CM', '@codemirror/basic-setup', 'basicSetup'],
},
indentWithTab: {
root: ['CM', '@codemirror/commands', 'indentWithTab'],
},
keymap: {
root: ['CM', '@codemirror/view', 'keymap'],
},
placeholder: {
root: ['CM', '@codemirror/view', 'placeholder'],
},
ViewUpdate: {
root: ['CM', '@codemirror/view', 'ViewUpdate'],
},
EditorView: {
root: ['CM', '@codemirror/view', 'EditorView'],
},
StateEffect: {
root: ['CM', '@codemirror/state', 'StateEffect'],
},
EditorState: {
root: ['CM', '@codemirror/basic-setup', 'EditorState'],
},
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom',
},
conf.output!.library = '@uiw/codemirror';
conf.externals = {
'@codemirror/basic-setup': {
root: ['CM', '@codemirror/basic-setup'],
commonjs: '@codemirror/basic-setup',
commonjs2: '@codemirror/basic-setup',
},
});
'@codemirror/state': {
root: ['CM', '@codemirror/state'],
commonjs: '@codemirror/state',
commonjs2: '@codemirror/state',
},
'@codemirror/view': {
root: ['CM', '@codemirror/view'],
commonjs: '@codemirror/view',
commonjs2: '@codemirror/view',
},
'@codemirror/theme-one-dark': {
root: ['CM', '@codemirror/theme-one-dark'],
commonjs: '@codemirror/theme-one-dark',
commonjs2: '@codemirror/theme-one-dark',
},
oneDark: {
root: ['CM', '@codemirror/theme-one-dark', 'oneDark'],
},
basicSetup: {
root: ['CM', '@codemirror/basic-setup', 'basicSetup'],
},
indentWithTab: {
root: ['CM', '@codemirror/commands', 'indentWithTab'],
},
keymap: {
root: ['CM', '@codemirror/view', 'keymap'],
},
placeholder: {
root: ['CM', '@codemirror/view', 'placeholder'],
},
ViewUpdate: {
root: ['CM', '@codemirror/view', 'ViewUpdate'],
},
EditorView: {
root: ['CM', '@codemirror/view', 'EditorView'],
},
StateEffect: {
root: ['CM', '@codemirror/state', 'StateEffect'],
},
EditorState: {
root: ['CM', '@codemirror/basic-setup', 'EditorState'],
},
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom',
},
};
} else {
conf = rawModules(conf, env, {
...options,
Expand All @@ -88,7 +81,6 @@ export default (conf: Configuration, env: 'development' | 'production', options:
...options,
allowedFiles: [path.resolve(process.cwd(), 'src'), path.resolve(process.cwd(), 'README.md')],
});
conf = lessModules(conf, env, options);
// Get the project version.
conf.plugins!.push(
new webpack.DefinePlugin({
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"prepare": "husky install && npm run build",
"watch": "tsbb watch",
"build": "tsbb build",
"bundle": "kkt build --bundle",
"bundle:min": "kkt build --bundle --mini --no-emptyDir",
"bundle": "ncc build src/index.tsx --target web",
"bundle:min": "ncc build src/index.tsx --target web --minify",
"test": "tsbb test --env=jsdom",
"coverage": "tsbb test --coverage --bail",
"doc": "kkt build --app-src ./website",
Expand Down Expand Up @@ -61,18 +61,18 @@
"react-dom": ">=16.8.0"
},
"dependencies": {
"@babel/runtime": "^7.16.3",
"@codemirror/basic-setup": "^0.19.0",
"@codemirror/state": "^0.19.5",
"@babel/runtime": "^7.17.2",
"@codemirror/basic-setup": "^0.19.1",
"@codemirror/state": "^0.19.9",
"@codemirror/theme-one-dark": "^0.19.1",
"@codemirror/view": "^0.19.15"
"@codemirror/view": "^0.19.45"
},
"devDependencies": {
"@codemirror/lang-cpp": "0.19.1",
"@codemirror/lang-html": "0.19.4",
"@codemirror/lang-java": "0.19.1",
"@codemirror/lang-javascript": "0.19.7",
"@codemirror/lang-json": "0.19.1",
"@codemirror/lang-json": "0.19.2",
"@codemirror/lang-lezer": "0.19.1",
"@codemirror/lang-markdown": "0.19.6",
"@codemirror/lang-php": "0.19.1",
Expand All @@ -81,12 +81,12 @@
"@codemirror/lang-sql": "0.19.4",
"@codemirror/lang-xml": "0.19.2",
"@codemirror/legacy-modes": "0.19.0",
"@codemirror/stream-parser": "0.19.5",
"@kkt/less-modules": "7.1.0",
"@kkt/raw-modules": "7.1.0",
"@kkt/react-library": "7.1.0",
"@kkt/scope-plugin-options": "7.1.0",
"@types/react": "17.0.38",
"@codemirror/stream-parser": "0.19.6",
"@kkt/less-modules": "7.1.1",
"@kkt/ncc": "1.0.4",
"@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",
Expand All @@ -95,13 +95,13 @@
"@uiw/reset.css": "1.0.5",
"code-example": "3.3.1",
"husky": "7.0.4",
"kkt": "7.1.0",
"kkt": "7.1.4",
"lint-staged": "12.3.4",
"prettier": "2.5.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-test-renderer": "17.0.2",
"tsbb": "3.5.6"
"tsbb": "3.7.0"
},
"browserslist": {
"production": [
Expand Down
46 changes: 46 additions & 0 deletions public/bundle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script src="https://unpkg.com/@babel/[email protected]/babel.min.js" crossorigin></script>
<script src="https://unpkg.com/[email protected]/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js" crossorigin></script>
<script src="https://codemirror.net/6/codemirror.js"></script>
<script src="https://unpkg.com/@uiw/react-codemirror/dist/codemirror.min.js"></script>
</head>
<body>
<div id="container" style="padding: 24px"></div>
<script>
window.require = function (module) {
if (!module) {
throw new Error('this is a fake require only use for import fusion next');
}
if (window.CM && window.CM[module]) {
return window.CM[module];
}
return window[module];
};
</script>
<script type="text/babel">
import CodeMirror from '@uiw/codemirror';
import { javascript } from '@codemirror/lang-javascript';

const Demo = () => {
return (
<div>
<CodeMirror
value="console.log('hello world!')"
height="200px"
extensions={[javascript({ jsx: true })]}
onChange={(value, viewUpdate) => {
console.log('value:', value);
}}
/>
</div>
);
};

ReactDOM.render(<Demo />, document.getElementById('container'));
</script>
</body>
</html>

0 comments on commit 7484096

Please sign in to comment.