Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use relative path from CWD for webpack config file #1735

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const loadUserConfig = require("./util/load-user-config");
const Path = require("path");
const customCheck = require("@xarc/webpack/lib/util/custom-check");
const webpackCovCfg = require(customCheck.getWebpackStartConfig(
"../webpack/webpack.config.coverage"
"../webpack/webpack.config.coverage",
false
));

module.exports = function(config) {
Expand Down
5 changes: 4 additions & 1 deletion packages/xarc-app-dev/src/config/karma/karma.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ const DLL_PATHS = loadElectrodeDll().map(x => require.resolve(x));
function loadWebpackConfig() {
if (!process.env.KARMA_RUN_TYPE) {
process.env.KARMA_RUN_TYPE = "base";
return require(customCheck.getWebpackStartConfig("@xarc/webpack/lib/webpack.config.test"));
return require(customCheck.getWebpackStartConfig(
"@xarc/webpack/lib/webpack.config.test",
false
));
}

return {};
Expand Down
2 changes: 1 addition & 1 deletion packages/xarc-app-dev/src/lib/dev-admin/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Middleware {
setup() {
const options = this._options;

const config = require(getWebpackStartConfig("webpack.config.dev.js"));
const config = require(getWebpackStartConfig("webpack.config.dev.js", false));

this._hmrPath = controlPaths.hmr;

Expand Down
15 changes: 10 additions & 5 deletions packages/xarc-webpack/src/util/custom-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ function useAppWebpackConfig() {
return process.env.USE_APP_WEBPACK_CONFIG === "true";
}

function getWebpackStartConfig(defaultFile) {
function getWebpackStartConfig(defaultFile: string, relativeToCwd = true) {
const customFilePath = Path.resolve("webpack.config.js");
const canUseAppProfile = useAppWebpackConfig() && Fs.existsSync(customFilePath);

if (canUseAppProfile) {
return customFilePath;
}
const configFilePath = canUseAppProfile
? customFilePath
: Path.join(archetype.config.webpack, defaultFile || "webpack.config.js");

return Path.join(archetype.config.webpack, defaultFile || "webpack.config.js");
if (relativeToCwd && Path.isAbsolute(configFilePath)) {
const cwdRel = Path.relative(process.cwd(), configFilePath);
return cwdRel.length < configFilePath.length ? cwdRel : configFilePath;
} else {
return configFilePath;
}
}

function setWebpackProfile(profile) {
Expand Down