From 7f1e4314aada19f11af3869ba6c75edc2b90794b Mon Sep 17 00:00:00 2001 From: tsonevn Date: Wed, 10 Jul 2019 11:20:09 +0300 Subject: [PATCH] updating package.json --- .gitignore | 1 - app/app.js | 1 + package.json | 5 +- webpack.config.js | 291 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 296 insertions(+), 2 deletions(-) create mode 100644 webpack.config.js diff --git a/.gitignore b/.gitignore index 2b98f65..8a00a0a 100644 --- a/.gitignore +++ b/.gitignore @@ -44,7 +44,6 @@ bin/ gen/ package-lock.json -webpack.config.js e2e/reports test-results.xml diff --git a/app/app.js b/app/app.js index de7f4f4..4d735d6 100644 --- a/app/app.js +++ b/app/app.js @@ -31,3 +31,4 @@ application.on(application.resumeEvent, function (args) { } }); application.run({ moduleName: "app-root" }); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiYXBwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBS0EsMERBQTREO0FBQzVELDBEQUE0RDtBQUM1RCxpRkFBa0Y7QUFFbEYsSUFBTSxrQkFBa0IsR0FBRyxPQUFPLENBQUMseUJBQXlCLENBQUMsQ0FBQztBQUM5RCxJQUFJLGNBQWMsQ0FBQyxLQUFLLEVBQUU7SUFDdEIsSUFBTSxVQUFVLEdBQUcsT0FBTyxDQUFDLHdCQUF3QixDQUFDLENBQUM7SUFDckQsV0FBVyxDQUFDLEdBQUcsQ0FBQyxRQUFRLEdBQUcsVUFBVSxDQUFDLFVBQVUsQ0FBQztDQUNwRDtBQUVELFNBQVMsYUFBYTtJQUNsQixJQUFNLFFBQVEsR0FBa0IsV0FBVyxDQUFDLFdBQVcsRUFBRSxDQUFDO0lBQzFELElBQUkseUJBQXlCLENBQUMsTUFBTSxDQUFDLGFBQWEsQ0FBQyxFQUFFO1FBQ2pELElBQU0sS0FBSyxHQUFHLHlCQ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AgICAgIHJvb3RWaWV3Lm5hdmlnYXRlKHtcbiAgICAgICAgICAgICAgICBtb2R1bGVOYW1lOiB2YWx1ZSxcbiAgICAgICAgICAgICAgICBjbGVhckhpc3Rvcnk6IHRydWVcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxufVxuYXBwbGljYXRpb24ub24oYXBwbGljYXRpb24ucmVzdW1lRXZlbnQsIChhcmdzKSA9PiB7XG4gICAgaWYgKGFyZ3MuYW5kcm9pZCkge1xuICAgICAgICBjb25zdCBkbGQgPSBuZXcgZGVlcExpbmtEYXRhTW9kdWxlLkRlZXBMaW5rRGF0YShcIlwiLCBhcmdzLmFuZHJvaWQpO1xuICAgICAgICBsYXVuY2hFeGFtcGxlKCk7XG4gICAgfSBlbHNlIGlmIChhcmdzLmlvcykge1xuICAgICAgICBsYXVuY2hFeGFtcGxlKCk7XG4gICAgfVxufSk7XG5hcHBsaWNhdGlvbi5ydW4oeyBtb2R1bGVOYW1lOiBcImFwcC1yb290XCIgfSk7XG5cbi8qXG5EbyBub3QgcGxhY2UgYW55IGNvZGUgYWZ0ZXIgdGhlIGFwcGxpY2F0aW9uIGhhcyBiZWVuIHN0YXJ0ZWQgYXMgaXQgd2lsbCBub3RcbmJlIGV4ZWN1dGVkIG9uIGlPUy5cbiovXG4iXX0= \ No newline at end of file diff --git a/package.json b/package.json index a4c5b38..045611b 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,14 @@ "id": "org.nativescript.nativescriptsdkexamplesjs", "tns-android": { "version": "5.4.0" + }, + "tns-ios": { + "version": "5.4.2" } }, "dependencies": { "nativescript-theme-core": "~1.0.4", - "tns-core-modules": "^5.3.1" + "tns-core-modules": "^5.4.3" }, "devDependencies": { "eslint": "~5.9.0", diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..b24c242 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,291 @@ +const { join, relative, resolve, sep } = require("path"); + +const webpack = require("webpack"); +const nsWebpack = require("nativescript-dev-webpack"); +const nativescriptTarget = require("nativescript-dev-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 UglifyJsPlugin = require("uglifyjs-webpack-plugin"); +const hashSalt = Date.now().toString(); + +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!"); + } + + const platforms = ["ios", "android"]; + const projectRoot = __dirname; + + // Default destination inside platforms//... + const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); + const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; + + const { + // The 'appPath' and 'appResourcesPath' values are fetched from + // the nsconfig.json configuration file + // when bundling with `tns run android|ios --bundle`. + appPath = "app", + appResourcesPath = "app/App_Resources", + + // You can provide the following flags when running 'tns run android|ios' + snapshot, // --env.snapshot + uglify, // --env.uglify + report, // --env.report + sourceMap, // --env.sourceMap + hmr, // --env.hmr, + unitTesting, // --env.unitTesting + } = env; + const externals = nsWebpack.getConvertedExternals(env.externals); + + const appFullPath = resolve(projectRoot, appPath); + const appResourcesFullPath = resolve(projectRoot, appResourcesPath); + + const entryModule = nsWebpack.getEntryModule(appFullPath); + const entryPath = `.${sep}${entryModule}.ts`; + const entries = { bundle: entryPath }; + if (platform === "ios") { + entries["tns_modules/tns-core-modules/inspector_modules"] = "inspector_modules.js"; + }; + + const config = { + mode: uglify ? "production" : "development", + context: appFullPath, + externals, + watchOptions: { + ignored: [ + appResourcesFullPath, + // Don't watch hidden files + "**/.*", + ] + }, + target: nativescriptTarget, + entry: entries, + output: { + pathinfo: false, + path: dist, + libraryTarget: "commonjs2", + filename: "[name].js", + globalObject: "global", + hashSalt + }, + resolve: { + extensions: [".ts", ".js", ".scss", ".css"], + // Resolve {N} system modules from tns-core-modules + modules: [ + resolve(__dirname, "node_modules/tns-core-modules"), + resolve(__dirname, "node_modules"), + "node_modules/tns-core-modules", + "node_modules", + ], + alias: { + '~': appFullPath + }, + // resolve symlinks to symlinked modules + symlinks: true + }, + resolveLoader: { + // don't resolve symlinks to symlinked loaders + symlinks: false + }, + node: { + // Disable node shims that conflict with NativeScript + "http": false, + "timers": false, + "setImmediate": false, + "fs": "empty", + "__dirname": false, + }, + devtool: sourceMap ? "inline-source-map" : "none", + optimization: { + runtimeChunk: "single", + splitChunks: { + cacheGroups: { + vendor: { + name: "vendor", + chunks: "all", + test: (module, chunks) => { + const moduleName = module.nameForCondition ? module.nameForCondition() : ''; + return /[\\/]node_modules[\\/]/.test(moduleName) || + appComponents.some(comp => comp === moduleName); + + }, + enforce: true, + }, + } + }, + minimize: !!uglify, + minimizer: [ + new UglifyJsPlugin({ + parallel: true, + cache: true, + uglifyOptions: { + output: { + comments: false, + }, + compress: { + // The Android SBG has problems parsing the output + // when these options are enabled + 'collapse_vars': platform !== "android", + sequences: platform !== "android", + } + } + }) + ], + }, + module: { + rules: [ + { + test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath), + use: [ + // Require all Android app components + platform === "android" && { + loader: "nativescript-dev-webpack/android-app-components-loader", + options: { modules: appComponents } + }, + + { + loader: "nativescript-dev-webpack/bundle-config-loader", + options: { + loadCss: !snapshot, // load the application css if in debug mode + unitTesting, + appFullPath, + projectRoot, + } + }, + ].filter(loader => !!loader) + }, + + { + test: /-page\.ts$/, + use: "nativescript-dev-webpack/script-hot-loader" + }, + + { + test: /\.(css|scss)$/, + use: "nativescript-dev-webpack/style-hot-loader" + }, + + { + test: /\.(html|xml)$/, + use: "nativescript-dev-webpack/markup-hot-loader" + }, + + { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" }, + + { + test: /\.css$/, + use: { loader: "css-loader", options: { minimize: false, url: false } } + }, + + { + test: /\.scss$/, + use: [ + { loader: "css-loader", options: { minimize: false, url: false } }, + "sass-loader" + ] + }, + + { + test: /\.ts$/, + use: { + loader: "ts-loader", + options: { + configFile: "tsconfig.tns.json", + allowTsInNodeModules: true, + compilerOptions: { + sourceMap + } + }, + } + }, + ] + }, + plugins: [ + // Define useful constants like TNS_WEBPACK + new webpack.DefinePlugin({ + "global.TNS_WEBPACK": "true", + "process": undefined, + }), + // Remove all files from the out dir. + new CleanWebpackPlugin([`${dist}/**/*`]), + // Copy assets to out dir. Add your own globs as needed. + new CopyWebpackPlugin([ + { from: { glob: "ns-ui-widgets-category/web-view/source-load/*.html" } }, + { from: { glob: "ns-ui-widgets-category/placeholder/platform-files/*.ts" } }, + { from: { glob: "fonts/**" } }, + { from: { glob: "**/*.jpg" } }, + { from: { glob: "**/*.png" } }, + ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }), + // Generate a bundle starter script and activate it in package.json + new nsWebpack.GenerateBundleStarterPlugin( + // Don't include `runtime.js` when creating a snapshot. The plugin + // configures the WebPack runtime to be generated inside the snapshot + // module and no `runtime.js` module exist. + (snapshot ? [] : ["./runtime"]) + .concat([ + "./vendor", + "./bundle", + ]) + ), + // For instructions on how to set up workers with webpack + // check out https://github.com/nativescript/worker-loader + new NativeScriptWorkerPlugin(), + new nsWebpack.PlatformFSPlugin({ + platform, + platforms, + }), + // Does IPC communication with the {N} CLI to notify events when running in watch mode. + new nsWebpack.WatchStateLoggerPlugin(), + ], + }; + + // Copy the native app resources to the out dir + // only if doing a full build (tns run/build) and not previewing (tns preview) + if (!externals || externals.length === 0) { + config.plugins.push(new CopyWebpackPlugin([ + { + from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, + to: `${dist}/App_Resources/${appResourcesPlatformDir}`, + context: projectRoot + }, + ])); + } + + if (report) { + // Generate report files for bundles content + config.plugins.push(new BundleAnalyzerPlugin({ + analyzerMode: "static", + openAnalyzer: false, + generateStatsFile: true, + reportFilename: resolve(projectRoot, "report", `report.html`), + statsFilename: resolve(projectRoot, "report", `stats.json`), + })); + } + + if (snapshot) { + config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({ + chunk: "vendor", + requireModules: [ + "tns-core-modules/bundle-entry-points", + ], + projectRoot, + webpackConfig: config, + })); + } + + if (hmr) { + config.plugins.push(new webpack.HotModuleReplacementPlugin()); + } + + + return config; +};