101 lines
2.4 KiB
JavaScript
101 lines
2.4 KiB
JavaScript
/*eslint-disable*/
|
|
const { join } = require('path');
|
|
const path = require('path');
|
|
const { readdirSync, statSync } = require('fs');
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
|
const TerserPlugin = require("terser-webpack-plugin");
|
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
const isDev = process.env.RUNNING_ENV === 'dev';
|
|
const isProd = process.env.RUNNING_ENV === 'prod';
|
|
|
|
const importEntry = () => {
|
|
const entries = {};
|
|
const rootDir = join(process.cwd(), '/src/components');
|
|
readdirSync(rootDir)
|
|
.filter(i => !i.startsWith('_'))
|
|
.forEach(file => {
|
|
if (statSync(join(rootDir, file)).isDirectory())
|
|
entries[file] = join(rootDir, `${file}/index.ts`);
|
|
});
|
|
return entries;
|
|
};
|
|
|
|
module.exports = {
|
|
entry: { ...importEntry(), 'index': join(__dirname, 'src/index.ts') },
|
|
output: {
|
|
path: path.resolve(__dirname, 'dist/'),
|
|
publicPath: '',
|
|
filename: '[name].js',
|
|
clean: true,
|
|
libraryTarget: 'umd' // 添加 export default
|
|
},
|
|
mode: 'production',
|
|
optimization: {
|
|
minimize: true,
|
|
minimizer: [new TerserPlugin({
|
|
terserOptions: {
|
|
compress: true,
|
|
},
|
|
})],
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.ts?$/,
|
|
use: 'ts-loader',
|
|
exclude: /node_modules/,
|
|
},
|
|
{
|
|
test: /\.css$/,
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader'],
|
|
},
|
|
{
|
|
test: /\.less$/,
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader'],
|
|
},
|
|
{
|
|
test: /\.(scss)$/,
|
|
use: [
|
|
MiniCssExtractPlugin.loader,
|
|
{
|
|
loader: 'css-loader'
|
|
},
|
|
{
|
|
loader: 'postcss-loader',
|
|
options: {
|
|
postcssOptions: {
|
|
plugins: () => [
|
|
require('autoprefixer')
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
loader: 'sass-loader'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
test: /\.(png|jpg|gif)$/i,
|
|
use: [
|
|
{
|
|
loader: 'url-loader',
|
|
options: {
|
|
limit: 8192,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
plugins: [
|
|
new MiniCssExtractPlugin({
|
|
filename: '[name].css'
|
|
}),
|
|
].filter(Boolean),
|
|
resolve: {
|
|
extensions: ['.ts', '.js'],
|
|
},
|
|
};
|