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

feat: move all node modules to the common chunk #507

Merged
merged 4 commits into from
Apr 30, 2018
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
34 changes: 19 additions & 15 deletions templates/webpack.angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeS
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");

module.exports = env => {
// Add your custom Activities, Services and other Android app components here.
const appComponents = [
"tns-core-modules/ui/frame",
"tns-core-modules/ui/frame/activity",
];

const platform = env && (env.android && "android" || env.ios && "ios");
if (!platform) {
throw new Error("You need to provide a target platform!");
Expand All @@ -30,13 +36,12 @@ module.exports = env => {
appPath = "app",
appResourcesPath = "app/App_Resources",

// Aot, snapshot, uglify and report can be enabled by providing
// the `--env.snapshot`, `--env.uglify` or `--env.report` flags
// when running 'tns run android|ios'
aot,
snapshot,
uglify,
report,
// You can provide the following flags when running 'tns run android|ios'
production, // --env.production
aot, // --env.aot
snapshot, // --env.snapshot
uglify, // --env.uglify
report, // --env.report
} = env;
const ngToolsWebpackOptions = { tsConfigPath: join(__dirname, "tsconfig.json") };

Expand All @@ -50,7 +55,7 @@ module.exports = env => {
const vendorPath = `.${sep}vendor.ts`;

const config = {
mode: "development",
mode: production ? "production" : "development",
context: appFullPath,
watchOptions: {
ignored: [
Expand Down Expand Up @@ -104,7 +109,12 @@ module.exports = env => {
common: {
name: "common",
chunks: "all",
test: /vendor/,
test: (module, chunks) => {
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
return /[\\/]node_modules[\\/]/.test(moduleName) ||
appComponents.some(comp => comp === moduleName);

},
enforce: true,
},
}
Expand Down Expand Up @@ -199,12 +209,6 @@ module.exports = env => {
};

if (platform === "android") {
// Add your custom Activities, Services and other android app components here.
const appComponents = [
"tns-core-modules/ui/frame",
"tns-core-modules/ui/frame/activity",
];

// Require all Android app components
// in the entry module (bundle.ts) and the vendor module (vendor.ts).
config.module.rules.unshift({
Expand Down
32 changes: 18 additions & 14 deletions templates/webpack.javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeS
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");

module.exports = env => {
// Add your custom Activities, Services and other android app components here.
const appComponents = [
"tns-core-modules/ui/frame",
"tns-core-modules/ui/frame/activity",
];

const platform = env && (env.android && "android" || env.ios && "ios");
if (!platform) {
throw new Error("You need to provide a target platform!");
Expand All @@ -30,12 +36,11 @@ module.exports = env => {
appPath = "app",
appResourcesPath = "app/App_Resources",

// Snapshot, uglify and report can be enabled by providing
// the `--env.snapshot`, `--env.uglify` or `--env.report` flags
// when running 'tns run android|ios'
snapshot,
uglify,
report,
// You can provide the following flags when running 'tns run android|ios'
production, // --env.production
snapshot, // --env.snapshot
uglify, // --env.uglify
report, // --env.report
} = env;

const appFullPath = resolve(projectRoot, appPath);
Expand All @@ -46,7 +51,7 @@ module.exports = env => {
const vendorPath = `.${sep}vendor.js`;

const config = {
mode: "development",
mode: production ? "production" : "development",
context: appFullPath,
watchOptions: {
ignored: [
Expand Down Expand Up @@ -100,7 +105,12 @@ module.exports = env => {
common: {
name: "common",
chunks: "all",
test: /vendor/,
test: (module, chunks) => {
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
return /[\\/]node_modules[\\/]/.test(moduleName) ||
appComponents.some(comp => comp === moduleName);

},
enforce: true,
},
}
Expand Down Expand Up @@ -173,12 +183,6 @@ module.exports = env => {
};

if (platform === "android") {
// Add your custom Activities, Services and other android app components here.
const appComponents = [
"tns-core-modules/ui/frame",
"tns-core-modules/ui/frame/activity",
];

// Require all Android app components
// in the entry module (bundle.js) and the vendor module (vendor.js).
config.module.rules.unshift({
Expand Down
32 changes: 18 additions & 14 deletions templates/webpack.typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeS
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");

module.exports = env => {
// Add your custom Activities, Services and other Android app components here.
const appComponents = [
"tns-core-modules/ui/frame",
"tns-core-modules/ui/frame/activity",
];

const platform = env && (env.android && "android" || env.ios && "ios");
if (!platform) {
throw new Error("You need to provide a target platform!");
Expand All @@ -30,12 +36,11 @@ module.exports = env => {
appPath = "app",
appResourcesPath = "app/App_Resources",

// Snapshot, uglify and report can be enabled by providing
// the `--env.snapshot`, `--env.uglify` or `--env.report` flags
// when running 'tns run android|ios'
snapshot,
uglify,
report,
// You can provide the following flags when running 'tns run android|ios'
production, // --env.production
snapshot, // --env.snapshot
uglify, // --env.uglify
report, // --env.report
} = env;

const appFullPath = resolve(projectRoot, appPath);
Expand All @@ -46,7 +51,7 @@ module.exports = env => {
const vendorPath = `.${sep}vendor.ts`;

const config = {
mode: "development",
mode: production ? "production" : "development",
context: appFullPath,
watchOptions: {
ignored: [
Expand Down Expand Up @@ -100,7 +105,12 @@ module.exports = env => {
common: {
name: "common",
chunks: "all",
test: /vendor/,
test: (module, chunks) => {
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
return /[\\/]node_modules[\\/]/.test(moduleName) ||
appComponents.some(comp => comp === moduleName);

},
enforce: true,
},
}
Expand Down Expand Up @@ -175,12 +185,6 @@ module.exports = env => {
};

if (platform === "android") {
// Add your custom Activities, Services and other android app components here.
const appComponents = [
"tns-core-modules/ui/frame",
"tns-core-modules/ui/frame/activity",
];

// Require all Android app components
// in the entry module (bundle.ts) and the vendor module (vendor.ts).
config.module.rules.unshift({
Expand Down