import path from 'path' ; 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 , env , options ) => { if ( options . bundle ) { conf = lessModules ( conf , env , options ) ; conf = reactLibrary ( conf , env , { ... options , ... pkg , name : 'mdeditor' , main : 'dist/mdeditor.js' , dependencies : { 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 } ) ; conf = lessModules ( conf , env , options ) ; conf = scopePluginOptions ( conf , env , { ... options , allowedFiles : [ path . resolve ( process . cwd ( ) , 'README.md' ) ] , } ) ; conf . plugins ! . push ( new webpack . DefinePlugin ( { VERSION : JSON . stringify ( pkg . version ) , } ) ) ; if ( env === 'production' ) { conf . optimization = { ... conf . optimization , splitChunks : { chunks : 'all' , minSize : 30000 , minChunks : 1 , maxAsyncRequests : 30 , maxInitialRequests : 25 , automaticNameDelimiter : '~' , cacheGroups : { reactvendor : { test : /[\\/]node_modules[\\/](react|react-dom)[\\/]/ , name : 'react-vendor' , chunks : 'all' , } , katex : { test : /[\\/]node_modules[\\/](katex)[\\/]/ , name : 'katex-vendor' , chunks : 'async' , } , micromark : { test : /[\\/]node_modules[\\/](micromark)[\\/]/ , name : 'micromark-vendor' , chunks : 'all' , } , prismjs : { test : /[\\/]node_modules[\\/](refractor)[\\/]/ , name : 'refractor-prismjs-vendor' , chunks : 'all' , } , runtime : { test : /[\\/]node_modules[\\/](@babel[\\/]runtime)[\\/]/ , name : 'babel-runtime-vendor' , chunks : 'all' , } , parse5 : { test : /[\\/]node_modules[\\/](parse5)[\\/]/ , name : 'parse5-vendor' , chunks : 'all' , } , } , } , } ; conf . output = { ... conf . output , publicPath : './' } ; } } return conf ; } ;