UNPKG

@plugin-light/project-config-uni-vue

Version:

开箱即用的项目配置,适用于 uni-app Vue2.x 项目

718 lines (705 loc) 29.9 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var fs = require('fs'); var path = require('path'); var shared = require('@plugin-light/shared'); var tComm = require('t-comm'); var webpackLoaderCssUrlBlankSpace = require('@plugin-light/webpack-loader-css-url-blank-space'); var webpackLoaderAutoPlaceholder = require('@plugin-light/webpack-loader-auto-placeholder'); var webpackLoaderCrossGameStyle = require('@plugin-light/webpack-loader-cross-game-style'); var webpackLoaderCrossModuleStyle = require('@plugin-light/webpack-loader-cross-module-style'); var webpackLoaderCrossPlatform = require('@plugin-light/webpack-loader-cross-platform'); var webpackLoaderInsertGlobalComp = require('@plugin-light/webpack-loader-insert-global-comp'); var webpackLoaderInsertPageMeta = require('@plugin-light/webpack-loader-insert-page-meta'); var webpackLoaderRemoveScoped = require('@plugin-light/webpack-loader-remove-scoped'); var webpackLoaderReplaceLibrary = require('@plugin-light/webpack-loader-replace-library'); var webpackLoaderReplaceTemplateTag = require('@plugin-light/webpack-loader-replace-template-tag'); var webpackLoaderReplaceVueKey = require('@plugin-light/webpack-loader-replace-vue-key'); var webpackLoaderSwipeComponent = require('@plugin-light/webpack-loader-swipe-component'); var webpackLoaderTransformDynamicComp = require('@plugin-light/webpack-loader-transform-dynamic-comp'); var webpackLoaderVLazy = require('@plugin-light/webpack-loader-v-lazy'); var config = require('t-comm/lib/v-console/config'); var webpackPluginAddPlaceholder = require('@plugin-light/webpack-plugin-add-placeholder'); var webpackPluginCheckLongConstant = require('@plugin-light/webpack-plugin-check-long-constant'); var webpackPluginCopyDir = require('@plugin-light/webpack-plugin-copy-dir'); var webpackPluginCustomPreload = require('@plugin-light/webpack-plugin-custom-preload'); var webpackPluginDispatchScript = require('@plugin-light/webpack-plugin-dispatch-script'); var webpackPluginDispatchVue = require('@plugin-light/webpack-plugin-dispatch-vue'); var webpackPluginFixImportPath = require('@plugin-light/webpack-plugin-fix-import-path'); var webpackPluginFixMiniCssPlugin = require('@plugin-light/webpack-plugin-fix-mini-css-plugin'); var webpackPluginFixNpmPackage = require('@plugin-light/webpack-plugin-fix-npm-package'); var webpackPluginGenMpPluginPlayground = require('@plugin-light/webpack-plugin-gen-mp-plugin-playground'); var webpackPluginGenVersion = require('@plugin-light/webpack-plugin-gen-version'); var webpackPluginGlobalThisPolyfill = require('@plugin-light/webpack-plugin-global-this-polyfill'); var webpackPluginInsertScript = require('@plugin-light/webpack-plugin-insert-script'); var webpackPluginManifestExpose = require('@plugin-light/webpack-plugin-manifest-expose'); var webpackPluginRemToRpx = require('@plugin-light/webpack-plugin-rem-to-rpx'); var webpackPluginReplaceUniH5 = require('@plugin-light/webpack-plugin-replace-uni-h5'); var webpackPluginTransferLocalFile = require('@plugin-light/webpack-plugin-transfer-local-file'); var chalk = require('chalk'); var ProgressBarPlugin = require('progress-bar-webpack-plugin'); var ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin'); var TransformPages = require('uni-read-pages'); var webpack = require('webpack'); var webpackBundleAnalyzer = require('webpack-bundle-analyzer'); var WorkboxPlugin = require('workbox-webpack-plugin'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n["default"] = e; return Object.freeze(n); } var fs__namespace = /*#__PURE__*/_interopNamespace(fs); var path__namespace = /*#__PURE__*/_interopNamespace(path); var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk); var ProgressBarPlugin__default = /*#__PURE__*/_interopDefaultLegacy(ProgressBarPlugin); var ScriptExtHtmlWebpackPlugin__default = /*#__PURE__*/_interopDefaultLegacy(ScriptExtHtmlWebpackPlugin); var TransformPages__default = /*#__PURE__*/_interopDefaultLegacy(TransformPages); var webpack__default = /*#__PURE__*/_interopDefaultLegacy(webpack); var WorkboxPlugin__default = /*#__PURE__*/_interopDefaultLegacy(WorkboxPlugin); const LOADER_MAP = { insertGlobalComp: webpackLoaderInsertGlobalComp.LOADER, crossModuleStyle: webpackLoaderCrossModuleStyle.LOADER, crossGameStyle: webpackLoaderCrossGameStyle.LOADER, crossPlatform: webpackLoaderCrossPlatform.LOADER, crossPlatformProd: webpackLoaderCrossPlatform.LOADER_PROD, transformDynamicComp: webpackLoaderTransformDynamicComp.LOADER, insertPageMeta: webpackLoaderInsertPageMeta.LOADER, autoPlaceholder: webpackLoaderAutoPlaceholder.LOADER, replaceVueKey: webpackLoaderReplaceVueKey.LOADER, replaceTemplateTag: webpackLoaderReplaceTemplateTag.LOADER, vLazy: webpackLoaderVLazy.LOADER, swipeComponent: webpackLoaderSwipeComponent.LOADER, removeScoped: webpackLoaderRemoveScoped.LOADER, replaceLibrary: webpackLoaderReplaceLibrary.LOADER, }; function chainWebpack(config, options = {}) { const { useXSS } = options; if (options.useInsertGlobalCompLoader) { config.module .rule('global-comp-vue') .test(/\.vue$/) .pre() .use(LOADER_MAP.insertGlobalComp) .loader(LOADER_MAP.insertGlobalComp) .options(options.insertGlobalCompLoaderOptions || {}) .end(); } if (options.useTransformDynamicCompLoader || options.useAddPlaceHolderPlugin) { config.module .rule('vue') .test(/\.vue$/) .use(LOADER_MAP.transformDynamicComp) .loader(LOADER_MAP.transformDynamicComp) .end(); } if (options.useAddPlaceHolderPlugin) { config.module .rule('vue') .test(/\.vue$/) .use(LOADER_MAP.autoPlaceholder) .loader(LOADER_MAP.autoPlaceholder) .end(); } if (options.useReplaceVueKeyLoader) { config.module .rule('vue') .test(/\.vue$/) .use(LOADER_MAP.replaceVueKey) .loader(LOADER_MAP.replaceVueKey) .end(); } if (options.useReplaceTemplateTagLoader) { config.module .rule('vue') .test(/\.vue$/) .use(LOADER_MAP.replaceTemplateTag) .loader(LOADER_MAP.replaceTemplateTag) .options(options.replaceTemplateTagLoaderOptions || {}) .end(); } if (options.useVLazyLoader) { config.module .rule('vue') .test(/\.vue$/) .use(LOADER_MAP.vLazy) .loader(LOADER_MAP.vLazy) .options(options.vLazyLoaderOptions || {}) .end(); } if (options.useSwipeComponentLoader) { config.module .rule('vue') .test(/\.vue$/) .use(LOADER_MAP.swipeComponent) .loader(LOADER_MAP.swipeComponent) .end(); } if (options.useRemoveScopedLoader) { config.module .rule('vue') .test(/\.vue$/) .use(LOADER_MAP.removeScoped) .loader(LOADER_MAP.removeScoped) .end(); } config.module .rule('vue') .test(/\.vue$/) .use(LOADER_MAP.crossPlatform) .loader(LOADER_MAP.crossPlatform) .end() .use(LOADER_MAP.crossGameStyle) // 处理样式的loader,必须在vue-loader前执行 .loader(LOADER_MAP.crossGameStyle) .end() .use(LOADER_MAP.crossModuleStyle) .loader(LOADER_MAP.crossModuleStyle) .options(options.crossModuleStyleLoaderOptions || {}) .end() .use('vue-loader') .loader('vue-loader') .tap((options) => { if (options?.compilerOptions) { options.compilerOptions.whitespace = 'preserve'; } return options; }) .tap((options) => { if (useXSS && options?.compilerOptions) { options.compilerOptions.directives = { html(node, directiveMeta) { (node.props || (node.props = [])).push({ name: 'innerHTML', value: `xss(_s(${directiveMeta.value}))`, }); }, }; } return options; }) .end(); if (options.useInsertPageMetaLoader) { config.module .rule('vue') .test(/\.vue$/) .use(LOADER_MAP.insertPageMeta) .loader(LOADER_MAP.insertPageMeta) .options(options.insertPageMetaLoaderOptions || {}) .end(); } config.module .rule('cross-platform-prod') .test(/\.[jt]s$/) .use(LOADER_MAP.crossPlatformProd) .loader(LOADER_MAP.crossPlatformProd) .end(); if (options.useReplaceLibraryLoader) { config.module .rule('replace-library') .test(/\.(ts|js|vue)$/) .use(LOADER_MAP.replaceLibrary) .loader(LOADER_MAP.replaceLibrary) .options(options.replaceLibraryLoaderOptions || {}) .end(); } // 发行或运行时启用了压缩时会生效; config.optimization.minimizer('terser').tap((args) => { const { compress } = args[0].terserOptions; // 非 App 平台移除 console 代码(包含所有 console 方法,如 log,debug,info...) compress.drop_console = process.env.VUE_APP_BRANCH === 'release'; compress.pure_funcs = [ '__f__', // App 平台 vue 移除日志代码 // 'console.debug' // 可移除指定的 console 方法 ]; return args; }); } function getExternals({ aegisWebSdkExternal, uniSimpleRouterExternal, axiosExternal, vueLazyloadExternal, }) { const externals = {}; if (shared.checkH5()) { if (aegisWebSdkExternal) { externals['aegis-web-sdk'] = 'window Aegis'; } if (uniSimpleRouterExternal) { externals['uni-simple-router'] = 'Router'; } if (axiosExternal) { externals.axios = 'axios'; } if (vueLazyloadExternal) { externals['vue-lazyload'] = 'VueLazyload'; } } return externals; } function getExternalScripts({ uniSimpleRouterExternal, aegisWebSdkExternal, axiosExternal, vueLazyloadExternal, }) { const externalScripts = []; insertScript(externalScripts, shared.CDN_MAP.AEGIS_WEB, aegisWebSdkExternal); insertScript(externalScripts, shared.CDN_MAP.AXIOS, axiosExternal); insertScript(externalScripts, shared.CDN_MAP.UNI_SIMPLE_ROUTER_BETA4, uniSimpleRouterExternal); insertScript(externalScripts, shared.CDN_MAP.VUE_LAZY_LOAD, vueLazyloadExternal); return externalScripts; } function insertScript(externalScripts, defaultScript, key) { if (typeof key === 'string') { externalScripts.push(key); } else if (key) { externalScripts.push(defaultScript); } } function optimizationH5(useH5SplitChunks) { const { getH5Options, getMainEntry, // eslint-disable-next-line @typescript-eslint/no-require-imports } = require('@dcloudio/uni-cli-shared'); const { title, publicPath, template, } = getH5Options(); return { pages: { index: { entry: path__namespace.resolve(process.env.UNI_INPUT_DIR, getMainEntry()), // 模板来源 template, filename: 'index.html', title, publicPath, chunks: [ 'uni-h5', 'core-js', 'vue-cli-plugin-uni', 'chunk-vendors', 'index', 'runtime', // 'tencent-cloud-chat', 'pmd-vue', ], }, }, chainWebpack(config) { config.optimization.splitChunks({ // chunks: 'all', minChunks: 1, maxInitialRequests: 20, // maxAsyncRequests: 30, cacheGroups: { tim_js_sdk: { name: 'tim-js-sdk', test: /[\\/]node_modules[\\/]_?tim-js-sdk(.*)/, priority: 15, chunks: 'all', // minSize: 0, reuseExistingChunk: true, }, tencent_cloud_chat: { name: 'tencent-cloud-chat', test: /node_modules[\\/]_?@tencentcloud[\\/]_?chat/, chunks: 'all', priority: 30, reuseExistingChunk: true, }, pmd_vue: { name: 'pmd-vue', test: /node_modules[\\/]_?@tencent[\\/]_?pmd-vue/, chunks: 'all', priority: 30, reuseExistingChunk: true, }, uni_h5: { name: 'uni-h5', test: /node_modules(.*)uni-h5(.*)/, chunks: 'all', priority: 20, reuseExistingChunk: true, }, vue_cli_plugin_uni: { name: 'vue-cli-plugin-uni', test: /vue-cli-plugin-uni[\\/]_?packages/, chunks: 'initial', priority: 30, reuseExistingChunk: true, }, core_js: { name: 'core-js', test: /[\\/]node_modules[\\/]_??core-js(.*)/, chunks: 'initial', priority: 30, reuseExistingChunk: true, }, vendors: { name: 'chunk-vendors', test: /[\\/]node_modules[\\/]/, priority: -10, chunks: 'initial', reuseExistingChunk: true, }, default: { minChunks: 2, priority: -20, reuseExistingChunk: true, }, // index_home: { // name: 'index-home', // test: path.resolve('src/project/user/views/index'), // priority: 60, // chunks: 'all', // reuseExistingChunk: true, // }, }, ...(typeof useH5SplitChunks === 'boolean' ? {} : useH5SplitChunks), }); }, }; } // 读取 manifest.json ,修改后重新写入 const manifestPath = `${process.env.UNI_INPUT_DIR}/manifest.json`; const originManifest = fs__namespace.readFileSync(manifestPath, { encoding: 'utf-8' }); let Manifest = originManifest; function replaceManifest(path, value) { const arr = path.split('.'); const len = arr.length; const lastItem = arr[len - 1]; let i = 0; const ManifestArr = Manifest.split(/\n/); for (let index = 0; index < ManifestArr.length; index++) { const item = ManifestArr[index]; if (new RegExp(`"${arr[i]}"`).test(item)) i = i + 1; if (i === len) { const hasComma = /,/.test(item); ManifestArr[index] = item.replace(new RegExp(`"${lastItem}"[\\s\\S]*:[\\s\\S]*`), `"${lastItem}": ${value}${hasComma ? ',' : ''}`); break; } } Manifest = ManifestArr.join('\n'); } function updateManifest(path, value) { replaceManifest(path, value); fs__namespace.writeFileSync(manifestPath, Manifest, { flag: 'w', }); } function getPlugins({ adapterDirs, useDispatchScriptPlugin = false, dispatchScriptPluginOptions = {}, useDispatchVuePlugin = false, dispatchVuePluginOptions = {}, useCopyDirPlugin = false, copyDirPluginOptions = {}, useAddPlaceHolderPlugin = false, remToRpxPluginMpOptions = {}, genVersionWebPluginOptions = { buildName: config.BUILD_NAME_MAP.build, commitName: config.BUILD_NAME_MAP.commit, delay: 1, }, useFixMiniCssPlugin = false, aegisWebSdkExternal, uniSimpleRouterExternal, axiosExternal, vueLazyloadExternal, customPreload, useWorkBoxPlugin, saveBundleAnalyzeHtml, useReplaceUniH5Plugin, outputDirMode, }) { const plugins = []; const isProduction = process.env.NODE_ENV === 'production'; if (process.env.VUE_APP_PLATFORM === 'app-plus') { const globalVarsDefinePlugin = new webpack__default["default"].DefinePlugin({ location: 'window.location', navigator: 'window.navigator', localStorage: 'window.localStorage', sessionStorage: 'window.sessionStorage', globalVars: 'window.globalVars', document: 'window.document', app: 'window.app', }); plugins.push(globalVarsDefinePlugin); plugins.push(new webpackPluginRemToRpx.RemToRpxPlugin({ unit: 'px', factor: 50, fileSuffix: [ 'css', 'scss', 'less', 'js', shared.CSS_POSTFIX_MAP.MP_WX, shared.CSS_POSTFIX_MAP.MP_QQ, shared.CSS_POSTFIX_MAP.MP_ALIPAY, shared.CSS_POSTFIX_MAP.MP_JD, ], })); } else if (process.env.VUE_APP_PLATFORM !== 'h5') { const globalVarsDefinePlugin = new webpack__default["default"].DefinePlugin({ window: 'globalThis.$window', location: 'globalThis.$location', navigator: 'globalThis.$navigator', localStorage: 'globalThis.$localStorage', sessionStorage: 'globalThis.$sessionStorage', globalVars: 'globalThis.$globalVars', document: 'globalThis.$document', app: 'globalThis.$window.app', top: 'globalThis.$window', defaultIsTestNet: process.env.NET_ENV === 'test', }); plugins.push(globalVarsDefinePlugin); plugins.push(new webpackPluginRemToRpx.RemToRpxPlugin(remToRpxPluginMpOptions || {})); plugins.push(new webpackPluginGenVersion.GenVersionMpPlugin({})); plugins.push(new webpackPluginTransferLocalFile.TransferLocalFilePlugin({ adapterDirs, isModifyRef: true, })); const mpPluginName = process.env.VUE_APP_MP_PLUGIN; plugins.push(new webpackPluginFixNpmPackage.FixNpmPackagePlugin({ pluginName: mpPluginName, })); if (process.env.VUE_APP_PLATFORM === 'mp-qq') { plugins.push(new webpackPluginGlobalThisPolyfill.GlobalThisPolyfillPlugin()); } if (useDispatchVuePlugin) { plugins.push(new webpackPluginDispatchVue.DispatchVuePlugin(dispatchVuePluginOptions || {})); } if (useDispatchScriptPlugin) { plugins.push(new webpackPluginDispatchScript.DispatchScriptPlugin(dispatchScriptPluginOptions || {})); } if (useAddPlaceHolderPlugin) { plugins.push(new webpackPluginAddPlaceholder.AddPlaceHolderPlugin()); } if (mpPluginName) { plugins.push(new webpackPluginFixImportPath.FixImportPathPlugin({ pluginName: mpPluginName, })); plugins.push(new webpackPluginGenMpPluginPlayground.GenMpPluginPlaygroundPlugin({ pluginName: mpPluginName, })); } } else { if (isProduction && process.env.VUE_APP_ROUTER_BASE && process.env.VUE_APP_ROUTER_BASE !== '/') { updateManifest('h5.router.base', JSON.stringify(process.env.VUE_APP_ROUTER_BASE)); } if (process.env.VUE_APP_BRANCH !== 'release' && process.env.UNI_OPT_TREESHAKINGNG) { delete process.env.UNI_OPT_TREESHAKINGNG; } if (process.env.VUE_APP_DIR && outputDirMode) { process.env.UNI_OUTPUT_DIR = outputDirMode.replace('${VUE_APP_DIR}', process.env.VUE_APP_DIR || ''); } else { process.env.UNI_OUTPUT_DIR = `${(process.env.UNI_INPUT_DIR || '').replace('src/project', 'dist/project')}/static`; } plugins.push(new webpackPluginGenVersion.GenVersionWebPlugin(genVersionWebPluginOptions)); if (isProduction) { plugins.push(new webpackPluginCheckLongConstant.CheckLongConstantPlugin()); } } if (useCopyDirPlugin) { plugins.push(new webpackPluginCopyDir.CopyDirPlugin(copyDirPluginOptions || {})); } plugins.push(new webpack__default["default"].DefinePlugin({ ROUTES: webpack__default["default"].DefinePlugin.runtimeValue(() => { const tfPages = new TransformPages__default["default"]({ includes: ['path', 'name', 'aliasPath', 'meta'], }); return JSON.stringify(tfPages.routes); }, true), VERSION: new Date().getTime(), })); if (shared.checkBundleAnalyze()) { plugins.push(new webpackBundleAnalyzer.BundleAnalyzerPlugin({ analyzerPort: 8888, })); } else if (saveBundleAnalyzeHtml && isProduction) { plugins.push(new webpackBundleAnalyzer.BundleAnalyzerPlugin({ analyzerMode: 'static', openAnalyzer: false, reportFilename: 'my-bundle-analyze.html', ...(typeof saveBundleAnalyzeHtml === 'object' ? saveBundleAnalyzeHtml : {}), })); } if (useFixMiniCssPlugin) { plugins.push(new webpackPluginFixMiniCssPlugin.FixMiniCssPlugin()); } plugins.push(new ProgressBarPlugin__default["default"]({ format: ` build [:bar] ${chalk__default["default"].green.bold(':percent')} (:elapsed seconds)`, clear: false, })); const externalScripts = getExternalScripts({ aegisWebSdkExternal, uniSimpleRouterExternal, axiosExternal, vueLazyloadExternal, }); if (externalScripts.length && shared.checkH5()) { plugins.push(new webpackPluginInsertScript.InsertScriptPlugin({ scripts: externalScripts, })); } if (customPreload && shared.checkH5()) { plugins.push(...[ new webpackPluginCustomPreload.CustomPreloadPlugin(typeof customPreload === 'boolean' ? {} : customPreload), new webpackPluginManifestExpose.ManifestExposePlugin(), new ScriptExtHtmlWebpackPlugin__default["default"]({ inline: /runtime/, }), ]); } if (useReplaceUniH5Plugin && shared.checkH5()) { plugins.push(new webpackPluginReplaceUniH5.ReplaceUniH5Plugin(useReplaceUniH5Plugin)); } if (shared.checkH5() && useWorkBoxPlugin && isProduction) { plugins.push(new WorkboxPlugin__default["default"].GenerateSW({ swDest: `./service-worker-${shared.getProjectName()}-${shared.getSubProjectName()}.js`, clientsClaim: true, include: [/.*(.js|.css|.svg|.png|.jpg|.jpeg)/], skipWaiting: true, maximumFileSizeToCacheInBytes: 25 * 1024 * 1024, importScripts: [], inlineWorkboxRuntime: true, runtimeCaching: [{ urlPattern: new RegExp('^https://image-1251917893\\.file\\.myqcloud.com.*(\\.js|\\.css|\\.svg|\\.png|\\.jpg|\\.jpeg)'), handler: 'StaleWhileRevalidate', options: { cacheableResponse: { statuses: [0, 200], }, }, }, { urlPattern: /.*\.html$/, handler: 'NetworkOnly', }], ...useWorkBoxPlugin, })); } return plugins; } const curDirname = shared.getRootDir(); function getDefaultNeedSourceMap() { const needSourceMap = shared.checkH5() && process.env.NODE_ENV === 'production' && tComm.getGitCurBranch(__dirname) === 'release'; return needSourceMap; } // 获取目下所有项目文件夹名称并创建webpack别名 function getAllAppNameAlias(usePMDBusinessAlias = false) { const files = fs__namespace.readdirSync(path__namespace.resolve(curDirname, 'src')); const result = { foldername: [], filename: [], // 文件名,有后缀 }; files.forEach((file) => { const pathname = path__namespace.join(curDirname, 'src', file); const stat = fs__namespace.lstatSync(pathname); if (!stat.isDirectory()) { result.filename.push(file); } else { result.foldername.push(file); } }); const rootDir = 'src'; const alias = { src: path__namespace.resolve(curDirname, rootDir), '@': path__namespace.resolve(process.env.UNI_INPUT_DIR || ''), // 由环境变量确定当前的项目 }; result.foldername.forEach((dir) => { alias[dir] = path__namespace.resolve(curDirname, rootDir, dir); }); if (usePMDBusinessAlias) { return { ...alias, 'src/component': 'pmd-business', }; } return alias; } function getUniVueConfig(options = {}) { const { useDispatchScriptPlugin, dispatchScriptPluginOptions, useDispatchVuePlugin, dispatchVuePluginOptions, useCopyDirPlugin, copyDirPluginOptions, useAddPlaceHolderPlugin, remToRpxPluginMpOptions, genVersionWebPluginOptions, useFixMiniCssPlugin, aegisWebSdkExternal = true, uniSimpleRouterExternal = false, axiosExternal = false, customPreload = false, usePMDBusinessAlias = false, } = options || {}; let transpileDependencies = shared.DEFAULT_TRANSPILE_DEPENDENCIES; let adapterDirs = shared.DEFAULT_ADAPTER_DIRS; let needSourceMap = getDefaultNeedSourceMap(); if (options?.adapterDirs) { adapterDirs = options.adapterDirs || []; } if (options?.transpileDependencies) { transpileDependencies = options.transpileDependencies; } if (typeof options?.needSourceMap === 'boolean') { needSourceMap = options.needSourceMap; } const useH5SplitChunks = shared.checkH5() && process.env.NODE_ENV === 'production' ? options?.useH5SplitChunks : false; const optimization = {}; if (useH5SplitChunks) { optimization.runtimeChunk = { name: 'runtime' }; } if (shared.checkDebugMode()) { optimization.minimize = false; } return { parallel: process.env.NODE_ENV !== 'production', lintOnSave: options.lintOnSave || false, configureWebpack: { resolve: { alias: { // 添加游戏人生alias ...getAllAppNameAlias(usePMDBusinessAlias), }, }, externals: getExternals({ aegisWebSdkExternal, uniSimpleRouterExternal, axiosExternal, vueLazyloadExternal: options.vueLazyloadExternal, }), plugins: getPlugins({ adapterDirs, useDispatchScriptPlugin, dispatchScriptPluginOptions, useDispatchVuePlugin, dispatchVuePluginOptions, useCopyDirPlugin, copyDirPluginOptions, useAddPlaceHolderPlugin, remToRpxPluginMpOptions, genVersionWebPluginOptions, useFixMiniCssPlugin, aegisWebSdkExternal, uniSimpleRouterExternal, axiosExternal, vueLazyloadExternal: options.vueLazyloadExternal, customPreload, useWorkBoxPlugin: options.useWorkBoxPlugin, saveBundleAnalyzeHtml: options.saveBundleAnalyzeHtml, useReplaceUniH5Plugin: options.useReplaceUniH5Plugin, outputDirMode: options.outputDirMode ?? 'dist/${VUE_APP_DIR}/static', }), module: { rules: [ { test: /\.(css)$/, use: [webpackLoaderCssUrlBlankSpace.LOADER], }, ], }, optimization, ...(needSourceMap ? { devtool: 'hidden-source-map', } : {}), // watchOptions: { // ignored: [/node_modules/], // }, }, css: { loaderOptions: { scss: { sassOptions: { silenceDeprecations: ['import', 'legacy-js-api'], quietDeps: true, }, }, }, }, ...(useH5SplitChunks ? { pages: optimizationH5(useH5SplitChunks).pages } : {}), transpileDependencies, chainWebpack(config) { chainWebpack(config, options); if (useH5SplitChunks) { optimizationH5(useH5SplitChunks).chainWebpack(config); } }, }; } exports.getUniVueConfig = getUniVueConfig;