1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import type { UserConfigExport } from '@tarojs/cli';
- export default {
- mini: {},
- h5: {
- /**
- * WebpackChain 插件配置
- * @docs https://github.com/neutrinojs/webpack-chain
- */
- webpackChain(chain) {
- // /**
- // * 如果 h5 端编译后体积过大,可以使用 webpack-bundle-analyzer 插件对打包体积进行分析。
- // * @docs https://github.com/webpack-contrib/webpack-bundle-analyzer
- // */
- // chain.plugin('analyzer')
- // .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
- // /**
- // * 如果 h5 端首屏加载时间过长,可以使用 prerender-spa-plugin 插件预加载首页。
- // * @docs https://github.com/chrisvfritz/prerender-spa-plugin
- // */
- // const path = require('path')
- // const Prerender = require('prerender-spa-plugin')
- // const staticDir = path.join(__dirname, '..', 'dist')
- // chain
- // .plugin('prerender')
- // .use(new Prerender({
- // staticDir,
- // routes: [ '/pages/index/index' ],
- // postProcess: (context) => ({ ...context, outputPath: path.join(staticDir, 'index.html') })
- // }))
- chain.module
- .rule('replace-a2b')
- .test(/\.[jt]sx?$/) // 作用于 .js/.ts/.jsx/.tsx
- .use('string-replace-loader')
- .loader('string-replace-loader')
- .options({
- search: 'localhost:10086', // 要替换的字符串/正则
- replace: '192.168.11.12:6001', // 替换成的字符串
- flags: 'g', // 全局替换
- })
- .before('babel-loader'); // 必须在 babel-loader 之前执行,防止被转码后匹配不到
- },
- },
- } satisfies UserConfigExport<'webpack5'>;
|