|
@@ -2,6 +2,9 @@ import { defineConfig, type UserConfigExport } from '@tarojs/cli';
|
|
|
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
|
|
|
import devConfig from './dev';
|
|
|
import prodConfig from './prod';
|
|
|
+import path from 'path';
|
|
|
+import TerserPlugin from 'terser-webpack-plugin';
|
|
|
+import webpack, { DefinePlugin } from 'webpack';
|
|
|
|
|
|
// https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
|
|
|
export default defineConfig<'webpack5'>(async (merge) => {
|
|
@@ -47,15 +50,15 @@ export default defineConfig<'webpack5'>(async (merge) => {
|
|
|
},
|
|
|
},
|
|
|
h5: {
|
|
|
- publicPath: '/',
|
|
|
+ publicPath: './',
|
|
|
staticDirectory: 'static',
|
|
|
output: {
|
|
|
- filename: 'js/[name].[hash:8].js',
|
|
|
+ filename: '[name].js',
|
|
|
chunkFilename: 'js/[name].[chunkhash:8].js',
|
|
|
},
|
|
|
miniCssExtractPluginOption: {
|
|
|
ignoreOrder: true,
|
|
|
- filename: 'css/[name].[hash].css',
|
|
|
+ filename: 'css/[name].[fullhash].css',
|
|
|
chunkFilename: 'css/[name].[chunkhash].css',
|
|
|
},
|
|
|
postcss: {
|
|
@@ -67,12 +70,22 @@ export default defineConfig<'webpack5'>(async (merge) => {
|
|
|
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
|
config: {
|
|
|
namingPattern: 'module', // 转换模式,取值为 global/module
|
|
|
- generateScopedName: '[name]__[local]___[hash:base64:5]',
|
|
|
+ generateScopedName: '[name]__[local]___[fullhash:base64:5]',
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
webpackChain(chain) {
|
|
|
- chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin);
|
|
|
+ chain.cache(false);
|
|
|
+ chain.output.path(path.resolve(__dirname, '../dist/h5'));
|
|
|
+ chain.optimization.minimize(false); // 彻底关闭压缩
|
|
|
+ // chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin);
|
|
|
+ chain.resolve
|
|
|
+ .plugin('tsconfig-paths')
|
|
|
+ .use(TsconfigPathsPlugin, [{
|
|
|
+ configFile: path.resolve(__dirname, '../tsconfig.json'), // 必须指向存在的 tsconfig
|
|
|
+ }]);
|
|
|
+ // 打开详细日志
|
|
|
+ chain.mode('production').stats('verbose');
|
|
|
chain.merge({
|
|
|
resolve: {
|
|
|
fallback: {
|
|
@@ -83,7 +96,25 @@ export default defineConfig<'webpack5'>(async (merge) => {
|
|
|
},
|
|
|
},
|
|
|
});
|
|
|
+ chain.optimization
|
|
|
+ .minimizer('terser')
|
|
|
+ .use(TerserPlugin, [{
|
|
|
+ parallel: false, // 单线程,错误不会丢
|
|
|
+ terserOptions: {
|
|
|
+ compress: false, // 先不压缩,只混淆
|
|
|
+ mangle: false,
|
|
|
+ format: {
|
|
|
+ comments: false,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ } as any]);
|
|
|
+ chain.plugin('define-plugin')
|
|
|
+ .use(DefinePlugin as any, [{
|
|
|
+ 'process.env.USE_MSW': JSON.stringify(process.env.USE_MSW || 'false'),
|
|
|
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'),
|
|
|
+ }]);
|
|
|
},
|
|
|
+
|
|
|
},
|
|
|
rn: {
|
|
|
appName: 'taroDemo',
|