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