1
1
var webpack = require("webpack");
2
2
var nsWebpack = require("nativescript-dev-webpack");
3
- var sources = require("webpack-sources");
4
3
var path = require("path");
5
- var CopyWebpackPlugin = require('copy-webpack-plugin');
6
- var fs = require("fs");
4
+ var CopyWebpackPlugin = require("copy-webpack-plugin");
7
5
var path = require("path");
8
6
9
7
module.exports = function(platform, destinationApp) {
10
8
if (!destinationApp) {
9
+ //Default destination inside platforms/<platform>/...
11
10
destinationApp = nsWebpack.getAppPath(platform);
12
11
}
13
12
var entry = {};
13
+ //Discover entry module from package.json
14
14
entry.bundle = "./" + nsWebpack.getEntryModule();
15
+ //Vendor entry with third party libraries.
15
16
entry.vendor = "./vendor";
16
17
17
18
return {
@@ -25,12 +26,14 @@ module.exports = function(platform, destinationApp) {
25
26
jsonpFunction: "nativescriptJsonp"
26
27
},
27
28
resolve: {
29
+ //Resolve platform-specific modules like module.android.js
28
30
extensions: [
29
31
".ts",
30
32
".js",
31
33
"." + platform + ".ts",
32
34
"." + platform + ".js",
33
35
],
36
+ //Resolve {N} system modules from tns-core-modules
34
37
modules: [
35
38
"node_modules/tns-core-modules",
36
39
"node_modules"
@@ -46,38 +49,54 @@ module.exports = function(platform, destinationApp) {
46
49
loaders: [
47
50
{
48
51
test: /\.html$/,
49
- loader: "html-loader"
52
+ loader: "raw-loader"
53
+ },
54
+ {
55
+ test: /\.css$/,
56
+ loader: "raw-loader"
50
57
},
51
58
{
52
59
test: /\.ts$/,
53
- loader: 'awesome-typescript-loader'
60
+ loaders: [
61
+ "awesome-typescript-loader",
62
+ "angular2-template-loader"
63
+ ]
54
64
},
55
65
{
56
66
test: /\.scss$/,
57
67
loaders: [
58
- 'raw-loader', 'resolve-url', 'sass'
68
+ "raw-loader",
69
+ "resolve-url",
70
+ "sass-loader"
59
71
]
60
72
},
61
73
]
62
74
},
63
75
plugins: [
76
+ //Vendor libs go to the vendor.js chunk
64
77
new webpack.optimize.CommonsChunkPlugin({
65
78
name: ["vendor"]
66
79
}),
80
+ //Define useful constants like TNS_WEBPACK
67
81
new webpack.DefinePlugin({
68
- global: ' global' ,
69
- __dirname: ' __dirname' ,
70
- "global.TNS_WEBPACK": ' true' ,
82
+ global: " global" ,
83
+ __dirname: " __dirname" ,
84
+ "global.TNS_WEBPACK": " true" ,
71
85
}),
86
+ //Copy assets to out dir. Add your own globs as needed.
72
87
new CopyWebpackPlugin([
73
- { from: "**/*.css" },
74
- { from: "**/*.html" },
75
- { from: "**/*.xml", ignore: "App_Resources/**" },
76
- ]),
88
+ {from: "app.css"},
89
+ {from: "css/**"},
90
+ {from: "**/*.jpg"},
91
+ {from: "**/*.png"},
92
+ {from: "**/*.xml"},
93
+ ], {ignore: ["App_Resources/**"]}),
94
+ //Generate a bundle starter script and activate it in package.json
77
95
new nsWebpack.GenerateBundleStarterPlugin([
78
96
"./vendor",
79
97
"./bundle",
80
98
]),
99
+ //Required for bundle chunks loading
81
100
new nsWebpack.NativeScriptJsonpPlugin(),
82
101
]
83
102
};
0 commit comments