Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

support nsconfig in webpack templates #1137

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
18 changes: 17 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require("path");
const { existsSync } = require("fs");
const { existsSync, readFileSync } = require("fs");
const { ANDROID_APP_PATH } = require("./androidProjectHelpers");
const {
getPackageJson,
Expand Down Expand Up @@ -110,6 +110,22 @@ exports.getAppPath = (platform, projectDir) => {
}
};

exports.getNSConfigPaths = (projectDir, defaultAppPath, defaultAppResourcePath) => {
let appPath = defaultAppPath || "app";
let appResourcesPath = defaultAppResourcePath || "app/App_Resources";
const nsConfigPath = path.join(projectDir, 'nsconfig.json');
if (existsSync(nsConfigPath)) {
const nsConfig = readFileSync(nsConfigPath).toJSON();
if (nsConfig.appPath) {
appPath = nsConfig.appPath;
}
if (nsConfig.appResourcesPath) {
appResourcesPath = nsConfig.appResourcesPath;
}
}
return { appPath, appResourcesPath };
};

/**
* For backward compatibility. This method is deprecated. Do not use it anymore.
* This method also has a bug of not escaping valid regex symbols in entry path.
Expand Down
10 changes: 6 additions & 4 deletions templates/webpack.angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ module.exports = env => {
// Default destination inside platforms/<platform>/...
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));


const {
// The 'appPath' and 'appResourcesPath' values are fetched from
// the nsconfig.json configuration file.
appPath = "src",
appResourcesPath = "App_Resources",

// the nsconfig.json configuration file
appPath,
appResourcesPath
} = nsWebpack.getNSConfigPaths(projectRoot, "src")
const {
// You can provide the following flags when running 'tns run android|ios'
aot, // --env.aot
snapshot, // --env.snapshot,
Expand Down
1 change: 1 addition & 0 deletions templates/webpack.config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const nativeScriptDevWebpack = {
WatchStateLoggerPlugin: EmptyClass,
PlatformFSPlugin: EmptyClass,
getAppPath: () => 'app',
getNSConfigPaths: () => ({ appPath: 'app', appResourcesPath: 'app/App_Resources' }),
getEntryModule: () => 'EntryModule',
hasRootLevelScopedModules: () => false,
hasRootLevelScopedAngular: () => false,
Expand Down
9 changes: 5 additions & 4 deletions templates/webpack.javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ module.exports = env => {

const {
// The 'appPath' and 'appResourcesPath' values are fetched from
// the nsconfig.json configuration file.
appPath = "app",
appResourcesPath = "app/App_Resources",

// the nsconfig.json configuration file
appPath,
appResourcesPath
} = nsWebpack.getNSConfigPaths(projectRoot)
const {
// You can provide the following flags when running 'tns run android|ios'
snapshot, // --env.snapshot
production, // --env.production
Expand Down
9 changes: 5 additions & 4 deletions templates/webpack.typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ module.exports = env => {

const {
// The 'appPath' and 'appResourcesPath' values are fetched from
// the nsconfig.json configuration file.
appPath = "app",
appResourcesPath = "app/App_Resources",

// the nsconfig.json configuration file
appPath,
appResourcesPath
} = nsWebpack.getNSConfigPaths(projectRoot)
const {
// You can provide the following flags when running 'tns run android|ios'
snapshot, // --env.snapshot
production, // --env.production
Expand Down
9 changes: 5 additions & 4 deletions templates/webpack.vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ module.exports = env => {

const {
// The 'appPath' and 'appResourcesPath' values are fetched from
// the nsconfig.json configuration file.
appPath = "app",
appResourcesPath = "app/App_Resources",

// the nsconfig.json configuration file
appPath,
appResourcesPath
} = nsWebpack.getNSConfigPaths(projectRoot)
const {
// You can provide the following flags when running 'tns run android|ios'
snapshot, // --env.snapshot
production, // --env.production
Expand Down