UNPKG

@aniyajs/rotor

Version:

基于webpack5开发的一款专注于打包、运行的工具

61 lines (51 loc) 1.41 kB
const path = require("path"); const paths = require("../utils/paths"); const webpackConfig = require("./webpack.config"); const fs = require("fs-extra"); const defaultConfig = require("../webpack/defaultConfig")( paths.appConfigTempIndexJs, ); function getClientEnvironment() { let stringified = {}; Object.assign(stringified, { ...Object.keys(defaultConfig?.define).reduce((env, key) => { env[key] = typeof defaultConfig?.define[key] === "string" ? JSON.stringify(defaultConfig?.define[key]) : defaultConfig?.define[key]; return env; }, {}), }); if ( fs.existsSync( path.join( paths.appConfigIndexDirTempPath, `config.${process.env.ANIYAJS_ENV}.js`, ), ) ) { const oldDefine = require( path.resolve( paths.appConfigIndexDirTempPath, `config.${process.env.ANIYAJS_ENV}.js`, ), ).default?.define; Object.assign(stringified, { ...Object.keys(oldDefine).reduce((env, key) => { env[key] = typeof oldDefine[key] === "string" ? JSON.stringify(oldDefine[key]) : oldDefine[key]; return env; }, {}), }); } const configFactory = webpackConfig(defaultConfig, stringified); return { raw: { ...defaultConfig, }, latestConfig: configFactory, }; } module.exports = getClientEnvironment;