|
1 | 1 | const { defineConfig } = require('@vue/cli-service');
|
| 2 | +const webpack = require('webpack'); |
2 | 3 | // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
3 | 4 | // const CompressionPlugin = require('compression-webpack-plugin');
|
4 | 5 | // 去除console
|
| 6 | +const dayjs = require('dayjs'); |
5 | 7 | const TerserPlugin = require('terser-webpack-plugin');
|
6 | 8 | const path = require('path');
|
7 | 9 | const resolve = (dir) => path.join(__dirname, dir); // 路径
|
| 10 | +const pkg = require('./package.json'); |
8 | 11 |
|
9 |
| -process.env.VUE_APP_VERSION = require('./package.json').version; |
| 12 | +process.env.VUE_APP_VERSION = pkg.version; |
10 | 13 |
|
11 | 14 | const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV);
|
12 | 15 | // const IS_DEV = ['development'].includes(process.env.NODE_ENV);
|
13 | 16 |
|
14 | 17 | // port = 8098 npm run dev OR npm run dev --port = 8098
|
15 | 18 | const port = process.env.port || process.env.npm_config_port || 8098; // dev port
|
| 19 | +// 获取所有依赖地址 |
| 20 | +['dependencies', 'devDependencies'].forEach((name) => { |
| 21 | + Object.keys(pkg[name]).forEach((key) => { |
| 22 | + const devPkg = require(`./node_modules/${key}/package.json`); |
| 23 | + pkg[name][key] = { |
| 24 | + url: devPkg.repository?.url || devPkg.repository || devPkg.homepage, |
| 25 | + version: pkg[name][key], |
| 26 | + }; |
| 27 | + }); |
| 28 | +}); |
| 29 | + |
| 30 | +const __APP_INFO__ = { |
| 31 | + pkg, |
| 32 | + lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), |
| 33 | +}; |
| 34 | + |
| 35 | +process.env.VUE_APP_APP_INFO = JSON.stringify(__APP_INFO__); |
16 | 36 |
|
17 | 37 | module.exports = defineConfig({
|
18 | 38 | // lintOnSave: false, //关闭eslint检查
|
@@ -53,6 +73,7 @@ module.exports = defineConfig({
|
53 | 73 |
|
54 | 74 | // 配置相关loader,支持修改,添加和替换相关的loader
|
55 | 75 | config.resolve.alias.set('@', resolve('src'));
|
| 76 | + config.resolve.alias.set('vue-i18n', 'vue-i18n/dist/vue-i18n.cjs.js'); |
56 | 77 |
|
57 | 78 | // 打包分析
|
58 | 79 | if (IS_PROD) {
|
@@ -150,6 +171,13 @@ module.exports = defineConfig({
|
150 | 171 | };
|
151 | 172 | config.resolve.fallback = { path: require.resolve('path-browserify') };
|
152 | 173 |
|
| 174 | + config.plugins.push( |
| 175 | + // 定义全局变量 |
| 176 | + new webpack.DefinePlugin({ |
| 177 | + __APP_INFO__: JSON.stringify(__APP_INFO__), |
| 178 | + }), |
| 179 | + ); |
| 180 | + |
153 | 181 | if (IS_PROD) {
|
154 | 182 | config.plugins.push(
|
155 | 183 | new TerserPlugin({
|
|
0 commit comments