mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
fix(webpack): --env.uglify works properly now (#9165)
This commit is contained in:

committed by
GitHub

parent
04a76415b7
commit
be52cefe67
@ -22,3 +22,4 @@ package.json
|
||||
*.css
|
||||
*.scss
|
||||
*.sh
|
||||
!packages/webpack/templates/*.js
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nativescript/webpack",
|
||||
"version": "4.0.1",
|
||||
"version": "4.0.2",
|
||||
"main": "index",
|
||||
"description": "Webpack plugin for NativeScript",
|
||||
"homepage": "https://nativescript.org",
|
||||
|
@ -4,34 +4,22 @@ const fs = require('fs');
|
||||
const webpack = require('webpack');
|
||||
const nsWebpack = require('@nativescript/webpack');
|
||||
const nativescriptTarget = require('@nativescript/webpack/nativescript-target');
|
||||
const {
|
||||
nsSupportHmrNg
|
||||
} = require('@nativescript/webpack/transformers/ns-support-hmr-ng');
|
||||
const { nsTransformNativeClassesNg } = require("@nativescript/webpack/transformers/ns-transform-native-classes-ng");
|
||||
const {
|
||||
parseWorkspaceConfig, hasConfigurations
|
||||
} = require('@nativescript/webpack/helpers/angular-config-parser');
|
||||
const {
|
||||
getMainModulePath
|
||||
} = require('@nativescript/webpack/utils/ast-utils');
|
||||
const { getNoEmitOnErrorFromTSConfig, getCompilerOptionsFromTSConfig } = require("@nativescript/webpack/utils/tsconfig-utils");
|
||||
const { nsSupportHmrNg } = require('@nativescript/webpack/transformers/ns-support-hmr-ng');
|
||||
const { nsTransformNativeClassesNg } = require('@nativescript/webpack/transformers/ns-transform-native-classes-ng');
|
||||
const { parseWorkspaceConfig, hasConfigurations } = require('@nativescript/webpack/helpers/angular-config-parser');
|
||||
const { getMainModulePath } = require('@nativescript/webpack/utils/ast-utils');
|
||||
const { getNoEmitOnErrorFromTSConfig, getCompilerOptionsFromTSConfig } = require('@nativescript/webpack/utils/tsconfig-utils');
|
||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||
const {
|
||||
NativeScriptWorkerPlugin
|
||||
} = require('nativescript-worker-loader/NativeScriptWorkerPlugin');
|
||||
const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
const {
|
||||
getAngularCompilerPlugin
|
||||
} = require('@nativescript/webpack/plugins/NativeScriptAngularCompilerPlugin');
|
||||
const { getAngularCompilerPlugin } = require('@nativescript/webpack/plugins/NativeScriptAngularCompilerPlugin');
|
||||
const hashSalt = Date.now().toString();
|
||||
|
||||
module.exports = env => {
|
||||
module.exports = (env) => {
|
||||
// Add your custom Activities, Services and other Android app components here.
|
||||
const appComponents = [
|
||||
"@nativescript/core/ui/frame", "@nativescript/core/ui/frame/activity"
|
||||
];
|
||||
const appComponents = ['@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity'];
|
||||
|
||||
const platform = env && ((env.android && 'android') || (env.ios && 'ios'));
|
||||
if (!platform) {
|
||||
@ -42,10 +30,7 @@ module.exports = env => {
|
||||
const projectRoot = __dirname;
|
||||
|
||||
// Default destination inside platforms/<platform>/...
|
||||
const dist = resolve(
|
||||
projectRoot,
|
||||
nsWebpack.getAppPath(platform, projectRoot)
|
||||
);
|
||||
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
|
||||
|
||||
const {
|
||||
// The 'appPath' and 'appResourcesPath' values are fetched from
|
||||
@ -70,7 +55,7 @@ module.exports = env => {
|
||||
ci, // --env.ci
|
||||
snapshotInDocker, // --env.snapshotInDocker
|
||||
skipSnapshotTools, // --env.skipSnapshotTools
|
||||
compileSnapshot // --env.compileSnapshot
|
||||
compileSnapshot, // --env.compileSnapshot
|
||||
} = env;
|
||||
|
||||
const { fileReplacements, copyReplacements } = parseWorkspaceConfig(platform, configuration, projectName);
|
||||
@ -99,12 +84,9 @@ module.exports = env => {
|
||||
const entryModule = `${nsWebpack.getEntryModule(appFullPath, platform)}.ts`;
|
||||
const entryPath = `.${sep}${entryModule}`;
|
||||
const entries = { bundle: entryPath };
|
||||
const areCoreModulesExternal =
|
||||
Array.isArray(env.externals) &&
|
||||
env.externals.some(e => e.indexOf('@nativescript') > -1);
|
||||
const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some((e) => e.indexOf('@nativescript') > -1);
|
||||
if (platform === 'ios' && !areCoreModulesExternal && !testing) {
|
||||
entries['tns_modules/@nativescript/core/inspector_modules'] =
|
||||
'inspector_modules';
|
||||
entries['tns_modules/@nativescript/core/inspector_modules'] = 'inspector_modules';
|
||||
}
|
||||
|
||||
const compilerOptions = getCompilerOptionsFromTSConfig(tsConfigPath);
|
||||
@ -115,11 +97,7 @@ module.exports = env => {
|
||||
const additionalLazyModuleResources = [];
|
||||
|
||||
const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] };
|
||||
const copyTargets = [
|
||||
{ from: { glob: 'assets/**', dot: false } },
|
||||
{ from: { glob: 'fonts/**', dot: false } },
|
||||
...copyReplacements,
|
||||
];
|
||||
const copyTargets = [{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, ...copyReplacements];
|
||||
|
||||
if (!production) {
|
||||
// for development purposes only
|
||||
@ -135,14 +113,9 @@ module.exports = env => {
|
||||
// directly from node_modules and the Angular modules loader won't be able to resolve the lazy routes
|
||||
// fixes https://github.com/NativeScript/nativescript-cli/issues/4024
|
||||
if (env.externals && env.externals.indexOf('@angular/core') > -1) {
|
||||
const appModuleRelativePath = getMainModulePath(
|
||||
resolve(appFullPath, entryModule),
|
||||
tsConfigName
|
||||
);
|
||||
const appModuleRelativePath = getMainModulePath(resolve(appFullPath, entryModule), tsConfigName);
|
||||
if (appModuleRelativePath) {
|
||||
const appModuleFolderPath = dirname(
|
||||
resolve(appFullPath, appModuleRelativePath)
|
||||
);
|
||||
const appModuleFolderPath = dirname(resolve(appFullPath, appModuleRelativePath));
|
||||
// include the new lazy loader path in the allowed ones
|
||||
additionalLazyModuleResources.push(appModuleFolderPath);
|
||||
}
|
||||
@ -150,48 +123,21 @@ module.exports = env => {
|
||||
|
||||
const ngCompilerPlugin = new AngularCompilerPlugin({
|
||||
hostReplacementPaths: nsWebpack.getResolver([platform, 'tns']),
|
||||
platformTransformers: ngCompilerTransformers.map(t =>
|
||||
t(() => ngCompilerPlugin, resolve(appFullPath, entryModule), projectRoot)
|
||||
),
|
||||
platformTransformers: ngCompilerTransformers.map((t) => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule), projectRoot)),
|
||||
mainPath: join(appFullPath, entryModule),
|
||||
tsConfigPath,
|
||||
skipCodeGeneration: false,
|
||||
sourceMap: !!isAnySourceMapEnabled,
|
||||
additionalLazyModuleResources: additionalLazyModuleResources,
|
||||
compilerOptions: { paths: compilerOptions.paths }
|
||||
compilerOptions: { paths: compilerOptions.paths },
|
||||
});
|
||||
|
||||
let sourceMapFilename = nsWebpack.getSourceMapFilename(
|
||||
hiddenSourceMap,
|
||||
__dirname,
|
||||
dist
|
||||
);
|
||||
let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
|
||||
|
||||
const itemsToClean = [`${dist}/**/*`];
|
||||
if (platform === 'android') {
|
||||
itemsToClean.push(
|
||||
`${join(
|
||||
projectRoot,
|
||||
'platforms',
|
||||
'android',
|
||||
'app',
|
||||
'src',
|
||||
'main',
|
||||
'assets',
|
||||
'snapshots'
|
||||
)}`
|
||||
);
|
||||
itemsToClean.push(
|
||||
`${join(
|
||||
projectRoot,
|
||||
'platforms',
|
||||
'android',
|
||||
'app',
|
||||
'build',
|
||||
'configurations',
|
||||
'nativescript-android-snapshot'
|
||||
)}`
|
||||
);
|
||||
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`);
|
||||
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`);
|
||||
}
|
||||
|
||||
const noEmitOnErrorFromTSConfig = getNoEmitOnErrorFromTSConfig(tsConfigName);
|
||||
@ -205,8 +151,8 @@ module.exports = env => {
|
||||
ignored: [
|
||||
appResourcesFullPath,
|
||||
// Don't watch hidden files
|
||||
'**/.*'
|
||||
]
|
||||
'**/.*',
|
||||
],
|
||||
},
|
||||
target: nativescriptTarget,
|
||||
entry: entries,
|
||||
@ -217,28 +163,23 @@ module.exports = env => {
|
||||
libraryTarget: 'commonjs2',
|
||||
filename: '[name].js',
|
||||
globalObject: 'global',
|
||||
hashSalt
|
||||
hashSalt,
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js', '.scss', '.css'],
|
||||
// Resolve {N} system modules from @nativescript/core
|
||||
modules: [
|
||||
resolve(__dirname, 'node_modules/@nativescript/core'),
|
||||
resolve(__dirname, 'node_modules'),
|
||||
'node_modules/@nativescript/core',
|
||||
'node_modules'
|
||||
],
|
||||
modules: [resolve(__dirname, 'node_modules/@nativescript/core'), resolve(__dirname, 'node_modules'), 'node_modules/@nativescript/core', 'node_modules'],
|
||||
alias: {
|
||||
'~/package.json': resolve(projectRoot, 'package.json'),
|
||||
'~': appFullPath,
|
||||
"tns-core-modules": "@nativescript/core",
|
||||
"nativescript-angular": "@nativescript/angular",
|
||||
...fileReplacements
|
||||
'tns-core-modules': '@nativescript/core',
|
||||
'nativescript-angular': '@nativescript/angular',
|
||||
...fileReplacements,
|
||||
},
|
||||
symlinks: true
|
||||
symlinks: true,
|
||||
},
|
||||
resolveLoader: {
|
||||
symlinks: false
|
||||
symlinks: false,
|
||||
},
|
||||
node: {
|
||||
// Disable node shims that conflict with NativeScript
|
||||
@ -246,13 +187,9 @@ module.exports = env => {
|
||||
timers: false,
|
||||
setImmediate: false,
|
||||
fs: 'empty',
|
||||
__dirname: false
|
||||
__dirname: false,
|
||||
},
|
||||
devtool: hiddenSourceMap
|
||||
? 'hidden-source-map'
|
||||
: sourceMap
|
||||
? 'inline-source-map'
|
||||
: 'none',
|
||||
devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none',
|
||||
optimization: {
|
||||
runtimeChunk: 'single',
|
||||
noEmitOnErrors: noEmitOnErrorFromTSConfig,
|
||||
@ -262,17 +199,12 @@ module.exports = env => {
|
||||
name: 'vendor',
|
||||
chunks: 'all',
|
||||
test: (module, chunks) => {
|
||||
const moduleName = module.nameForCondition
|
||||
? module.nameForCondition()
|
||||
: '';
|
||||
return (
|
||||
/[\\/]node_modules[\\/]/.test(moduleName) ||
|
||||
appComponents.some(comp => comp === moduleName)
|
||||
);
|
||||
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
|
||||
return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName);
|
||||
},
|
||||
enforce: true,
|
||||
},
|
||||
},
|
||||
enforce: true
|
||||
}
|
||||
}
|
||||
},
|
||||
minimize: !!uglify,
|
||||
minimizer: [
|
||||
@ -283,29 +215,32 @@ module.exports = env => {
|
||||
terserOptions: {
|
||||
output: {
|
||||
comments: false,
|
||||
semicolons: !isAnySourceMapEnabled
|
||||
semicolons: !isAnySourceMapEnabled,
|
||||
},
|
||||
compress: {
|
||||
// The Android SBG has problems parsing the output
|
||||
// when these options are enabled
|
||||
collapse_vars: platform !== 'android',
|
||||
sequences: platform !== 'android',
|
||||
// For v8 Compatibility
|
||||
keep_infinity: true, // for V8
|
||||
reduce_funcs: false, // for V8
|
||||
// custom
|
||||
drop_console: true,
|
||||
drop_console: production,
|
||||
drop_debugger: true,
|
||||
ecma: 6,
|
||||
keep_infinity: platform === 'android', // for Chrome/V8
|
||||
reduce_funcs: platform !== 'android', // for Chrome/V8
|
||||
global_defs: {
|
||||
__UGLIFIED__: true
|
||||
}
|
||||
__UGLIFIED__: true,
|
||||
},
|
||||
},
|
||||
// Required for Element Level CSS, Observable Events, & Android Frame
|
||||
keep_classnames: true,
|
||||
// custom
|
||||
ecma: 6,
|
||||
safari10: platform !== 'android'
|
||||
}
|
||||
})
|
||||
]
|
||||
safari10: platform !== 'android',
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
@ -315,7 +250,7 @@ module.exports = env => {
|
||||
// Require all Android app components
|
||||
platform === 'android' && {
|
||||
loader: '@nativescript/webpack/helpers/android-app-components-loader',
|
||||
options: { modules: appComponents }
|
||||
options: { modules: appComponents },
|
||||
},
|
||||
|
||||
{
|
||||
@ -326,10 +261,10 @@ module.exports = env => {
|
||||
unitTesting,
|
||||
appFullPath,
|
||||
projectRoot,
|
||||
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform)
|
||||
}
|
||||
}
|
||||
].filter(loader => !!loader)
|
||||
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform),
|
||||
},
|
||||
},
|
||||
].filter((loader) => !!loader),
|
||||
},
|
||||
|
||||
{ test: /\.html$|\.xml$/, use: 'raw-loader' },
|
||||
@ -339,8 +274,8 @@ module.exports = env => {
|
||||
use: [
|
||||
'@nativescript/webpack/helpers/style-hot-loader',
|
||||
{
|
||||
loader: "@nativescript/webpack/helpers/css2json-loader",
|
||||
options: { useForImports: true }
|
||||
loader: '@nativescript/webpack/helpers/css2json-loader',
|
||||
options: { useForImports: true },
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -349,8 +284,8 @@ module.exports = env => {
|
||||
use: [
|
||||
'@nativescript/webpack/helpers/style-hot-loader',
|
||||
{
|
||||
loader: "@nativescript/webpack/helpers/css2json-loader",
|
||||
options: { useForImports: true }
|
||||
loader: '@nativescript/webpack/helpers/css2json-loader',
|
||||
options: { useForImports: true },
|
||||
},
|
||||
'sass-loader',
|
||||
],
|
||||
@ -361,25 +296,21 @@ module.exports = env => {
|
||||
{
|
||||
test: /\.scss$/,
|
||||
exclude: /[\/|\\]app\.scss$/,
|
||||
use: ['raw-loader', 'resolve-url-loader', 'sass-loader']
|
||||
use: ['raw-loader', 'resolve-url-loader', 'sass-loader'],
|
||||
},
|
||||
|
||||
{
|
||||
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
|
||||
use: [
|
||||
'@nativescript/webpack/helpers/moduleid-compat-loader',
|
||||
'@nativescript/webpack/helpers/lazy-ngmodule-hot-loader',
|
||||
'@ngtools/webpack'
|
||||
]
|
||||
use: ['@nativescript/webpack/helpers/moduleid-compat-loader', '@nativescript/webpack/helpers/lazy-ngmodule-hot-loader', '@ngtools/webpack'],
|
||||
},
|
||||
|
||||
// Mark files inside `@angular/core` as using SystemJS style dynamic imports.
|
||||
// Removing this will cause deprecation warnings to appear.
|
||||
{
|
||||
test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/,
|
||||
parser: { system: true }
|
||||
}
|
||||
]
|
||||
parser: { system: true },
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
// Define useful constants like TNS_WEBPACK
|
||||
@ -387,27 +318,23 @@ module.exports = env => {
|
||||
'global.TNS_WEBPACK': 'true',
|
||||
'global.isAndroid': platform === 'android',
|
||||
'global.isIOS': platform === 'ios',
|
||||
process: 'global.process'
|
||||
process: 'global.process',
|
||||
}),
|
||||
// Remove all files from the out dir.
|
||||
new CleanWebpackPlugin({
|
||||
cleanOnceBeforeBuildPatterns: itemsToClean,
|
||||
verbose: !!verbose
|
||||
verbose: !!verbose,
|
||||
}),
|
||||
// Copy assets
|
||||
new CopyWebpackPlugin([
|
||||
...copyTargets,
|
||||
{ from: { glob: '**/*.jpg', dot: false } },
|
||||
{ from: { glob: '**/*.png', dot: false } },
|
||||
], copyIgnore),
|
||||
new CopyWebpackPlugin([...copyTargets, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore),
|
||||
new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'),
|
||||
// For instructions on how to set up workers with webpack
|
||||
// check out https://github.com/nativescript/worker-loader
|
||||
new NativeScriptWorkerPlugin(),
|
||||
ngCompilerPlugin,
|
||||
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
|
||||
new nsWebpack.WatchStateLoggerPlugin()
|
||||
]
|
||||
new nsWebpack.WatchStateLoggerPlugin(),
|
||||
],
|
||||
};
|
||||
|
||||
if (report) {
|
||||
@ -418,7 +345,7 @@ module.exports = env => {
|
||||
openAnalyzer: false,
|
||||
generateStatsFile: true,
|
||||
reportFilename: resolve(projectRoot, 'report', `report.html`),
|
||||
statsFilename: resolve(projectRoot, 'report', `stats.json`)
|
||||
statsFilename: resolve(projectRoot, 'report', `stats.json`),
|
||||
})
|
||||
);
|
||||
}
|
||||
@ -428,19 +355,12 @@ module.exports = env => {
|
||||
new nsWebpack.NativeScriptSnapshotPlugin({
|
||||
chunk: 'vendor',
|
||||
angular: true,
|
||||
requireModules: [
|
||||
'reflect-metadata',
|
||||
'@angular/platform-browser',
|
||||
'@angular/core',
|
||||
'@angular/common',
|
||||
'@angular/router',
|
||||
'@nativescript/angular'
|
||||
],
|
||||
requireModules: ['reflect-metadata', '@angular/platform-browser', '@angular/core', '@angular/common', '@angular/router', '@nativescript/angular'],
|
||||
projectRoot,
|
||||
webpackConfig: config,
|
||||
snapshotInDocker,
|
||||
skipSnapshotTools,
|
||||
useLibs
|
||||
useLibs,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -1,30 +1,27 @@
|
||||
const { join, relative, resolve, sep } = require("path");
|
||||
const { join, relative, resolve, sep } = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const webpack = require("webpack");
|
||||
const nsWebpack = require("@nativescript/webpack");
|
||||
const nativescriptTarget = require("@nativescript/webpack/nativescript-target");
|
||||
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
|
||||
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const webpack = require('webpack');
|
||||
const nsWebpack = require('@nativescript/webpack');
|
||||
const nativescriptTarget = require('@nativescript/webpack/nativescript-target');
|
||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||
const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
const hashSalt = Date.now().toString();
|
||||
|
||||
module.exports = env => {
|
||||
module.exports = (env) => {
|
||||
// Add your custom Activities, Services and other android app components here.
|
||||
const appComponents = env.appComponents || [];
|
||||
appComponents.push(...[
|
||||
"@nativescript/core/ui/frame",
|
||||
"@nativescript/core/ui/frame/activity",
|
||||
]);
|
||||
appComponents.push(...['@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity']);
|
||||
|
||||
const platform = env && (env.android && "android" || env.ios && "ios" || env.platform);
|
||||
const platform = env && ((env.android && 'android') || (env.ios && 'ios') || env.platform);
|
||||
if (!platform) {
|
||||
throw new Error("You need to provide a target platform!");
|
||||
throw new Error('You need to provide a target platform!');
|
||||
}
|
||||
|
||||
const platforms = ["ios", "android"];
|
||||
const platforms = ['ios', 'android'];
|
||||
const projectRoot = __dirname;
|
||||
|
||||
if (env.platform) {
|
||||
@ -37,8 +34,8 @@ module.exports = env => {
|
||||
const {
|
||||
// The 'appPath' and 'appResourcesPath' values are fetched from
|
||||
// the nsconfig.json configuration file.
|
||||
appPath = "src",
|
||||
appResourcesPath = "App_Resources",
|
||||
appPath = 'src',
|
||||
appResourcesPath = 'App_Resources',
|
||||
|
||||
// You can provide the following flags when running 'tns run android|ios'
|
||||
snapshot, // --env.snapshot
|
||||
@ -53,26 +50,28 @@ module.exports = env => {
|
||||
verbose, // --env.verbose
|
||||
snapshotInDocker, // --env.snapshotInDocker
|
||||
skipSnapshotTools, // --env.skipSnapshotTools
|
||||
compileSnapshot // --env.compileSnapshot
|
||||
ci, // --env.ci
|
||||
compileSnapshot, // --env.compileSnapshot
|
||||
} = env;
|
||||
|
||||
const useLibs = compileSnapshot;
|
||||
const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap;
|
||||
const externals = nsWebpack.getConvertedExternals(env.externals);
|
||||
|
||||
let appFullPath = resolve(projectRoot, appPath);
|
||||
if (!fs.existsSync(appFullPath)) {
|
||||
// some apps use 'app' directory
|
||||
appFullPath = resolve(projectRoot, 'app');
|
||||
}
|
||||
const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot });
|
||||
let coreModulesPackageName = "tns-core-modules";
|
||||
let coreModulesPackageName = 'tns-core-modules';
|
||||
const alias = env.alias || {};
|
||||
alias['~/package.json'] = resolve(projectRoot, 'package.json');
|
||||
alias['~'] = appFullPath;
|
||||
|
||||
if (hasRootLevelScopedModules) {
|
||||
coreModulesPackageName = "@nativescript/core";
|
||||
alias["tns-core-modules"] = coreModulesPackageName;
|
||||
coreModulesPackageName = '@nativescript/core';
|
||||
alias['tns-core-modules'] = coreModulesPackageName;
|
||||
}
|
||||
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
|
||||
|
||||
@ -83,31 +82,30 @@ module.exports = env => {
|
||||
const entries = env.entries || {};
|
||||
entries.bundle = entryPath;
|
||||
|
||||
const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some(e => e.indexOf("@nativescript") > -1);
|
||||
if (platform === "ios" && !areCoreModulesExternal && !testing) {
|
||||
entries["tns_modules/@nativescript/core/inspector_modules"] = "inspector_modules";
|
||||
};
|
||||
const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some((e) => e.indexOf('@nativescript') > -1);
|
||||
if (platform === 'ios' && !areCoreModulesExternal && !testing) {
|
||||
entries['tns_modules/@nativescript/core/inspector_modules'] = 'inspector_modules';
|
||||
}
|
||||
|
||||
let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
|
||||
|
||||
const itemsToClean = [`${dist}/**/*`];
|
||||
if (platform === "android") {
|
||||
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "src", "main", "assets", "snapshots")}`);
|
||||
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`);
|
||||
if (platform === 'android') {
|
||||
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`);
|
||||
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`);
|
||||
}
|
||||
|
||||
|
||||
nsWebpack.processAppComponents(appComponents, platform);
|
||||
const config = {
|
||||
mode: production ? "production" : "development",
|
||||
mode: production ? 'production' : 'development',
|
||||
context: appFullPath,
|
||||
externals,
|
||||
watchOptions: {
|
||||
ignored: [
|
||||
appResourcesFullPath,
|
||||
// Don't watch hidden files
|
||||
"**/.*",
|
||||
]
|
||||
'**/.*',
|
||||
],
|
||||
},
|
||||
target: nativescriptTarget,
|
||||
entry: entries,
|
||||
@ -115,74 +113,78 @@ module.exports = env => {
|
||||
pathinfo: false,
|
||||
path: dist,
|
||||
sourceMapFilename,
|
||||
libraryTarget: "commonjs2",
|
||||
filename: "[name].js",
|
||||
globalObject: "global",
|
||||
hashSalt
|
||||
libraryTarget: 'commonjs2',
|
||||
filename: '[name].js',
|
||||
globalObject: 'global',
|
||||
hashSalt,
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".js", ".scss", ".css"],
|
||||
extensions: ['.js', '.scss', '.css'],
|
||||
// Resolve {N} system modules from @nativescript/core
|
||||
modules: [
|
||||
resolve(__dirname, `node_modules/${coreModulesPackageName}`),
|
||||
resolve(__dirname, "node_modules"),
|
||||
`node_modules/${coreModulesPackageName}`,
|
||||
"node_modules",
|
||||
],
|
||||
modules: [resolve(__dirname, `node_modules/${coreModulesPackageName}`), resolve(__dirname, 'node_modules'), `node_modules/${coreModulesPackageName}`, 'node_modules'],
|
||||
alias,
|
||||
// resolve symlinks to symlinked modules
|
||||
symlinks: true
|
||||
symlinks: true,
|
||||
},
|
||||
resolveLoader: {
|
||||
// don't resolve symlinks to symlinked loaders
|
||||
symlinks: false
|
||||
symlinks: false,
|
||||
},
|
||||
node: {
|
||||
// Disable node shims that conflict with NativeScript
|
||||
"http": false,
|
||||
"timers": false,
|
||||
"setImmediate": false,
|
||||
"fs": "empty",
|
||||
"__dirname": false,
|
||||
http: false,
|
||||
timers: false,
|
||||
setImmediate: false,
|
||||
fs: 'empty',
|
||||
__dirname: false,
|
||||
},
|
||||
devtool: hiddenSourceMap ? "hidden-source-map" : (sourceMap ? "inline-source-map" : "none"),
|
||||
devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none',
|
||||
optimization: {
|
||||
runtimeChunk: "single",
|
||||
runtimeChunk: 'single',
|
||||
noEmitOnErrors: true,
|
||||
splitChunks: {
|
||||
cacheGroups: {
|
||||
vendor: {
|
||||
name: "vendor",
|
||||
chunks: "all",
|
||||
name: 'vendor',
|
||||
chunks: 'all',
|
||||
test: (module, chunks) => {
|
||||
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
|
||||
return /[\\/]node_modules[\\/]/.test(moduleName) ||
|
||||
appComponents.some(comp => comp === moduleName);
|
||||
|
||||
return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName);
|
||||
},
|
||||
enforce: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
minimize: !!uglify,
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
parallel: true,
|
||||
cache: true,
|
||||
cache: !ci,
|
||||
sourceMap: isAnySourceMapEnabled,
|
||||
terserOptions: {
|
||||
output: {
|
||||
comments: false,
|
||||
semicolons: !isAnySourceMapEnabled
|
||||
semicolons: !isAnySourceMapEnabled,
|
||||
},
|
||||
compress: {
|
||||
// The Android SBG has problems parsing the output
|
||||
// when these options are enabled
|
||||
'collapse_vars': platform !== "android",
|
||||
sequences: platform !== "android",
|
||||
}
|
||||
}
|
||||
})
|
||||
collapse_vars: platform !== 'android',
|
||||
sequences: platform !== 'android',
|
||||
// For v8 Compatibility
|
||||
keep_infinity: true, // for V8
|
||||
reduce_funcs: false, // for V8
|
||||
// custom
|
||||
drop_console: production,
|
||||
drop_debugger: true,
|
||||
global_defs: {
|
||||
__UGLIFIED__: true,
|
||||
},
|
||||
},
|
||||
// Required for Element Level CSS, Observable Events, & Android Frame
|
||||
keep_classnames: true,
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
module: {
|
||||
@ -191,66 +193,58 @@ module.exports = env => {
|
||||
include: join(appFullPath, entryPath),
|
||||
use: [
|
||||
// Require all Android app components
|
||||
platform === "android" && {
|
||||
loader: "@nativescript/webpack/helpers/android-app-components-loader",
|
||||
options: { modules: appComponents }
|
||||
platform === 'android' && {
|
||||
loader: '@nativescript/webpack/helpers/android-app-components-loader',
|
||||
options: { modules: appComponents },
|
||||
},
|
||||
|
||||
{
|
||||
loader: "@nativescript/webpack/bundle-config-loader",
|
||||
loader: '@nativescript/webpack/bundle-config-loader',
|
||||
options: {
|
||||
loadCss: !snapshot, // load the application css if in debug mode
|
||||
unitTesting,
|
||||
appFullPath,
|
||||
projectRoot,
|
||||
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform)
|
||||
}
|
||||
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform),
|
||||
},
|
||||
].filter(loader => !!loader)
|
||||
},
|
||||
].filter((loader) => !!loader),
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.(js|css|scss|html|xml)$/,
|
||||
use: "@nativescript/webpack/hmr/hot-loader"
|
||||
use: '@nativescript/webpack/hmr/hot-loader',
|
||||
},
|
||||
|
||||
{ test: /\.(html|xml)$/, use: "@nativescript/webpack/helpers/xml-namespace-loader" },
|
||||
{ test: /\.(html|xml)$/, use: '@nativescript/webpack/helpers/xml-namespace-loader' },
|
||||
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: "@nativescript/webpack/helpers/css2json-loader"
|
||||
use: '@nativescript/webpack/helpers/css2json-loader',
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: [
|
||||
"@nativescript/webpack/helpers/css2json-loader",
|
||||
"sass-loader"
|
||||
]
|
||||
use: ['@nativescript/webpack/helpers/css2json-loader', 'sass-loader'],
|
||||
},
|
||||
]
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
// Define useful constants like TNS_WEBPACK
|
||||
new webpack.DefinePlugin({
|
||||
"global.TNS_WEBPACK": "true",
|
||||
"global.isAndroid": platform === 'android',
|
||||
"global.isIOS": platform === 'ios',
|
||||
"process": "global.process",
|
||||
'global.TNS_WEBPACK': 'true',
|
||||
'global.isAndroid': platform === 'android',
|
||||
'global.isIOS': platform === 'ios',
|
||||
process: 'global.process',
|
||||
}),
|
||||
// Remove all files from the out dir.
|
||||
new CleanWebpackPlugin({
|
||||
cleanOnceBeforeBuildPatterns: itemsToClean,
|
||||
verbose: !!verbose
|
||||
verbose: !!verbose,
|
||||
}),
|
||||
// Copy assets
|
||||
new CopyWebpackPlugin([
|
||||
{ from: { glob: 'assets/**', dot: false } },
|
||||
{ from: { glob: 'fonts/**', dot: false } },
|
||||
{ from: { glob: '**/*.jpg', dot: false } },
|
||||
{ from: { glob: '**/*.png', dot: false } },
|
||||
], copyIgnore),
|
||||
new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),
|
||||
new CopyWebpackPlugin([{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore),
|
||||
new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'),
|
||||
|
||||
// For instructions on how to set up workers with webpack
|
||||
// check out https://github.com/nativescript/worker-loader
|
||||
@ -260,33 +254,35 @@ module.exports = env => {
|
||||
platforms,
|
||||
}),
|
||||
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
|
||||
new nsWebpack.WatchStateLoggerPlugin()
|
||||
new nsWebpack.WatchStateLoggerPlugin(),
|
||||
],
|
||||
};
|
||||
|
||||
if (report) {
|
||||
// Generate report files for bundles content
|
||||
config.plugins.push(new BundleAnalyzerPlugin({
|
||||
analyzerMode: "static",
|
||||
config.plugins.push(
|
||||
new BundleAnalyzerPlugin({
|
||||
analyzerMode: 'static',
|
||||
openAnalyzer: false,
|
||||
generateStatsFile: true,
|
||||
reportFilename: resolve(projectRoot, "report", `report.html`),
|
||||
statsFilename: resolve(projectRoot, "report", `stats.json`),
|
||||
}));
|
||||
reportFilename: resolve(projectRoot, 'report', `report.html`),
|
||||
statsFilename: resolve(projectRoot, 'report', `stats.json`),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (snapshot) {
|
||||
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
|
||||
chunk: "vendor",
|
||||
requireModules: [
|
||||
"@nativescript/core/bundle-entry-points",
|
||||
],
|
||||
config.plugins.push(
|
||||
new nsWebpack.NativeScriptSnapshotPlugin({
|
||||
chunk: 'vendor',
|
||||
requireModules: ['@nativescript/core/bundle-entry-points'],
|
||||
projectRoot,
|
||||
webpackConfig: config,
|
||||
snapshotInDocker,
|
||||
skipSnapshotTools,
|
||||
useLibs
|
||||
}));
|
||||
useLibs,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (hmr) {
|
||||
|
@ -2,8 +2,8 @@
|
||||
* @see https://github.com/NativeScript/NativeScript/tree/feat/ns7-finishing-touches/packages/webpack/templates
|
||||
* @see https://github.com/NativeScript/NativeScript/pull/8801/files
|
||||
*/
|
||||
const webpackConfig = require("./webpack.typescript");
|
||||
const webpack = require("webpack");
|
||||
const webpackConfig = require('./webpack.typescript');
|
||||
const webpack = require('webpack');
|
||||
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
||||
|
||||
module.exports = (env) => {
|
||||
@ -15,20 +15,21 @@ module.exports = (env) => {
|
||||
const baseConfig = webpackConfig(env);
|
||||
|
||||
/** Find the rule for transpiling ts files ("ts-loader"), and modify it to test for .tsx files too. */
|
||||
const tsxRule = baseConfig.module.rules.find(rule => rule.use && rule.use.loader === "ts-loader");
|
||||
const tsxRule = baseConfig.module.rules.find((rule) => rule.use && rule.use.loader === 'ts-loader');
|
||||
tsxRule.test = /\.(ts|tsx)$/;
|
||||
tsxRule.use = [
|
||||
/**
|
||||
* Add React Refresh HMR support.
|
||||
* @see https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/55028c6355b31e697e21bf3e9a48613a7b94bee7/examples/typescript-without-babel/webpack.config.js#L18-L21
|
||||
*/
|
||||
hmr && !production && {
|
||||
loader: "babel-loader",
|
||||
hmr &&
|
||||
!production && {
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
sourceMaps: isAnySourceMapEnabled ? "inline" : false,
|
||||
sourceMaps: isAnySourceMapEnabled ? 'inline' : false,
|
||||
babelrc: false,
|
||||
plugins: ['react-refresh/babel']
|
||||
}
|
||||
plugins: ['react-refresh/babel'],
|
||||
},
|
||||
},
|
||||
tsxRule.use,
|
||||
].filter(Boolean);
|
||||
@ -37,37 +38,34 @@ module.exports = (env) => {
|
||||
* Modify "nativescript-dev-webpack/hmr/hot-loader" to test for .tsx files
|
||||
* (and also js files, which it should have been doing to begin with!)
|
||||
*/
|
||||
const nativeScriptDevWebpackHotLoader = baseConfig.module.rules.find(rule =>
|
||||
rule.use === "@nativescript/webpack/hmr/hot-loader"
|
||||
);
|
||||
const nativeScriptDevWebpackHotLoader = baseConfig.module.rules.find((rule) => rule.use === '@nativescript/webpack/hmr/hot-loader');
|
||||
nativeScriptDevWebpackHotLoader.test = /\.(ts|tsx|js|css|scss|html|xml)$/;
|
||||
|
||||
/** We don't officially support JSX. Makes the webpack config rather more complicated to set up. */
|
||||
baseConfig.resolve.extensions = [".tsx", ...baseConfig.resolve.extensions];
|
||||
baseConfig.resolve.alias["react-dom"] = "react-nativescript";
|
||||
baseConfig.resolve.extensions = ['.tsx', ...baseConfig.resolve.extensions];
|
||||
baseConfig.resolve.alias['react-dom'] = 'react-nativescript';
|
||||
|
||||
/** Augment NativeScript's existing DefinePlugin definitions with a few more of our own. */
|
||||
const existingDefinePlugin = baseConfig.plugins.find(plugin =>
|
||||
plugin && plugin.constructor && plugin.constructor.name === "DefinePlugin"
|
||||
);
|
||||
const existingDefinePlugin = baseConfig.plugins.find((plugin) => plugin && plugin.constructor && plugin.constructor.name === 'DefinePlugin');
|
||||
baseConfig.plugins.splice(
|
||||
baseConfig.plugins.indexOf(existingDefinePlugin),
|
||||
1,
|
||||
new webpack.DefinePlugin({
|
||||
...existingDefinePlugin.definitions,
|
||||
/** For various libraries in the React ecosystem. */
|
||||
"__DEV__": production ? "false" : "true",
|
||||
"__TEST__": "false",
|
||||
__DEV__: production ? 'false' : 'true',
|
||||
__TEST__: 'false',
|
||||
/**
|
||||
* Primarily for React Fast Refresh plugin, but technically the allowHmrInProduction option could be used instead.
|
||||
* Worth including anyway, as there are plenty of Node libraries that use this flag.
|
||||
*/
|
||||
"process.env.NODE_ENV": JSON.stringify(production ? "production" : "development"),
|
||||
}),
|
||||
'process.env.NODE_ENV': JSON.stringify(production ? 'production' : 'development'),
|
||||
})
|
||||
);
|
||||
|
||||
if(hmr && !production){
|
||||
baseConfig.plugins.push(new ReactRefreshWebpackPlugin({
|
||||
if (hmr && !production) {
|
||||
baseConfig.plugins.push(
|
||||
new ReactRefreshWebpackPlugin({
|
||||
/**
|
||||
* Maybe one day we'll implement an Error Overlay, but the work involved is too daunting for now.
|
||||
* @see https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/79#issuecomment-644324557
|
||||
@ -79,9 +77,10 @@ module.exports = (env) => {
|
||||
* 2) Remove the `!production` condition on `tsxRule` to ensure that babel-loader gets used.
|
||||
*/
|
||||
forceEnable: false,
|
||||
}));
|
||||
})
|
||||
);
|
||||
} else {
|
||||
baseConfig.plugins = baseConfig.plugins.filter(p => !(p && p.constructor && p.constructor.name === "HotModuleReplacementPlugin"));
|
||||
baseConfig.plugins = baseConfig.plugins.filter((p) => !(p && p.constructor && p.constructor.name === 'HotModuleReplacementPlugin'));
|
||||
}
|
||||
|
||||
return baseConfig;
|
||||
|
@ -1,34 +1,31 @@
|
||||
const { join, relative, resolve, sep } = require("path");
|
||||
const { join, relative, resolve, sep } = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const webpack = require("webpack");
|
||||
const nsWebpack = require("@nativescript/webpack");
|
||||
const nativescriptTarget = require("@nativescript/webpack/nativescript-target");
|
||||
const { getNoEmitOnErrorFromTSConfig } = require("@nativescript/webpack/utils/tsconfig-utils");
|
||||
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
const webpack = require('webpack');
|
||||
const nsWebpack = require('@nativescript/webpack');
|
||||
const nativescriptTarget = require('@nativescript/webpack/nativescript-target');
|
||||
const { getNoEmitOnErrorFromTSConfig } = require('@nativescript/webpack/utils/tsconfig-utils');
|
||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
||||
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
|
||||
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||
const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
const hashSalt = Date.now().toString();
|
||||
const preprocessConfig = require("./svelte.config.js");
|
||||
const svelteNativePreprocessor = require("svelte-native-preprocessor");
|
||||
const preprocessConfig = require('./svelte.config.js');
|
||||
const svelteNativePreprocessor = require('svelte-native-preprocessor');
|
||||
|
||||
module.exports = env => {
|
||||
module.exports = (env) => {
|
||||
// Add your custom Activities, Services and other Android app components here.
|
||||
const appComponents = env.appComponents || [];
|
||||
appComponents.push(...[
|
||||
"@nativescript/core/ui/frame",
|
||||
"@nativescript/core/ui/frame/activity",
|
||||
]);
|
||||
appComponents.push(...['@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity']);
|
||||
|
||||
const platform = env && (env.android && "android" || env.ios && "ios" || env.platform);
|
||||
const platform = env && ((env.android && 'android') || (env.ios && 'ios') || env.platform);
|
||||
if (!platform) {
|
||||
throw new Error("You need to provide a target platform!");
|
||||
throw new Error('You need to provide a target platform!');
|
||||
}
|
||||
|
||||
const platforms = ["ios", "android"];
|
||||
const platforms = ['ios', 'android'];
|
||||
const projectRoot = __dirname;
|
||||
|
||||
if (env.platform) {
|
||||
@ -41,8 +38,8 @@ module.exports = env => {
|
||||
const {
|
||||
// The 'appPath' and 'appResourcesPath' values are fetched from
|
||||
// the nsconfig.json configuration file.
|
||||
appPath = "src",
|
||||
appResourcesPath = "App_Resources",
|
||||
appPath = 'src',
|
||||
appResourcesPath = 'App_Resources',
|
||||
|
||||
// You can provide the following flags when running 'tns run android|ios'
|
||||
snapshot, // --env.snapshot
|
||||
@ -55,9 +52,10 @@ module.exports = env => {
|
||||
unitTesting, // --env.unitTesting,
|
||||
testing, // --env.testing
|
||||
verbose, // --env.verbose
|
||||
ci, // --env.ci
|
||||
snapshotInDocker, // --env.snapshotInDocker
|
||||
skipSnapshotTools, // --env.skipSnapshotTools
|
||||
compileSnapshot // --env.compileSnapshot
|
||||
compileSnapshot, // --env.compileSnapshot
|
||||
} = env;
|
||||
|
||||
const useLibs = compileSnapshot;
|
||||
@ -70,14 +68,14 @@ module.exports = env => {
|
||||
appFullPath = resolve(projectRoot, 'app');
|
||||
}
|
||||
const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot });
|
||||
let coreModulesPackageName = "tns-core-modules";
|
||||
let coreModulesPackageName = 'tns-core-modules';
|
||||
const alias = env.alias || {};
|
||||
alias['~/package.json'] = resolve(projectRoot, 'package.json');
|
||||
alias['~'] = appFullPath;
|
||||
|
||||
if (hasRootLevelScopedModules) {
|
||||
coreModulesPackageName = "@nativescript/core";
|
||||
alias["tns-core-modules"] = coreModulesPackageName;
|
||||
coreModulesPackageName = '@nativescript/core';
|
||||
alias['tns-core-modules'] = coreModulesPackageName;
|
||||
}
|
||||
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
|
||||
|
||||
@ -88,34 +86,34 @@ module.exports = env => {
|
||||
const entries = env.entries || {};
|
||||
entries.bundle = entryPath;
|
||||
|
||||
const tsConfigPath = resolve(projectRoot, "tsconfig.json");
|
||||
const tsConfigPath = resolve(projectRoot, 'tsconfig.json');
|
||||
|
||||
const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some(e => e.indexOf("@nativescript") > -1);
|
||||
if (platform === "ios" && !areCoreModulesExternal && !testing) {
|
||||
entries["tns_modules/@nativescript/core/inspector_modules"] = "inspector_modules";
|
||||
};
|
||||
const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some((e) => e.indexOf('@nativescript') > -1);
|
||||
if (platform === 'ios' && !areCoreModulesExternal && !testing) {
|
||||
entries['tns_modules/@nativescript/core/inspector_modules'] = 'inspector_modules';
|
||||
}
|
||||
|
||||
let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
|
||||
|
||||
const itemsToClean = [`${dist}/**/*`];
|
||||
if (platform === "android") {
|
||||
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "src", "main", "assets", "snapshots")}`);
|
||||
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`);
|
||||
if (platform === 'android') {
|
||||
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`);
|
||||
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`);
|
||||
}
|
||||
|
||||
const noEmitOnErrorFromTSConfig = getNoEmitOnErrorFromTSConfig(tsConfigPath);
|
||||
|
||||
nsWebpack.processAppComponents(appComponents, platform);
|
||||
const config = {
|
||||
mode: production ? "production" : "development",
|
||||
mode: production ? 'production' : 'development',
|
||||
context: appFullPath,
|
||||
externals,
|
||||
watchOptions: {
|
||||
ignored: [
|
||||
appResourcesFullPath,
|
||||
// Don't watch hidden files
|
||||
"**/.*",
|
||||
]
|
||||
'**/.*',
|
||||
],
|
||||
},
|
||||
target: nativescriptTarget,
|
||||
entry: entries,
|
||||
@ -123,74 +121,78 @@ module.exports = env => {
|
||||
pathinfo: false,
|
||||
path: dist,
|
||||
sourceMapFilename,
|
||||
libraryTarget: "commonjs2",
|
||||
filename: "[name].js",
|
||||
globalObject: "global",
|
||||
hashSalt
|
||||
libraryTarget: 'commonjs2',
|
||||
filename: '[name].js',
|
||||
globalObject: 'global',
|
||||
hashSalt,
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".ts", ".mjs", ".js", ".svelte", ".scss", ".css"],
|
||||
extensions: ['.ts', '.mjs', '.js', '.svelte', '.scss', '.css'],
|
||||
// Resolve {N} system modules from @nativescript/core
|
||||
modules: [
|
||||
resolve(__dirname, `node_modules/${coreModulesPackageName}`),
|
||||
resolve(__dirname, "node_modules"),
|
||||
`node_modules/${coreModulesPackageName}`,
|
||||
"node_modules",
|
||||
],
|
||||
modules: [resolve(__dirname, `node_modules/${coreModulesPackageName}`), resolve(__dirname, 'node_modules'), `node_modules/${coreModulesPackageName}`, 'node_modules'],
|
||||
alias,
|
||||
// resolve symlinks to symlinked modules
|
||||
symlinks: true
|
||||
symlinks: true,
|
||||
},
|
||||
resolveLoader: {
|
||||
// don't resolve symlinks to symlinked loaders
|
||||
symlinks: false
|
||||
symlinks: false,
|
||||
},
|
||||
node: {
|
||||
// Disable node shims that conflict with NativeScript
|
||||
"http": false,
|
||||
"timers": false,
|
||||
"setImmediate": false,
|
||||
"fs": "empty",
|
||||
"__dirname": false,
|
||||
http: false,
|
||||
timers: false,
|
||||
setImmediate: false,
|
||||
fs: 'empty',
|
||||
__dirname: false,
|
||||
},
|
||||
devtool: hiddenSourceMap ? "hidden-source-map" : (sourceMap ? "inline-source-map" : "none"),
|
||||
devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none',
|
||||
optimization: {
|
||||
runtimeChunk: "single",
|
||||
runtimeChunk: 'single',
|
||||
noEmitOnErrors: noEmitOnErrorFromTSConfig,
|
||||
splitChunks: {
|
||||
cacheGroups: {
|
||||
vendor: {
|
||||
name: "vendor",
|
||||
chunks: "all",
|
||||
name: 'vendor',
|
||||
chunks: 'all',
|
||||
test: (module, chunks) => {
|
||||
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
|
||||
return /[\\/]node_modules[\\/]/.test(moduleName) ||
|
||||
appComponents.some(comp => comp === moduleName);
|
||||
|
||||
return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName);
|
||||
},
|
||||
enforce: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
minimize: !!uglify,
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
parallel: true,
|
||||
cache: true,
|
||||
cache: !ci,
|
||||
sourceMap: isAnySourceMapEnabled,
|
||||
terserOptions: {
|
||||
output: {
|
||||
comments: false,
|
||||
semicolons: !isAnySourceMapEnabled
|
||||
semicolons: !isAnySourceMapEnabled,
|
||||
},
|
||||
compress: {
|
||||
// The Android SBG has problems parsing the output
|
||||
// when these options are enabled
|
||||
'collapse_vars': platform !== "android",
|
||||
sequences: platform !== "android",
|
||||
}
|
||||
}
|
||||
})
|
||||
collapse_vars: platform !== 'android',
|
||||
sequences: platform !== 'android',
|
||||
// For v8 Compatibility
|
||||
keep_infinity: true, // for V8
|
||||
reduce_funcs: false, // for V8
|
||||
// custom
|
||||
drop_console: production,
|
||||
drop_debugger: true,
|
||||
global_defs: {
|
||||
__UGLIFIED__: true,
|
||||
},
|
||||
},
|
||||
// Required for Element Level CSS, Observable Events, & Android Frame
|
||||
keep_classnames: true,
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
module: {
|
||||
@ -199,42 +201,39 @@ module.exports = env => {
|
||||
include: join(appFullPath, entryPath),
|
||||
use: [
|
||||
// Require all Android app components
|
||||
platform === "android" && {
|
||||
loader: "@nativescript/webpack/helpers/android-app-components-loader",
|
||||
options: { modules: appComponents }
|
||||
platform === 'android' && {
|
||||
loader: '@nativescript/webpack/helpers/android-app-components-loader',
|
||||
options: { modules: appComponents },
|
||||
},
|
||||
|
||||
{
|
||||
loader: "@nativescript/webpack/bundle-config-loader",
|
||||
loader: '@nativescript/webpack/bundle-config-loader',
|
||||
options: {
|
||||
loadCss: !snapshot, // load the application css if in debug mode
|
||||
unitTesting,
|
||||
appFullPath,
|
||||
projectRoot,
|
||||
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform)
|
||||
}
|
||||
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform),
|
||||
},
|
||||
].filter(loader => !!loader)
|
||||
},
|
||||
].filter((loader) => !!loader),
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.(ts|css|scss|html|xml)$/,
|
||||
use: "@nativescript/webpack/hmr/hot-loader"
|
||||
use: '@nativescript/webpack/hmr/hot-loader',
|
||||
},
|
||||
|
||||
{ test: /\.(html|xml)$/, use: "@nativescript/webpack/helpers/xml-namespace-loader" },
|
||||
{ test: /\.(html|xml)$/, use: '@nativescript/webpack/helpers/xml-namespace-loader' },
|
||||
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: "@nativescript/webpack/helpers/css2json-loader"
|
||||
use: '@nativescript/webpack/helpers/css2json-loader',
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: [
|
||||
"@nativescript/webpack/helpers/css2json-loader",
|
||||
"sass-loader"
|
||||
]
|
||||
use: ['@nativescript/webpack/helpers/css2json-loader', 'sass-loader'],
|
||||
},
|
||||
|
||||
{
|
||||
@ -244,7 +243,7 @@ module.exports = env => {
|
||||
{
|
||||
test: /\.ts$/,
|
||||
use: {
|
||||
loader: "ts-loader",
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
configFile: tsConfigPath,
|
||||
// https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds
|
||||
@ -253,15 +252,13 @@ module.exports = env => {
|
||||
allowTsInNodeModules: true,
|
||||
compilerOptions: {
|
||||
sourceMap: isAnySourceMapEnabled,
|
||||
declaration: false
|
||||
declaration: false,
|
||||
},
|
||||
getCustomTransformers: (program) => ({
|
||||
before: [
|
||||
require("@nativescript/webpack/transformers/ns-transform-native-classes").default
|
||||
]
|
||||
})
|
||||
before: [require('@nativescript/webpack/transformers/ns-transform-native-classes').default],
|
||||
}),
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.svelte$/,
|
||||
@ -275,35 +272,30 @@ module.exports = env => {
|
||||
hotReload: env.production ? false : true,
|
||||
hotOptions: {
|
||||
injectCss: false,
|
||||
native: true
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
native: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
// Define useful constants like TNS_WEBPACK
|
||||
new webpack.DefinePlugin({
|
||||
"global.TNS_WEBPACK": "true",
|
||||
"global.isAndroid": platform === 'android',
|
||||
"global.isIOS": platform === 'ios',
|
||||
"process": "global.process",
|
||||
'global.TNS_WEBPACK': 'true',
|
||||
'global.isAndroid': platform === 'android',
|
||||
'global.isIOS': platform === 'ios',
|
||||
process: 'global.process',
|
||||
}),
|
||||
// Remove all files from the out dir.
|
||||
new CleanWebpackPlugin({
|
||||
cleanOnceBeforeBuildPatterns: itemsToClean,
|
||||
verbose: !!verbose
|
||||
verbose: !!verbose,
|
||||
}),
|
||||
// Copy assets
|
||||
new CopyWebpackPlugin([
|
||||
{ from: { glob: 'assets/**', dot: false } },
|
||||
{ from: { glob: 'fonts/**', dot: false } },
|
||||
{ from: { glob: '**/*.jpg', dot: false } },
|
||||
{ from: { glob: '**/*.png', dot: false } },
|
||||
], copyIgnore),
|
||||
new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),
|
||||
new CopyWebpackPlugin([{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore),
|
||||
new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'),
|
||||
// For instructions on how to set up workers with webpack
|
||||
// check out https://github.com/nativescript/worker-loader
|
||||
new NativeScriptWorkerPlugin(),
|
||||
@ -322,36 +314,38 @@ module.exports = env => {
|
||||
memoryLimit: 4096,
|
||||
diagnosticOptions: {
|
||||
syntactic: true,
|
||||
semantic: true
|
||||
}
|
||||
}
|
||||
})
|
||||
semantic: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
if (report) {
|
||||
// Generate report files for bundles content
|
||||
config.plugins.push(new BundleAnalyzerPlugin({
|
||||
analyzerMode: "static",
|
||||
config.plugins.push(
|
||||
new BundleAnalyzerPlugin({
|
||||
analyzerMode: 'static',
|
||||
openAnalyzer: false,
|
||||
generateStatsFile: true,
|
||||
reportFilename: resolve(projectRoot, "report", `report.html`),
|
||||
statsFilename: resolve(projectRoot, "report", `stats.json`),
|
||||
}));
|
||||
reportFilename: resolve(projectRoot, 'report', `report.html`),
|
||||
statsFilename: resolve(projectRoot, 'report', `stats.json`),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (snapshot) {
|
||||
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
|
||||
chunk: "vendor",
|
||||
requireModules: [
|
||||
"@nativescript/core/bundle-entry-points",
|
||||
],
|
||||
config.plugins.push(
|
||||
new nsWebpack.NativeScriptSnapshotPlugin({
|
||||
chunk: 'vendor',
|
||||
requireModules: ['@nativescript/core/bundle-entry-points'],
|
||||
projectRoot,
|
||||
webpackConfig: config,
|
||||
snapshotInDocker,
|
||||
skipSnapshotTools,
|
||||
useLibs
|
||||
}));
|
||||
useLibs,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (hmr) {
|
||||
|
@ -1,32 +1,29 @@
|
||||
const { join, relative, resolve, sep } = require("path");
|
||||
const { join, relative, resolve, sep } = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const webpack = require("webpack");
|
||||
const nsWebpack = require("@nativescript/webpack");
|
||||
const nativescriptTarget = require("@nativescript/webpack/nativescript-target");
|
||||
const { getNoEmitOnErrorFromTSConfig } = require("@nativescript/webpack/utils/tsconfig-utils");
|
||||
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
const webpack = require('webpack');
|
||||
const nsWebpack = require('@nativescript/webpack');
|
||||
const nativescriptTarget = require('@nativescript/webpack/nativescript-target');
|
||||
const { getNoEmitOnErrorFromTSConfig } = require('@nativescript/webpack/utils/tsconfig-utils');
|
||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
||||
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
|
||||
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||
const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
const hashSalt = Date.now().toString();
|
||||
|
||||
module.exports = env => {
|
||||
module.exports = (env) => {
|
||||
// Add your custom Activities, Services and other Android app components here.
|
||||
const appComponents = env.appComponents || [];
|
||||
appComponents.push(...[
|
||||
"@nativescript/core/ui/frame",
|
||||
"@nativescript/core/ui/frame/activity",
|
||||
]);
|
||||
appComponents.push(...['@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity']);
|
||||
|
||||
const platform = env && (env.android && "android" || env.ios && "ios" || env.platform);
|
||||
const platform = env && ((env.android && 'android') || (env.ios && 'ios') || env.platform);
|
||||
if (!platform) {
|
||||
throw new Error("You need to provide a target platform!");
|
||||
throw new Error('You need to provide a target platform!');
|
||||
}
|
||||
|
||||
const platforms = ["ios", "android"];
|
||||
const platforms = ['ios', 'android'];
|
||||
const projectRoot = __dirname;
|
||||
|
||||
if (env.platform) {
|
||||
@ -39,8 +36,8 @@ module.exports = env => {
|
||||
const {
|
||||
// The 'appPath' and 'appResourcesPath' values are fetched from
|
||||
// the nsconfig.json configuration file.
|
||||
appPath = "src",
|
||||
appResourcesPath = "App_Resources",
|
||||
appPath = 'src',
|
||||
appResourcesPath = 'App_Resources',
|
||||
|
||||
// You can provide the following flags when running 'tns run android|ios'
|
||||
snapshot, // --env.snapshot
|
||||
@ -53,9 +50,10 @@ module.exports = env => {
|
||||
unitTesting, // --env.unitTesting,
|
||||
testing, // --env.testing
|
||||
verbose, // --env.verbose
|
||||
ci, // --env.ci
|
||||
snapshotInDocker, // --env.snapshotInDocker
|
||||
skipSnapshotTools, // --env.skipSnapshotTools
|
||||
compileSnapshot // --env.compileSnapshot
|
||||
compileSnapshot, // --env.compileSnapshot
|
||||
} = env;
|
||||
|
||||
const useLibs = compileSnapshot;
|
||||
@ -68,14 +66,14 @@ module.exports = env => {
|
||||
appFullPath = resolve(projectRoot, 'app');
|
||||
}
|
||||
const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot });
|
||||
let coreModulesPackageName = "tns-core-modules";
|
||||
let coreModulesPackageName = 'tns-core-modules';
|
||||
const alias = env.alias || {};
|
||||
alias['~/package.json'] = resolve(projectRoot, 'package.json');
|
||||
alias['~'] = appFullPath;
|
||||
|
||||
if (hasRootLevelScopedModules) {
|
||||
coreModulesPackageName = "@nativescript/core";
|
||||
alias["tns-core-modules"] = coreModulesPackageName;
|
||||
coreModulesPackageName = '@nativescript/core';
|
||||
alias['tns-core-modules'] = coreModulesPackageName;
|
||||
}
|
||||
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
|
||||
|
||||
@ -86,34 +84,34 @@ module.exports = env => {
|
||||
const entries = env.entries || {};
|
||||
entries.bundle = entryPath;
|
||||
|
||||
const tsConfigPath = resolve(projectRoot, "tsconfig.json");
|
||||
const tsConfigPath = resolve(projectRoot, 'tsconfig.json');
|
||||
|
||||
const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some(e => e.indexOf("@nativescript") > -1);
|
||||
if (platform === "ios" && !areCoreModulesExternal && !testing) {
|
||||
entries["tns_modules/@nativescript/core/inspector_modules"] = "inspector_modules";
|
||||
};
|
||||
const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some((e) => e.indexOf('@nativescript') > -1);
|
||||
if (platform === 'ios' && !areCoreModulesExternal && !testing) {
|
||||
entries['tns_modules/@nativescript/core/inspector_modules'] = 'inspector_modules';
|
||||
}
|
||||
|
||||
let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
|
||||
|
||||
const itemsToClean = [`${dist}/**/*`];
|
||||
if (platform === "android") {
|
||||
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "src", "main", "assets", "snapshots")}`);
|
||||
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`);
|
||||
if (platform === 'android') {
|
||||
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`);
|
||||
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`);
|
||||
}
|
||||
|
||||
const noEmitOnErrorFromTSConfig = getNoEmitOnErrorFromTSConfig(tsConfigPath);
|
||||
|
||||
nsWebpack.processAppComponents(appComponents, platform);
|
||||
const config = {
|
||||
mode: production ? "production" : "development",
|
||||
mode: production ? 'production' : 'development',
|
||||
context: appFullPath,
|
||||
externals,
|
||||
watchOptions: {
|
||||
ignored: [
|
||||
appResourcesFullPath,
|
||||
// Don't watch hidden files
|
||||
"**/.*",
|
||||
]
|
||||
'**/.*',
|
||||
],
|
||||
},
|
||||
target: nativescriptTarget,
|
||||
entry: entries,
|
||||
@ -121,74 +119,78 @@ module.exports = env => {
|
||||
pathinfo: false,
|
||||
path: dist,
|
||||
sourceMapFilename,
|
||||
libraryTarget: "commonjs2",
|
||||
filename: "[name].js",
|
||||
globalObject: "global",
|
||||
hashSalt
|
||||
libraryTarget: 'commonjs2',
|
||||
filename: '[name].js',
|
||||
globalObject: 'global',
|
||||
hashSalt,
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".ts", ".js", ".scss", ".css"],
|
||||
extensions: ['.ts', '.js', '.scss', '.css'],
|
||||
// Resolve {N} system modules from @nativescript/core
|
||||
modules: [
|
||||
resolve(__dirname, `node_modules/${coreModulesPackageName}`),
|
||||
resolve(__dirname, "node_modules"),
|
||||
`node_modules/${coreModulesPackageName}`,
|
||||
"node_modules",
|
||||
],
|
||||
modules: [resolve(__dirname, `node_modules/${coreModulesPackageName}`), resolve(__dirname, 'node_modules'), `node_modules/${coreModulesPackageName}`, 'node_modules'],
|
||||
alias,
|
||||
// resolve symlinks to symlinked modules
|
||||
symlinks: true
|
||||
symlinks: true,
|
||||
},
|
||||
resolveLoader: {
|
||||
// don't resolve symlinks to symlinked loaders
|
||||
symlinks: false
|
||||
symlinks: false,
|
||||
},
|
||||
node: {
|
||||
// Disable node shims that conflict with NativeScript
|
||||
"http": false,
|
||||
"timers": false,
|
||||
"setImmediate": false,
|
||||
"fs": "empty",
|
||||
"__dirname": false,
|
||||
http: false,
|
||||
timers: false,
|
||||
setImmediate: false,
|
||||
fs: 'empty',
|
||||
__dirname: false,
|
||||
},
|
||||
devtool: hiddenSourceMap ? "hidden-source-map" : (sourceMap ? "inline-source-map" : "none"),
|
||||
devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none',
|
||||
optimization: {
|
||||
runtimeChunk: "single",
|
||||
runtimeChunk: 'single',
|
||||
noEmitOnErrors: noEmitOnErrorFromTSConfig,
|
||||
splitChunks: {
|
||||
cacheGroups: {
|
||||
vendor: {
|
||||
name: "vendor",
|
||||
chunks: "all",
|
||||
name: 'vendor',
|
||||
chunks: 'all',
|
||||
test: (module, chunks) => {
|
||||
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
|
||||
return /[\\/]node_modules[\\/]/.test(moduleName) ||
|
||||
appComponents.some(comp => comp === moduleName);
|
||||
|
||||
return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName);
|
||||
},
|
||||
enforce: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
minimize: !!uglify,
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
parallel: true,
|
||||
cache: true,
|
||||
cache: !ci,
|
||||
sourceMap: isAnySourceMapEnabled,
|
||||
terserOptions: {
|
||||
output: {
|
||||
comments: false,
|
||||
semicolons: !isAnySourceMapEnabled
|
||||
semicolons: !isAnySourceMapEnabled,
|
||||
},
|
||||
compress: {
|
||||
// The Android SBG has problems parsing the output
|
||||
// when these options are enabled
|
||||
'collapse_vars': platform !== "android",
|
||||
sequences: platform !== "android",
|
||||
}
|
||||
}
|
||||
})
|
||||
collapse_vars: platform !== 'android',
|
||||
sequences: platform !== 'android',
|
||||
// For v8 Compatibility
|
||||
keep_infinity: true, // for V8
|
||||
reduce_funcs: false, // for V8
|
||||
// custom
|
||||
drop_console: production,
|
||||
drop_debugger: true,
|
||||
global_defs: {
|
||||
__UGLIFIED__: true,
|
||||
},
|
||||
},
|
||||
// Required for Element Level CSS, Observable Events, & Android Frame
|
||||
keep_classnames: true,
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
module: {
|
||||
@ -197,48 +199,45 @@ module.exports = env => {
|
||||
include: join(appFullPath, entryPath),
|
||||
use: [
|
||||
// Require all Android app components
|
||||
platform === "android" && {
|
||||
loader: "@nativescript/webpack/helpers/android-app-components-loader",
|
||||
options: { modules: appComponents }
|
||||
platform === 'android' && {
|
||||
loader: '@nativescript/webpack/helpers/android-app-components-loader',
|
||||
options: { modules: appComponents },
|
||||
},
|
||||
|
||||
{
|
||||
loader: "@nativescript/webpack/bundle-config-loader",
|
||||
loader: '@nativescript/webpack/bundle-config-loader',
|
||||
options: {
|
||||
loadCss: !snapshot, // load the application css if in debug mode
|
||||
unitTesting,
|
||||
appFullPath,
|
||||
projectRoot,
|
||||
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform)
|
||||
}
|
||||
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform),
|
||||
},
|
||||
].filter(loader => !!loader)
|
||||
},
|
||||
].filter((loader) => !!loader),
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.(ts|css|scss|html|xml)$/,
|
||||
use: "@nativescript/webpack/hmr/hot-loader"
|
||||
use: '@nativescript/webpack/hmr/hot-loader',
|
||||
},
|
||||
|
||||
{ test: /\.(html|xml)$/, use: "@nativescript/webpack/helpers/xml-namespace-loader" },
|
||||
{ test: /\.(html|xml)$/, use: '@nativescript/webpack/helpers/xml-namespace-loader' },
|
||||
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: "@nativescript/webpack/helpers/css2json-loader"
|
||||
use: '@nativescript/webpack/helpers/css2json-loader',
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: [
|
||||
"@nativescript/webpack/helpers/css2json-loader",
|
||||
"sass-loader"
|
||||
]
|
||||
use: ['@nativescript/webpack/helpers/css2json-loader', 'sass-loader'],
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.ts$/,
|
||||
use: {
|
||||
loader: "ts-loader",
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
configFile: tsConfigPath,
|
||||
// https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds
|
||||
@ -247,39 +246,32 @@ module.exports = env => {
|
||||
allowTsInNodeModules: true,
|
||||
compilerOptions: {
|
||||
sourceMap: isAnySourceMapEnabled,
|
||||
declaration: false
|
||||
declaration: false,
|
||||
},
|
||||
getCustomTransformers: (program) => ({
|
||||
before: [
|
||||
require("@nativescript/webpack/transformers/ns-transform-native-classes").default
|
||||
]
|
||||
})
|
||||
before: [require('@nativescript/webpack/transformers/ns-transform-native-classes').default],
|
||||
}),
|
||||
},
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
// Define useful constants like TNS_WEBPACK
|
||||
new webpack.DefinePlugin({
|
||||
"global.TNS_WEBPACK": "true",
|
||||
"global.isAndroid": platform === 'android',
|
||||
"global.isIOS": platform === 'ios',
|
||||
"process": "global.process",
|
||||
'global.TNS_WEBPACK': 'true',
|
||||
'global.isAndroid': platform === 'android',
|
||||
'global.isIOS': platform === 'ios',
|
||||
process: 'global.process',
|
||||
}),
|
||||
// Remove all files from the out dir.
|
||||
new CleanWebpackPlugin({
|
||||
cleanOnceBeforeBuildPatterns: itemsToClean,
|
||||
verbose: !!verbose
|
||||
verbose: !!verbose,
|
||||
}),
|
||||
// Copy assets
|
||||
new CopyWebpackPlugin([
|
||||
{ from: { glob: 'assets/**', dot: false } },
|
||||
{ from: { glob: 'fonts/**', dot: false } },
|
||||
{ from: { glob: '**/*.jpg', dot: false } },
|
||||
{ from: { glob: '**/*.png', dot: false } },
|
||||
], copyIgnore),
|
||||
new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),
|
||||
new CopyWebpackPlugin([{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore),
|
||||
new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'),
|
||||
// For instructions on how to set up workers with webpack
|
||||
// check out https://github.com/nativescript/worker-loader
|
||||
new NativeScriptWorkerPlugin(),
|
||||
@ -298,36 +290,38 @@ module.exports = env => {
|
||||
memoryLimit: 4096,
|
||||
diagnosticOptions: {
|
||||
syntactic: true,
|
||||
semantic: true
|
||||
}
|
||||
}
|
||||
})
|
||||
semantic: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
if (report) {
|
||||
// Generate report files for bundles content
|
||||
config.plugins.push(new BundleAnalyzerPlugin({
|
||||
analyzerMode: "static",
|
||||
config.plugins.push(
|
||||
new BundleAnalyzerPlugin({
|
||||
analyzerMode: 'static',
|
||||
openAnalyzer: false,
|
||||
generateStatsFile: true,
|
||||
reportFilename: resolve(projectRoot, "report", `report.html`),
|
||||
statsFilename: resolve(projectRoot, "report", `stats.json`),
|
||||
}));
|
||||
reportFilename: resolve(projectRoot, 'report', `report.html`),
|
||||
statsFilename: resolve(projectRoot, 'report', `stats.json`),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (snapshot) {
|
||||
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
|
||||
chunk: "vendor",
|
||||
requireModules: [
|
||||
"@nativescript/core/bundle-entry-points",
|
||||
],
|
||||
config.plugins.push(
|
||||
new nsWebpack.NativeScriptSnapshotPlugin({
|
||||
chunk: 'vendor',
|
||||
requireModules: ['@nativescript/core/bundle-entry-points'],
|
||||
projectRoot,
|
||||
webpackConfig: config,
|
||||
snapshotInDocker,
|
||||
skipSnapshotTools,
|
||||
useLibs
|
||||
}));
|
||||
useLibs,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (hmr) {
|
||||
|
@ -1,33 +1,30 @@
|
||||
const { join, relative, resolve, sep } = require("path");
|
||||
const { join, relative, resolve, sep } = require('path');
|
||||
|
||||
const webpack = require("webpack");
|
||||
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const webpack = require('webpack');
|
||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
|
||||
const VueLoaderPlugin = require('vue-loader/lib/plugin');
|
||||
const NsVueTemplateCompiler = require("nativescript-vue-template-compiler");
|
||||
const NsVueTemplateCompiler = require('nativescript-vue-template-compiler');
|
||||
|
||||
const nsWebpack = require("@nativescript/webpack");
|
||||
const nativescriptTarget = require("@nativescript/webpack/nativescript-target");
|
||||
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
|
||||
const nsWebpack = require('@nativescript/webpack');
|
||||
const nativescriptTarget = require('@nativescript/webpack/nativescript-target');
|
||||
const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin');
|
||||
const hashSalt = Date.now().toString();
|
||||
|
||||
module.exports = env => {
|
||||
module.exports = (env) => {
|
||||
// Add your custom Activities, Services and other android app components here.
|
||||
const appComponents = env.appComponents || [];
|
||||
appComponents.push(...[
|
||||
"@nativescript/core/ui/frame",
|
||||
"@nativescript/core/ui/frame/activity",
|
||||
]);
|
||||
appComponents.push(...['@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity']);
|
||||
|
||||
const platform = env && (env.android && "android" || env.ios && "ios" || env.platform);
|
||||
const platform = env && ((env.android && 'android') || (env.ios && 'ios') || env.platform);
|
||||
if (!platform) {
|
||||
throw new Error("You need to provide a target platform!");
|
||||
throw new Error('You need to provide a target platform!');
|
||||
}
|
||||
|
||||
const platforms = ["ios", "android"];
|
||||
const platforms = ['ios', 'android'];
|
||||
const projectRoot = __dirname;
|
||||
|
||||
if (env.platform) {
|
||||
@ -40,8 +37,8 @@ module.exports = env => {
|
||||
const {
|
||||
// The 'appPath' and 'appResourcesPath' values are fetched from
|
||||
// the nsconfig.json configuration file.
|
||||
appPath = "app",
|
||||
appResourcesPath = "app/App_Resources",
|
||||
appPath = 'app',
|
||||
appResourcesPath = 'app/App_Resources',
|
||||
|
||||
// You can provide the following flags when running 'tns run android|ios'
|
||||
snapshot, // --env.snapshot
|
||||
@ -53,20 +50,21 @@ module.exports = env => {
|
||||
unitTesting, // --env.unitTesting
|
||||
testing, // --env.testing
|
||||
verbose, // --env.verbose
|
||||
ci, // --env.ci
|
||||
snapshotInDocker, // --env.snapshotInDocker
|
||||
skipSnapshotTools, // --env.skipSnapshotTools
|
||||
compileSnapshot // --env.compileSnapshot
|
||||
compileSnapshot, // --env.compileSnapshot
|
||||
} = env;
|
||||
|
||||
const useLibs = compileSnapshot;
|
||||
const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap;
|
||||
const externals = nsWebpack.getConvertedExternals(env.externals);
|
||||
|
||||
const mode = production ? "production" : "development"
|
||||
const mode = production ? 'production' : 'development';
|
||||
|
||||
const appFullPath = resolve(projectRoot, appPath);
|
||||
const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot });
|
||||
let coreModulesPackageName = "tns-core-modules";
|
||||
let coreModulesPackageName = 'tns-core-modules';
|
||||
const alias = env.alias || {};
|
||||
alias['~/package.json'] = resolve(projectRoot, 'package.json');
|
||||
alias['~'] = appFullPath;
|
||||
@ -74,8 +72,8 @@ module.exports = env => {
|
||||
alias['vue'] = 'nativescript-vue';
|
||||
|
||||
if (hasRootLevelScopedModules) {
|
||||
coreModulesPackageName = "@nativescript/core";
|
||||
alias["tns-core-modules"] = coreModulesPackageName;
|
||||
coreModulesPackageName = '@nativescript/core';
|
||||
alias['tns-core-modules'] = coreModulesPackageName;
|
||||
}
|
||||
|
||||
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
|
||||
@ -87,18 +85,18 @@ module.exports = env => {
|
||||
const entries = env.entries || {};
|
||||
entries.bundle = entryPath;
|
||||
|
||||
const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some(e => e.indexOf("@nativescript") > -1);
|
||||
if (platform === "ios" && !areCoreModulesExternal && !testing) {
|
||||
entries["tns_modules/@nativescript/core/inspector_modules"] = "inspector_modules";
|
||||
};
|
||||
const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some((e) => e.indexOf('@nativescript') > -1);
|
||||
if (platform === 'ios' && !areCoreModulesExternal && !testing) {
|
||||
entries['tns_modules/@nativescript/core/inspector_modules'] = 'inspector_modules';
|
||||
}
|
||||
console.log(`Bundling application for entryPath ${entryPath}...`);
|
||||
|
||||
let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
|
||||
|
||||
const itemsToClean = [`${dist}/**/*`];
|
||||
if (platform === "android") {
|
||||
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "src", "main", "assets", "snapshots")}`);
|
||||
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`);
|
||||
if (platform === 'android') {
|
||||
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`);
|
||||
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`);
|
||||
}
|
||||
|
||||
nsWebpack.processAppComponents(appComponents, platform);
|
||||
@ -110,7 +108,7 @@ module.exports = env => {
|
||||
ignored: [
|
||||
appResourcesFullPath,
|
||||
// Don't watch hidden files
|
||||
"**/.*",
|
||||
'**/.*',
|
||||
],
|
||||
},
|
||||
target: nativescriptTarget,
|
||||
@ -120,20 +118,15 @@ module.exports = env => {
|
||||
pathinfo: false,
|
||||
path: dist,
|
||||
sourceMapFilename,
|
||||
libraryTarget: "commonjs2",
|
||||
filename: "[name].js",
|
||||
globalObject: "global",
|
||||
hashSalt
|
||||
libraryTarget: 'commonjs2',
|
||||
filename: '[name].js',
|
||||
globalObject: 'global',
|
||||
hashSalt,
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".vue", ".ts", ".js", ".scss", ".css"],
|
||||
extensions: ['.vue', '.ts', '.js', '.scss', '.css'],
|
||||
// Resolve {N} system modules from @nativescript/core
|
||||
modules: [
|
||||
resolve(__dirname, `node_modules/${coreModulesPackageName}`),
|
||||
resolve(__dirname, "node_modules"),
|
||||
`node_modules/${coreModulesPackageName}`,
|
||||
"node_modules",
|
||||
],
|
||||
modules: [resolve(__dirname, `node_modules/${coreModulesPackageName}`), resolve(__dirname, 'node_modules'), `node_modules/${coreModulesPackageName}`, 'node_modules'],
|
||||
alias,
|
||||
// resolve symlinks to symlinked modules
|
||||
symlinks: true,
|
||||
@ -144,26 +137,24 @@ module.exports = env => {
|
||||
},
|
||||
node: {
|
||||
// Disable node shims that conflict with NativeScript
|
||||
"http": false,
|
||||
"timers": false,
|
||||
"setImmediate": false,
|
||||
"fs": "empty",
|
||||
"__dirname": false,
|
||||
http: false,
|
||||
timers: false,
|
||||
setImmediate: false,
|
||||
fs: 'empty',
|
||||
__dirname: false,
|
||||
},
|
||||
devtool: hiddenSourceMap ? "hidden-source-map" : (sourceMap ? "inline-source-map" : "none"),
|
||||
devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none',
|
||||
optimization: {
|
||||
runtimeChunk: "single",
|
||||
runtimeChunk: 'single',
|
||||
noEmitOnErrors: true,
|
||||
splitChunks: {
|
||||
cacheGroups: {
|
||||
vendor: {
|
||||
name: "vendor",
|
||||
chunks: "all",
|
||||
name: 'vendor',
|
||||
chunks: 'all',
|
||||
test: (module) => {
|
||||
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
|
||||
return /[\\/]node_modules[\\/]/.test(moduleName) ||
|
||||
appComponents.some(comp => comp === moduleName);
|
||||
|
||||
return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName);
|
||||
},
|
||||
enforce: true,
|
||||
},
|
||||
@ -173,54 +164,66 @@ module.exports = env => {
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
parallel: true,
|
||||
cache: true,
|
||||
cache: !ci,
|
||||
sourceMap: isAnySourceMapEnabled,
|
||||
terserOptions: {
|
||||
output: {
|
||||
comments: false,
|
||||
semicolons: !isAnySourceMapEnabled
|
||||
semicolons: !isAnySourceMapEnabled,
|
||||
},
|
||||
compress: {
|
||||
// The Android SBG has problems parsing the output
|
||||
// when these options are enabled
|
||||
'collapse_vars': platform !== "android",
|
||||
sequences: platform !== "android",
|
||||
collapse_vars: platform !== 'android',
|
||||
sequences: platform !== 'android',
|
||||
// For v8 Compatibility
|
||||
keep_infinity: true, // for V8
|
||||
reduce_funcs: false, // for V8
|
||||
// custom
|
||||
drop_console: production,
|
||||
drop_debugger: true,
|
||||
global_defs: {
|
||||
__UGLIFIED__: true,
|
||||
},
|
||||
},
|
||||
keep_fnames: true,
|
||||
// Required for Element Level CSS, Observable Events, & Android Frame
|
||||
keep_classnames: true,
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
module: {
|
||||
rules: [{
|
||||
include: [join(appFullPath, entryPath + ".js"), join(appFullPath, entryPath + ".ts")],
|
||||
rules: [
|
||||
{
|
||||
include: [join(appFullPath, entryPath + '.js'), join(appFullPath, entryPath + '.ts')],
|
||||
use: [
|
||||
// Require all Android app components
|
||||
platform === "android" && {
|
||||
loader: "@nativescript/webpack/helpers/android-app-components-loader",
|
||||
platform === 'android' && {
|
||||
loader: '@nativescript/webpack/helpers/android-app-components-loader',
|
||||
options: { modules: appComponents },
|
||||
},
|
||||
|
||||
{
|
||||
loader: "@nativescript/webpack/bundle-config-loader",
|
||||
loader: '@nativescript/webpack/bundle-config-loader',
|
||||
options: {
|
||||
registerPages: true, // applicable only for non-angular apps
|
||||
loadCss: !snapshot, // load the application css if in debug mode
|
||||
unitTesting,
|
||||
appFullPath,
|
||||
projectRoot,
|
||||
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform)
|
||||
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform),
|
||||
},
|
||||
},
|
||||
].filter(loader => Boolean(loader)),
|
||||
].filter((loader) => Boolean(loader)),
|
||||
},
|
||||
{
|
||||
test: /[\/|\\]app\.css$/,
|
||||
use: [
|
||||
'@nativescript/webpack/helpers/style-hot-loader',
|
||||
{
|
||||
loader: "@nativescript/webpack/helpers/css2json-loader",
|
||||
options: { useForImports: true }
|
||||
loader: '@nativescript/webpack/helpers/css2json-loader',
|
||||
options: { useForImports: true },
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -229,8 +232,8 @@ module.exports = env => {
|
||||
use: [
|
||||
'@nativescript/webpack/helpers/style-hot-loader',
|
||||
{
|
||||
loader: "@nativescript/webpack/helpers/css2json-loader",
|
||||
options: { useForImports: true }
|
||||
loader: '@nativescript/webpack/helpers/css2json-loader',
|
||||
options: { useForImports: true },
|
||||
},
|
||||
'sass-loader',
|
||||
],
|
||||
@ -238,21 +241,12 @@ module.exports = env => {
|
||||
{
|
||||
test: /\.css$/,
|
||||
exclude: /[\/|\\]app\.css$/,
|
||||
use: [
|
||||
'@nativescript/webpack/helpers/style-hot-loader',
|
||||
'@nativescript/webpack/helpers/apply-css-loader.js',
|
||||
{ loader: "css-loader", options: { url: false } },
|
||||
],
|
||||
use: ['@nativescript/webpack/helpers/style-hot-loader', '@nativescript/webpack/helpers/apply-css-loader.js', { loader: 'css-loader', options: { url: false } }],
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
exclude: /[\/|\\]app\.scss$/,
|
||||
use: [
|
||||
'@nativescript/webpack/helpers/style-hot-loader',
|
||||
'@nativescript/webpack/helpers/apply-css-loader.js',
|
||||
{ loader: "css-loader", options: { url: false } },
|
||||
'sass-loader',
|
||||
],
|
||||
use: ['@nativescript/webpack/helpers/style-hot-loader', '@nativescript/webpack/helpers/apply-css-loader.js', { loader: 'css-loader', options: { url: false } }, 'sass-loader'],
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
@ -265,18 +259,16 @@ module.exports = env => {
|
||||
appendTsSuffixTo: [/\.vue$/],
|
||||
allowTsInNodeModules: true,
|
||||
compilerOptions: {
|
||||
declaration: false
|
||||
declaration: false,
|
||||
},
|
||||
getCustomTransformers: (program) => ({
|
||||
before: [
|
||||
require("@nativescript/webpack/transformers/ns-transform-native-classes").default
|
||||
]
|
||||
})
|
||||
before: [require('@nativescript/webpack/transformers/ns-transform-native-classes').default],
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.vue$/,
|
||||
loader: "vue-loader",
|
||||
loader: 'vue-loader',
|
||||
options: {
|
||||
compiler: NsVueTemplateCompiler,
|
||||
},
|
||||
@ -289,25 +281,20 @@ module.exports = env => {
|
||||
new VueLoaderPlugin(),
|
||||
// Define useful constants like TNS_WEBPACK
|
||||
new webpack.DefinePlugin({
|
||||
"global.TNS_WEBPACK": "true",
|
||||
"global.isAndroid": platform === 'android',
|
||||
"global.isIOS": platform === 'ios',
|
||||
"TNS_ENV": JSON.stringify(mode),
|
||||
"process": "global.process"
|
||||
'global.TNS_WEBPACK': 'true',
|
||||
'global.isAndroid': platform === 'android',
|
||||
'global.isIOS': platform === 'ios',
|
||||
TNS_ENV: JSON.stringify(mode),
|
||||
process: 'global.process',
|
||||
}),
|
||||
// Remove all files from the out dir.
|
||||
new CleanWebpackPlugin({
|
||||
cleanOnceBeforeBuildPatterns: itemsToClean,
|
||||
verbose: !!verbose
|
||||
verbose: !!verbose,
|
||||
}),
|
||||
// Copy assets
|
||||
new CopyWebpackPlugin([
|
||||
{ from: { glob: 'assets/**', dot: false } },
|
||||
{ from: { glob: 'fonts/**', dot: false } },
|
||||
{ from: { glob: '**/*.jpg', dot: false } },
|
||||
{ from: { glob: '**/*.png', dot: false } },
|
||||
], copyIgnore),
|
||||
new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),
|
||||
new CopyWebpackPlugin([{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore),
|
||||
new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'),
|
||||
// For instructions on how to set up workers with webpack
|
||||
// check out https://github.com/nativescript/worker-loader
|
||||
new NativeScriptWorkerPlugin(),
|
||||
@ -316,7 +303,7 @@ module.exports = env => {
|
||||
platforms,
|
||||
}),
|
||||
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
|
||||
new nsWebpack.WatchStateLoggerPlugin()
|
||||
new nsWebpack.WatchStateLoggerPlugin(),
|
||||
],
|
||||
};
|
||||
|
||||
@ -324,40 +311,42 @@ module.exports = env => {
|
||||
config.module.rules.push(
|
||||
{
|
||||
test: /-page\.js$/,
|
||||
use: "@nativescript/webpack/helpers/script-hot-loader"
|
||||
use: '@nativescript/webpack/helpers/script-hot-loader',
|
||||
},
|
||||
{
|
||||
test: /\.(html|xml)$/,
|
||||
use: "@nativescript/webpack/helpers/markup-hot-loader"
|
||||
use: '@nativescript/webpack/helpers/markup-hot-loader',
|
||||
},
|
||||
|
||||
{ test: /\.(html|xml)$/, use: "@nativescript/webpack/helpers/xml-namespace-loader" }
|
||||
{ test: /\.(html|xml)$/, use: '@nativescript/webpack/helpers/xml-namespace-loader' }
|
||||
);
|
||||
}
|
||||
|
||||
if (report) {
|
||||
// Generate report files for bundles content
|
||||
config.plugins.push(new BundleAnalyzerPlugin({
|
||||
analyzerMode: "static",
|
||||
config.plugins.push(
|
||||
new BundleAnalyzerPlugin({
|
||||
analyzerMode: 'static',
|
||||
openAnalyzer: false,
|
||||
generateStatsFile: true,
|
||||
reportFilename: resolve(projectRoot, "report", `report.html`),
|
||||
statsFilename: resolve(projectRoot, "report", `stats.json`),
|
||||
}));
|
||||
reportFilename: resolve(projectRoot, 'report', `report.html`),
|
||||
statsFilename: resolve(projectRoot, 'report', `stats.json`),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (snapshot) {
|
||||
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
|
||||
chunk: "vendor",
|
||||
requireModules: [
|
||||
"@nativescript/core/bundle-entry-points",
|
||||
],
|
||||
config.plugins.push(
|
||||
new nsWebpack.NativeScriptSnapshotPlugin({
|
||||
chunk: 'vendor',
|
||||
requireModules: ['@nativescript/core/bundle-entry-points'],
|
||||
projectRoot,
|
||||
webpackConfig: config,
|
||||
snapshotInDocker,
|
||||
skipSnapshotTools,
|
||||
useLibs
|
||||
}));
|
||||
useLibs,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (hmr) {
|
||||
|
Reference in New Issue
Block a user