/** Copyright © 2013-2021 DataYes, All Rights Reserved. */
/* eslint-disable */
const path = require('path');
const webpack = require('webpack');
const fs = require('fs');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkTSCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const { TsConfigPathsPlugin } = require('awesome-typescript-loader');
const WebpackBar = require('webpackbar');
const CaseSensitive = require('case-sensitive-paths-webpack-plugin');
const withCI = require('@dyc/adam-apple-ci/with-ci');
const withModernBuildOrNot = require('./with-modern');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');
const compose =
(...args) =>
(result) =>
args.reduceRight((result, fn) => fn(result), result);
const theme = require('./theme');
const withDll = (webpackConfig) => {
const glob = require('globby');
const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin');
const manifestJson = path.join(process.cwd(), 'node_modules/vender-dll/manifest.json');
if (!fs.existsSync(manifestJson)) {
throw new Error('没有找到 node_modules/vender-dll/manifest.json, 尝试npm run build:dll');
}
const manifest = path.resolve(process.cwd(), './node_modules/vender-dll/*.dll.js');
webpackConfig.plugins.push(
new webpack.DllReferencePlugin({
context: process.cwd(),
manifest: require.resolve(path.join(process.cwd(), 'node_modules/vender-dll/manifest.json')),
})
);
glob.sync(manifest).forEach((x, i) => {
webpackConfig.plugins.push(
new AddAssetHtmlPlugin({
filepath: x,
includeSourcemap: false,
})
);
});
return webpackConfig;
};
const withDllOrNot = process.argv.includes('--no-dll') ? (i) => i : withDll;
const withLazyBuild = (webpackConfig) => {
const LazyCompilePlugin = require('lazy-compile-webpack-plugin');
webpackConfig.plugins.push(new LazyCompilePlugin());
return webpackConfig;
};
const withLazyBuildOrNot = process.argv.includes('-l') ? withLazyBuild : (i) => i;
module.exports = compose(
withLazyBuildOrNot,
withModernBuildOrNot({}),
withDllOrNot,
withCI
)({
mode: 'development',
devtool: 'eval-cheap-module-source-map',
entry: path.join(process.cwd(), 'js/index'),
output: {
pathinfo: false,
filename: 'static/js/[name].bundle.js',
path: path.join(process.cwd(), 'build'),
chunkFilename: 'static/js/[name].chunk.js',
publicPath: '/',
},
resolve: {
symlinks: false,
modules: ['node_modules', 'js', 'framework/src'],
extensions: ['.js', '.ts', 'jsx', '.tsx'],
plugins: [
new TsConfigPathsPlugin({
configFile: path.join(process.cwd(), 'tsconfig.json'),
}),
],
},
optimization: {
minimize: false,
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(process.cwd(), 'public/index.html'),
// favicon: path.join(process.cwd(), 'public/favicon.png'),
chunks: ['vendor', 'main'],
inject: true,
}),
new webpack.DefinePlugin({
__DEVELOPMENT__: true,
__DEVTOOLS__: true,
}),
// new webpack.ProvidePlugin({
// jquery: path.join(process.cwd(), 'js/utils/zepto/zepto.min'),
// }),
// new BundleAnalyzerPlugin(),
new ForkTSCheckerWebpackPlugin({
async: true,
typescript: {
enabled: true,
mode: 'write-references',
// profile: true,
},
}),
new WebpackBar({
// profile: true,
name: require(path.join(process.cwd(), 'package.json')).name || 'client',
}),
new CaseSensitive(),
new FriendlyErrorsWebpackPlugin(),
new AntdDayjsWebpackPlugin({
replaceMoment: true,
plugins: [
'isSameOrBefore',
'isSameOrAfter',
'advancedFormat',
'customParseFormat',
'weekday',
'weekYear',
'weekOfYear',
'isMoment',
'localeData',
'localizedFormat',
'badMutable',
'isoWeek',
'dayOfYear',
'duration',
'relativeTime',
'isBetween',
'minMax',
],
}),
],
module: {
noParse: [/jszip.js$/],
rules: [
{
test: /\.(t|j)sx?$/,
use: [
'cache-loader',
{
loader: 'thread-loader',
// loaders with equal options will share worker pools
options: {
// the number of spawned workers, defaults to (number of cpus - 1) or
// fallback to 1 when require('os').cpus() is undefined
workers: 2,
// number of jobs a worker processes in parallel
// defaults to 20
workerParallelJobs: 50,
// additional node.js arguments
workerNodeArgs: ['--max-old-space-size=1024'],
// Allow to respawn a dead worker pool
// respawning slows down the entire compilation
// and should be set to false for development
poolRespawn: false,
// timeout for killing the worker processes when idle
// defaults to 500 (ms)
// can be set to Infinity for watching builds to keep workers alive
poolTimeout: 2000,
// number of jobs the poll distributes to the workers
// defaults to 200
// decrease of less efficient but more fair distribution
poolParallelJobs: 50,
// name of the pool
// can be used to create different pools with elsewise identical options
name: 'js-thread-pool',
},
},
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
],
exclude: /node_modules/,
include: [path.resolve('js'), path.resolve('framework'), path.resolve('packages')],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.less$/,
use: [
'style-loader',
'css-loader',
{
loader: 'less-loader',
options: {
javascriptEnabled: true,
modifyVars: theme,
},
},
],
},
{
test: /\.(jpeg|png|jpg|gif|pdf|mp3|ogg|wav)$/,
use: ['file-loader?name=[path][name].[ext]'],
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: ['url-loader?limit=10000&mimetype=application/font-woff'],
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: ['file-loader'],
},
],
},
performance: {
hints: false,
},
devServer: {
quiet: true,
contentBase: process.cwd(),
port: process.env.PORT || 3000,
host: '0.0.0.0',
hot: true,
compress: true,
stats: {
colors: true,
assets: false,
modules: false,
children: false,
},
historyApiFallback: true,
},
});
把你刚才的改动放入文件中
最新发布