123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- const path = require("path");
- const webpack = require('webpack');
- const TerserPlugin = require("terser-webpack-plugin");
- const HappyPack = require('happypack');
- const os = require('os');
- const happyThreadPool = HappyPack.ThreadPool({
- size: os.cpus().length
- });
-
- const common = require("./common");
- const pathVars = require("./pathVars");
- const pageVars = require("./pageVars");
-
- //---------------------------------- output -----------------------------------//
- const entryConfig = {};
-
- let charts = pageVars.getCharts();
-
- charts.forEach((chartItem) => {
- entryConfig[chartItem["chunkName"]] = chartItem["entryJs"];
- });
- console.log("entryConfig", entryConfig);
- //---------------------------------- output -----------------------------------//
-
- let outputConfig = {
- path: pathVars.chartsDistPath,
- publicPath: "./", // 表示资源的发布地址,当配置过该属性后,打包文件中所有通过相对路径引用的资源都会被配置的路径所替换(如:css中背景图的路径)
- filename: "[name].js",
- library: "[name]",
- libraryExport: 'default',
- umdNamedDefine: true,
- // es umd
- libraryTarget: "umd",
-
- assetModuleFilename: 'chartImages/[name]_[hash][ext][query]'
- };
-
-
- //---------------------------------- plugin -----------------------------------//
- let pluginConfig = [
- new HappyPack({
- id: 'babel',
- loaders: ["babel-loader"],
- threadPool: happyThreadPool
- })
- ];
-
- module.exports = {
- mode: 'production',
- entry: entryConfig,
- output: outputConfig,
- resolve: common.resolve,
- module: {
- rules: [{
- test: /\.(css|less)$/,
- include: [pathVars.srcPath],
- exclude: [pathVars.nodeModulesPath],
- use: [{
- options: {
- /* 解决css背景图路径问题 由于图片目录已经定好了,因此这里可以用固定的相对路径*/
- publicPath: '../'
- },
- },
- //"css-loader?modules&localIdentName=[name]__[local]-[hash:base64:5]",
- "css-loader",
- "less-loader"
- ],
- },
- {
- test: /\.js$/,
- exclude: pathVars.nodeModulesPath,
- include: pathVars.srcPath,
- use: ['babel-loader']
- //use: ["happypack/loader?id=babel"]
- },
- {
- test: /\.(png|jpg|gif|woff|svg|eot|ttf|woff2)$/,
- type: 'asset/resource',
- parser: {
- dataUrlCondition: {
- maxSize: 10 * 1024
- }
- }
- },
- {
- test: /\.(glsl|vs|fs|vert|frag)$/,
- exclude: [pathVars.nodeModulesPath, pathVars.dllPath],
- use: ["raw-loader", "glslify-loader"]
- }
- ]
- },
- plugins: pluginConfig,
- optimization: {
- minimize: true,
- minimizer: [
- new TerserPlugin()
- ]
- }
- };
|