mirror of
https://github.com/jaywcjlove/wxmp.git
synced 2026-01-09 14:58:48 +08:00
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import path from 'path';
|
|
import webpack, { Configuration } from 'webpack';
|
|
import lessModules from '@kkt/less-modules';
|
|
import { mdCodeModulesLoader } from 'markdown-react-code-preview-loader';
|
|
import scopePluginOptions from '@kkt/scope-plugin-options';
|
|
import { LoaderConfOptions } from 'kkt';
|
|
import raw from '@kkt/raw-modules';
|
|
import pkg from './package.json';
|
|
|
|
export default (conf: Configuration, env: 'development' | 'production', options: LoaderConfOptions) => {
|
|
conf = lessModules(conf, env, options);
|
|
conf = mdCodeModulesLoader(conf);
|
|
conf = raw(conf, env, {
|
|
...options,
|
|
test: /\.(md.css)$/i,
|
|
});
|
|
conf = scopePluginOptions(conf, env, {
|
|
...options,
|
|
allowedFiles: [path.resolve(process.cwd(), 'README.md'), path.resolve(process.cwd(), 'src')],
|
|
});
|
|
conf.plugins!.push(
|
|
new webpack.DefinePlugin({
|
|
VERSION: JSON.stringify(pkg.version),
|
|
}),
|
|
);
|
|
|
|
conf.module!.exprContextCritical = false;
|
|
if (env === 'production') {
|
|
conf.output = { ...conf.output, publicPath: './' };
|
|
conf.optimization = {
|
|
...conf.optimization,
|
|
splitChunks: {
|
|
cacheGroups: {
|
|
reactvendor: {
|
|
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
|
|
name: 'react-vendor',
|
|
chunks: 'all',
|
|
},
|
|
refractor: {
|
|
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
|
|
name: 'refractor-prismjs-vendor',
|
|
chunks: 'all',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
return conf;
|
|
};
|