Skip to content

Commit b058c1c

Browse files
author
vakrilov
committed
Added webpack configs and readme update
1 parent f8da02e commit b058c1c

File tree

5 files changed

+162
-14
lines changed

5 files changed

+162
-14
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
logs
33
*.log
44
npm-debug.log*
5+
.DS_Store
56

67
# Runtime data
78
pids
@@ -40,6 +41,7 @@ jspm_packages
4041
#Exclude all javascript (js) and (js.map) files from source code
4142
**/*.js
4243
**/*.map
44+
!examples/CameraTestAngular/webpack.*.js
4345

4446
# Dist directory where create script produces plugin installation files
4547
dist

README.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
# nativescript-camera
22
NativeScript plugin to empower using device camera.
33

4-
Steps to create redistributable package.
5-
6-
1. cd to root folder of the plugin.
7-
2. npm install
8-
3. ./create.sh
4+
## Build
95

6+
Run the create script in the root of the repo:
7+
```
8+
./create.sh
9+
```
1010
This will create a `nativescript-camera-*.tgz` file (* stands for version) within ./dist folder.
11-
12-
Prerequisites:
13-
14-
1. tns-core-modules >= 2.4.0
15-
2. tns-core-modules-widgets >= 2.4.0
16-
3. tns-platform-declarations@next
17-
18-
> Note: On Android 6.0 and above it is neccessary to request permissions for camera (to be able to take picture) and access for Photos (to be able to share the image via Google Photos app).
19-
NativeScript-camera plug-in has a dedicated method called `requestPermissions()` which can be used in that case.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var makeConfig = require("./webpack.common");
2+
module.exports = makeConfig("android");
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
var AotPlugin = require("@ngtools/webpack").AotPlugin;
8+
9+
module.exports = function (platform, destinationApp) {
10+
if (!destinationApp) {
11+
//Default destination inside platforms/<platform>/...
12+
destinationApp = nsWebpack.getAppPath(platform);
13+
}
14+
var entry = {};
15+
//Discover entry module from package.json
16+
entry.bundle = "./" + nsWebpack.getEntryModule();
17+
//Vendor entry with third party libraries.
18+
entry.vendor = "./vendor";
19+
//app.css bundle
20+
entry["app.css"] = "./app.css";
21+
22+
var plugins = [
23+
new ExtractTextPlugin("app.css"),
24+
//Vendor libs go to the vendor.js chunk
25+
new webpack.optimize.CommonsChunkPlugin({
26+
name: ["vendor"]
27+
}),
28+
//Define useful constants like TNS_WEBPACK
29+
new webpack.DefinePlugin({
30+
"global.TNS_WEBPACK": "true",
31+
}),
32+
//Copy assets to out dir. Add your own globs as needed.
33+
new CopyWebpackPlugin([
34+
{ from: "app.css" },
35+
{ from: "css/**" },
36+
{ from: "fonts/**" },
37+
{ from: "**/*.jpg" },
38+
{ from: "**/*.png" },
39+
{ from: "**/*.xml" },
40+
], { ignore: ["App_Resources/**"] }),
41+
//Generate a bundle starter script and activate it in package.json
42+
new nsWebpack.GenerateBundleStarterPlugin([
43+
"./vendor",
44+
"./bundle",
45+
]),
46+
47+
//Angular AOT compiler
48+
new AotPlugin({
49+
tsConfigPath: "tsconfig.aot.json",
50+
entryModule: path.resolve(__dirname, "app/app.module#AppModule"),
51+
typeChecking: false
52+
}),
53+
new nsWebpack.StyleUrlResolvePlugin({platform}),
54+
];
55+
56+
if (process.env.npm_config_uglify) {
57+
plugins.push(new webpack.LoaderOptionsPlugin({
58+
minimize: true
59+
}));
60+
61+
//Work around an Android issue by setting compress = false
62+
var compress = platform !== "android";
63+
plugins.push(new webpack.optimize.UglifyJsPlugin({
64+
mangle: {
65+
except: nsWebpack.uglifyMangleExcludes,
66+
},
67+
compress: compress,
68+
}));
69+
}
70+
71+
return {
72+
context: path.resolve("./app"),
73+
target: nativescriptTarget,
74+
entry: entry,
75+
output: {
76+
pathinfo: true,
77+
path: path.resolve(destinationApp),
78+
libraryTarget: "commonjs2",
79+
filename: "[name].js",
80+
},
81+
resolve: {
82+
//Resolve platform-specific modules like module.android.js
83+
extensions: [
84+
".aot.ts",
85+
".ts",
86+
".js",
87+
".css",
88+
"." + platform + ".ts",
89+
"." + platform + ".js",
90+
"." + platform + ".css",
91+
],
92+
//Resolve {N} system modules from tns-core-modules
93+
modules: [
94+
"node_modules/tns-core-modules",
95+
"node_modules"
96+
]
97+
},
98+
node: {
99+
//Disable node shims that conflict with NativeScript
100+
"http": false,
101+
"timers": false,
102+
"setImmediate": false,
103+
"fs": "empty",
104+
},
105+
module: {
106+
loaders: [
107+
{
108+
test: /\.html$|\.xml$/,
109+
loaders: [
110+
"raw-loader",
111+
]
112+
},
113+
// Root app.css file gets extracted with bundled dependencies
114+
{
115+
test: /app\.css$/,
116+
loader: ExtractTextPlugin.extract([
117+
"resolve-url-loader",
118+
"nativescript-css-loader",
119+
"nativescript-dev-webpack/platform-css-loader",
120+
]),
121+
},
122+
// Other CSS files get bundled using the raw loader
123+
{
124+
test: /\.css$/,
125+
exclude: /app\.css$/,
126+
loaders: [
127+
"raw-loader",
128+
]
129+
},
130+
// Compile TypeScript files with ahead-of-time compiler.
131+
{
132+
test: /\.ts$/,
133+
loaders: [
134+
"nativescript-dev-webpack/tns-aot-loader",
135+
"@ngtools/webpack",
136+
]
137+
},
138+
// SASS support
139+
{
140+
test: /\.scss$/,
141+
loaders: [
142+
"raw-loader",
143+
"resolve-url-loader",
144+
"sass-loader"
145+
]
146+
},
147+
]
148+
},
149+
plugins: plugins,
150+
};
151+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var makeConfig = require("./webpack.common");
2+
module.exports = makeConfig("ios");

0 commit comments

Comments
 (0)