|
1 | 1 | 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'; |
4 | 4 | import lessModules from '@kkt/less-modules'; |
5 | 5 | import rawModules from '@kkt/raw-modules'; |
6 | 6 | import scopePluginOptions from '@kkt/scope-plugin-options'; |
7 | 7 | import pkg from './package.json'; |
8 | 8 |
|
9 | | -export default (conf: Configuration, env: 'production' | 'development', options: LoaderConfOptions) => { |
| 9 | +export default (conf: WebpackConfiguration, env: 'production' | 'development', options: LoaderConfOptions) => { |
10 | 10 | conf = lessModules(conf, env, options); |
11 | | - conf = rawModules(conf, env, { ...options }); |
12 | | - conf = scopePluginOptions(conf, env, { |
13 | | - ...options, |
14 | | - allowedFiles: [ |
15 | | - path.resolve(process.cwd(), 'README.md') |
16 | | - ] |
17 | | - }); |
18 | | - // Get the project version. |
19 | | - conf.plugins!.push(new webpack.DefinePlugin({ |
20 | | - VERSION: JSON.stringify(pkg.version), |
21 | | - })); |
22 | | - if (env === 'production') { |
23 | | - conf.module!.exprContextCritical = false; |
24 | | - conf.output = { ...conf.output, publicPath: './' }; |
25 | | - conf.optimization = { |
26 | | - ...conf.optimization, |
27 | | - splitChunks: { |
28 | | - cacheGroups: { |
29 | | - reactvendor: { |
30 | | - test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/, |
31 | | - name: 'react-vendor', |
32 | | - chunks: 'all', |
33 | | - }, |
34 | | - babelstandalone: { |
35 | | - test: /[\\/]node_modules[\\/](@babel[\\/]standalone)[\\/]/, |
36 | | - name: 'babel-standalone-vendor', |
37 | | - chunks: 'all', |
38 | | - }, |
39 | | - prismjs: { |
40 | | - test: /[\\/]node_modules[\\/](refractor)[\\/]/, |
41 | | - name: 'refractor-vendor', |
42 | | - chunks: 'all', |
43 | | - }, |
44 | | - codemirror: { |
45 | | - test: /[\\/]node_modules[\\/](@codemirror)[\\/]/, |
46 | | - name: 'codemirror-vendor', |
47 | | - chunks: 'all', |
48 | | - }, |
49 | | - uiw: { |
50 | | - test: /[\\/]node_modules[\\/](@uiw)[\\/]/, |
51 | | - name: 'uiw-vendor', |
52 | | - chunks: 'all', |
53 | | - }, |
54 | | - parse5: { |
55 | | - test: /[\\/]node_modules[\\/](parse5)[\\/]/, |
56 | | - name: 'parse5-vendor', |
57 | | - chunks: 'all', |
58 | | - }, |
59 | | - }, |
| 11 | + if (options.bundle) { |
| 12 | + conf.output!.library = '@uiw/react-split'; |
| 13 | + conf.externals = { |
| 14 | + react: { |
| 15 | + root: 'React', |
| 16 | + commonjs2: 'react', |
| 17 | + commonjs: 'react', |
| 18 | + amd: 'react', |
60 | 19 | }, |
61 | 20 | }; |
| 21 | + } else { |
| 22 | + conf = rawModules(conf, env, { ...options }); |
| 23 | + conf = scopePluginOptions(conf, env, { |
| 24 | + ...options, |
| 25 | + allowedFiles: [ |
| 26 | + path.resolve(process.cwd(), 'README.md') |
| 27 | + ] |
| 28 | + }); |
| 29 | + // Get the project version. |
| 30 | + conf.plugins!.push(new webpack.DefinePlugin({ |
| 31 | + VERSION: JSON.stringify(pkg.version), |
| 32 | + })); |
| 33 | + |
| 34 | + if (env === 'production') { |
| 35 | + conf.module!.exprContextCritical = false; |
| 36 | + conf.output = { ...conf.output, publicPath: './' }; |
| 37 | + conf.optimization = { |
| 38 | + ...conf.optimization, |
| 39 | + splitChunks: { |
| 40 | + cacheGroups: { |
| 41 | + reactvendor: { |
| 42 | + test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/, |
| 43 | + name: 'react-vendor', |
| 44 | + chunks: 'all', |
| 45 | + }, |
| 46 | + babelstandalone: { |
| 47 | + test: /[\\/]node_modules[\\/](@babel[\\/]standalone)[\\/]/, |
| 48 | + name: 'babel-standalone-vendor', |
| 49 | + chunks: 'all', |
| 50 | + }, |
| 51 | + prismjs: { |
| 52 | + test: /[\\/]node_modules[\\/](refractor)[\\/]/, |
| 53 | + name: 'refractor-vendor', |
| 54 | + chunks: 'all', |
| 55 | + }, |
| 56 | + codemirror: { |
| 57 | + test: /[\\/]node_modules[\\/](@codemirror)[\\/]/, |
| 58 | + name: 'codemirror-vendor', |
| 59 | + chunks: 'all', |
| 60 | + }, |
| 61 | + uiw: { |
| 62 | + test: /[\\/]node_modules[\\/](@uiw)[\\/]/, |
| 63 | + name: 'uiw-vendor', |
| 64 | + chunks: 'all', |
| 65 | + }, |
| 66 | + parse5: { |
| 67 | + test: /[\\/]node_modules[\\/](parse5)[\\/]/, |
| 68 | + name: 'parse5-vendor', |
| 69 | + chunks: 'all', |
| 70 | + }, |
| 71 | + }, |
| 72 | + }, |
| 73 | + }; |
| 74 | + } |
62 | 75 | } |
63 | 76 |
|
64 | 77 | return conf; |
65 | 78 | } |
66 | | - |
|
0 commit comments