mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
feat: 只在prod开压缩
This commit is contained in:
parent
035fe51d36
commit
14bc847bcc
@ -131,7 +131,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod
|
|||||||
.end()
|
.end()
|
||||||
.use('swc-loader')
|
.use('swc-loader')
|
||||||
.loader(require.resolve('swc-loader'))
|
.loader(require.resolve('swc-loader'))
|
||||||
.options(buildSwcOptions(targets, config, false, false, true));
|
.options(buildSwcOptions(targets, config, false, false, true, false));
|
||||||
webpackConfig.module
|
webpackConfig.module
|
||||||
.rule('jsx')
|
.rule('jsx')
|
||||||
.test(/\.jsx$/)
|
.test(/\.jsx$/)
|
||||||
@ -139,7 +139,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod
|
|||||||
.end()
|
.end()
|
||||||
.use('swc-loader')
|
.use('swc-loader')
|
||||||
.loader(require.resolve('swc-loader'))
|
.loader(require.resolve('swc-loader'))
|
||||||
.options(buildSwcOptions(targets, config, true, false, true));
|
.options(buildSwcOptions(targets, config, true, false, true, false));
|
||||||
|
|
||||||
webpackConfig.module
|
webpackConfig.module
|
||||||
.rule('ts')
|
.rule('ts')
|
||||||
@ -148,7 +148,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod
|
|||||||
.end()
|
.end()
|
||||||
.use('swc-loader')
|
.use('swc-loader')
|
||||||
.loader(require.resolve('swc-loader'))
|
.loader(require.resolve('swc-loader'))
|
||||||
.options(buildSwcOptions(targets, config, false, true));
|
.options(buildSwcOptions(targets, config, false, true, false));
|
||||||
webpackConfig.module
|
webpackConfig.module
|
||||||
.rule('tsx')
|
.rule('tsx')
|
||||||
.test(/\.tsx$/)
|
.test(/\.tsx$/)
|
||||||
@ -156,7 +156,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod
|
|||||||
.end()
|
.end()
|
||||||
.use('swc-loader')
|
.use('swc-loader')
|
||||||
.loader(require.resolve('swc-loader'))
|
.loader(require.resolve('swc-loader'))
|
||||||
.options(buildSwcOptions(targets, config, true, true));
|
.options(buildSwcOptions(targets, config, true, true, false));
|
||||||
// 为了避免第三方依赖包编译不充分导致线上问题,默认对 node_modules 也进行全编译,只在生产构建的时候进行
|
// 为了避免第三方依赖包编译不充分导致线上问题,默认对 node_modules 也进行全编译,只在生产构建的时候进行
|
||||||
if (isProd) {
|
if (isProd) {
|
||||||
const cjsReg = [/css-loader/].concat(config.swcLoader?.cjsPkg || []);
|
const cjsReg = [/css-loader/].concat(config.swcLoader?.cjsPkg || []);
|
||||||
@ -178,7 +178,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod
|
|||||||
.end()
|
.end()
|
||||||
.use('swc-loader')
|
.use('swc-loader')
|
||||||
.loader(require.resolve('swc-loader'))
|
.loader(require.resolve('swc-loader'))
|
||||||
.options(buildSwcOptions(targets, config, false, false, true));
|
.options(buildSwcOptions(targets, config, false, false, true, true));
|
||||||
webpackConfig.module
|
webpackConfig.module
|
||||||
.rule('cjs-in-node_modules')
|
.rule('cjs-in-node_modules')
|
||||||
.test(/\.(js)$/)
|
.test(/\.(js)$/)
|
||||||
@ -197,7 +197,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod
|
|||||||
.end()
|
.end()
|
||||||
.use('swc-loader')
|
.use('swc-loader')
|
||||||
.loader(require.resolve('swc-loader'))
|
.loader(require.resolve('swc-loader'))
|
||||||
.options(buildSwcOptions(targets, config, false, false, false));
|
.options(buildSwcOptions(targets, config, false, false, false, true));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const babelOpts = await getBabelOpts({
|
const babelOpts = await getBabelOpts({
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { deepmerge } from '@fesjs/utils';
|
import { deepmerge } from '@fesjs/utils';
|
||||||
|
|
||||||
export function buildSwcOptions(targets, config, isJsx, isTs, isEsm) {
|
export function buildSwcOptions(targets, config, isJsx, isTs, isEsm, minify) {
|
||||||
if (config.swcLoader?.cjsPkg) {
|
if (config.swcLoader?.cjsPkg) {
|
||||||
delete config.swcLoader.cjsPkg;
|
delete config.swcLoader.cjsPkg;
|
||||||
}
|
}
|
||||||
@ -17,15 +17,17 @@ export function buildSwcOptions(targets, config, isJsx, isTs, isEsm) {
|
|||||||
syntax: isTs ? 'typescript' : 'ecmascript',
|
syntax: isTs ? 'typescript' : 'ecmascript',
|
||||||
jsx: isJsx,
|
jsx: isJsx,
|
||||||
},
|
},
|
||||||
experimental: {
|
experimental: isJsx
|
||||||
plugins: [['swc-plugin-vue-jsx', {}]],
|
? {
|
||||||
},
|
plugins: [['swc-plugin-vue-jsx', {}]],
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
// preserveAllComments: true,
|
// preserveAllComments: true,
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
type: isEsm ? 'es6' : 'commonjs',
|
type: isEsm ? 'es6' : 'commonjs',
|
||||||
},
|
},
|
||||||
// minify: true,
|
minify,
|
||||||
},
|
},
|
||||||
config.swcLoader || {},
|
config.swcLoader || {},
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user