|
| 1 | +var webpack = require("webpack"); |
| 2 | +var nsWebpack = require("nativescript-dev-webpack"); |
| 3 | +var nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); |
| 4 | +var path = require("path"); |
| 5 | +var CopyWebpackPlugin = require("copy-webpack-plugin"); |
| 6 | +var ExtractTextPlugin = require("extract-text-webpack-plugin"); |
| 7 | + |
| 8 | +module.exports = function (platform, destinationApp) { |
| 9 | + if (!destinationApp) { |
| 10 | + // Default destination inside platforms/<platform>/... |
| 11 | + destinationApp = nsWebpack.getAppPath(platform); |
| 12 | + } |
| 13 | + var entry = {}; |
| 14 | + // Discover entry module from package.json |
| 15 | + entry.bundle = "./" + nsWebpack.getEntryModule(); |
| 16 | + // Vendor entry with third party libraries. |
| 17 | + entry.vendor = "./vendor"; |
| 18 | + // app.css bundle |
| 19 | + entry["app.css"] = "./app.css"; |
| 20 | + |
| 21 | + var plugins = [ |
| 22 | + new ExtractTextPlugin("app.css"), |
| 23 | + // Vendor libs go to the vendor.js chunk |
| 24 | + new webpack.optimize.CommonsChunkPlugin({ |
| 25 | + name: ["vendor"] |
| 26 | + }), |
| 27 | + // Define useful constants like TNS_WEBPACK |
| 28 | + new webpack.DefinePlugin({ |
| 29 | + "global.TNS_WEBPACK": "true", |
| 30 | + }), |
| 31 | + // Copy assets to out dir. Add your own globs as needed. |
| 32 | + new CopyWebpackPlugin([ |
| 33 | + { from: "app.css" }, |
| 34 | + { from: "css/**" }, |
| 35 | + { from: "fonts/**" }, |
| 36 | + { from: "**/*.jpg" }, |
| 37 | + { from: "**/*.png" }, |
| 38 | + { from: "**/*.xml" }, |
| 39 | + ], { ignore: ["App_Resources/**"] }), |
| 40 | + // Generate a bundle starter script and activate it in package.json |
| 41 | + new nsWebpack.GenerateBundleStarterPlugin([ |
| 42 | + "./vendor", |
| 43 | + "./bundle", |
| 44 | + ]), |
| 45 | + ]; |
| 46 | + |
| 47 | + if (process.env.npm_config_uglify) { |
| 48 | + plugins.push(new webpack.LoaderOptionsPlugin({ |
| 49 | + minimize: true |
| 50 | + })); |
| 51 | + |
| 52 | + // Work around an Android issue by setting compress = false |
| 53 | + var compress = platform !== "android"; |
| 54 | + plugins.push(new webpack.optimize.UglifyJsPlugin({ |
| 55 | + mangle: { |
| 56 | + except: nsWebpack.uglifyMangleExcludes, |
| 57 | + }, |
| 58 | + compress: compress, |
| 59 | + })); |
| 60 | + } |
| 61 | + |
| 62 | + return { |
| 63 | + context: path.resolve("./app"), |
| 64 | + target: nativescriptTarget, |
| 65 | + entry: entry, |
| 66 | + output: { |
| 67 | + pathinfo: true, |
| 68 | + path: path.resolve(destinationApp), |
| 69 | + libraryTarget: "commonjs2", |
| 70 | + filename: "[name].js", |
| 71 | + }, |
| 72 | + resolve: { |
| 73 | + // Resolve platform-specific modules like module.android.js |
| 74 | + extensions: [ |
| 75 | + ".js", |
| 76 | + ".css", |
| 77 | + "." + platform + ".js", |
| 78 | + "." + platform + ".css", |
| 79 | + ], |
| 80 | + // Resolve {N} system modules from tns-core-modules |
| 81 | + modules: [ |
| 82 | + "node_modules/tns-core-modules", |
| 83 | + "node_modules", |
| 84 | + ] |
| 85 | + }, |
| 86 | + node: { |
| 87 | + // Disable node shims that conflict with NativeScript |
| 88 | + "http": false, |
| 89 | + "timers": false, |
| 90 | + "setImmediate": false, |
| 91 | + "fs": "empty", |
| 92 | + }, |
| 93 | + module: { |
| 94 | + loaders: [ |
| 95 | + { |
| 96 | + test: /\.html$/, |
| 97 | + loader: "raw-loader" |
| 98 | + }, |
| 99 | + // Root app.css file gets extracted with bundled dependencies |
| 100 | + { |
| 101 | + test: /app\.css$/, |
| 102 | + loader: ExtractTextPlugin.extract([ |
| 103 | + "resolve-url-loader", |
| 104 | + "nativescript-css-loader", |
| 105 | + "nativescript-dev-webpack/platform-css-loader", |
| 106 | + ]), |
| 107 | + }, |
| 108 | + // Other CSS files get bundled using the raw loader |
| 109 | + { |
| 110 | + test: /\.css$/, |
| 111 | + exclude: /app\.css$/, |
| 112 | + loaders: [ |
| 113 | + "raw-loader", |
| 114 | + ] |
| 115 | + }, |
| 116 | + // SASS support |
| 117 | + { |
| 118 | + test: /\.scss$/, |
| 119 | + loaders: [ |
| 120 | + "raw-loader", |
| 121 | + "resolve-url-loader", |
| 122 | + "sass-loader", |
| 123 | + ] |
| 124 | + }, |
| 125 | + ] |
| 126 | + }, |
| 127 | + plugins: plugins, |
| 128 | + }; |
| 129 | +}; |
0 commit comments