Skip to content

Commit

Permalink
fix: update webnpack.config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
NickIliev committed May 7, 2019
1 parent 5443936 commit c3f4661
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"readme": "NativeScript Application",
"repository": "<fill-your-repository-here>",
"nativescript": {
"id": "org.nativescript.curiosity",
"tns-android": {
"version": "5.3.1"
}
"id": "org.nativescript.curiosity"
},
"dependencies": {
"@angular/animations": "~7.2.0",
Expand All @@ -28,7 +25,7 @@
"nativescript-theme-core": "^1.0.4",
"nativescript-ui-sidedrawer": "^6.0.0",
"reflect-metadata": "~0.1.13",
"rxjs": "^6.4.0",
"rxjs": "^6.3.3",
"tns-core-modules": "next",
"zone.js": "^0.8.4"
},
Expand All @@ -47,7 +44,7 @@
"nativescript-dev-webpack": "next",
"tns-platform-declarations": "~5.3.1",
"tslint": "^5.11.0",
"typescript": "3.1.1"
"typescript": "~3.1.1"
},
"scripts": {
"tslint": "tslint -p tsconfig.json",
Expand Down
22 changes: 14 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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 TerserPlugin = require("terser-webpack-plugin");
const { getAngularCompilerPlugin } = require("nativescript-dev-webpack/plugins/NativeScriptAngularCompilerPlugin");
const hashSalt = Date.now().toString();

Expand Down Expand Up @@ -47,10 +47,12 @@ module.exports = env => {
uglify, // --env.uglify
report, // --env.report
sourceMap, // --env.sourceMap
hiddenSourceMap, // --env.hiddenSourceMap
hmr, // --env.hmr,
unitTesting, // --env.unitTesting
} = env;

const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap;
const externals = nsWebpack.getConvertedExternals(env.externals);
const appFullPath = resolve(projectRoot, appPath);
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
Expand Down Expand Up @@ -89,13 +91,15 @@ module.exports = env => {
const ngCompilerPlugin = new AngularCompilerPlugin({
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
platformTransformers: ngCompilerTransformers.map(t => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule))),
mainPath: resolve(appPath, entryModule),
mainPath: join(appFullPath, entryModule),
tsConfigPath: join(__dirname, tsConfigName),
skipCodeGeneration: !aot,
sourceMap: !!sourceMap,
sourceMap: !!isAnySourceMapEnabled,
additionalLazyModuleResources: additionalLazyModuleResources
});

let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);

const config = {
mode: uglify ? "production" : "development",
context: appFullPath,
Expand All @@ -112,6 +116,7 @@ module.exports = env => {
output: {
pathinfo: false,
path: dist,
sourceMapFilename,
libraryTarget: "commonjs2",
filename: "[name].js",
globalObject: "global",
Expand Down Expand Up @@ -142,7 +147,7 @@ module.exports = env => {
"fs": "empty",
"__dirname": false,
},
devtool: sourceMap ? "inline-source-map" : "none",
devtool: hiddenSourceMap ? "hidden-source-map" : (sourceMap ? "inline-source-map" : "none"),
optimization: {
runtimeChunk: "single",
splitChunks: {
Expand All @@ -161,13 +166,14 @@ module.exports = env => {
},
minimize: !!uglify,
minimizer: [
new UglifyJsPlugin({
new TerserPlugin({
parallel: true,
cache: true,
sourceMap: !!sourceMap,
uglifyOptions: {
sourceMap: isAnySourceMapEnabled,
terserOptions: {
output: {
comments: false,
semicolons: !isAnySourceMapEnabled
},
compress: {
// The Android SBG has problems parsing the output
Expand Down Expand Up @@ -253,7 +259,7 @@ module.exports = env => {
new CleanWebpackPlugin([`${dist}/**/*`]),
// Copy assets to out dir. Add your own globs as needed.
new CopyWebpackPlugin([
{ from: { glob: "settings.json"} },
{ from: { glob: "settings.json"} }, // HERE
{ from: { glob: "fonts/**" } },
{ from: { glob: "**/*.jpg" } },
{ from: { glob: "**/*.png" } },
Expand Down

0 comments on commit c3f4661

Please sign in to comment.