11var webpack = require ( "webpack" ) ;
22var nsWebpack = require ( "nativescript-dev-webpack" ) ;
3+ var nativescriptTarget = require ( "nativescript-dev-webpack/nativescript-target" ) ;
34var path = require ( "path" ) ;
45var CopyWebpackPlugin = require ( "copy-webpack-plugin" ) ;
56var ExtractTextPlugin = require ( "extract-text-webpack-plugin" ) ;
6- var path = require ( "path" ) ;
7- var AotPlugin = require ( '@ngtools/webpack' ) . AotPlugin ;
8-
9- var nativescriptTarget = require ( 'nativescript-dev-webpack/nativescript-target' ) ;
7+ var AotPlugin = require ( "@ngtools/webpack" ) . AotPlugin ;
108
119module . exports = function ( platform , destinationApp ) {
1210 if ( ! destinationApp ) {
@@ -21,6 +19,51 @@ module.exports = function (platform, destinationApp) {
2119 //app.css bundle
2220 entry [ "app.css" ] = "./app.css" ;
2321
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 : "global" ,
31+ __dirname : "__dirname" ,
32+ "global.TNS_WEBPACK" : "true" ,
33+ } ) ,
34+ //Copy assets to out dir. Add your own globs as needed.
35+ new CopyWebpackPlugin ( [
36+ { from : "app.css" } ,
37+ { from : "css/**" } ,
38+ { from : "fonts/**" } ,
39+ { from : "**/*.jpg" } ,
40+ { from : "**/*.png" } ,
41+ { from : "**/*.xml" } ,
42+ ] , { ignore : [ "App_Resources/**" ] } ) ,
43+ //Generate a bundle starter script and activate it in package.json
44+ new nsWebpack . GenerateBundleStarterPlugin ( [
45+ "./vendor" ,
46+ "./bundle" ,
47+ ] ) ,
48+ //Angular AOT compiler
49+ new AotPlugin ( {
50+ tsConfigPath : "tsconfig.aot.json" ,
51+ entryModule : path . resolve ( __dirname , "app/app.module#AppModule" ) ,
52+ typeChecking : false
53+ } ) ,
54+ ] ;
55+
56+ if ( process . env . npm_config_uglify ) {
57+ //Work around an Android issue by setting compress = false
58+ var compress = platform !== "android" ;
59+ plugins . push ( new webpack . optimize . UglifyJsPlugin ( {
60+ mangle : {
61+ except : nsWebpack . uglifyMangleExcludes ,
62+ } ,
63+ compress : compress ,
64+ } ) ) ;
65+ }
66+
2467 return {
2568 context : path . resolve ( "./app" ) ,
2669 target : nativescriptTarget ,
@@ -48,11 +91,6 @@ module.exports = function (platform, destinationApp) {
4891 "node_modules"
4992 ]
5093 } ,
51- resolveLoader : {
52- alias : {
53- "raw" : path . join ( __dirname , "node_modules/raw-loader" ) ,
54- }
55- } ,
5694 node : {
5795 //Disable node shims that conflict with NativeScript
5896 "http" : false ,
@@ -63,7 +101,7 @@ module.exports = function (platform, destinationApp) {
63101 loaders : [
64102 {
65103 test : / \. h t m l $ / ,
66- loader : "raw"
104+ loader : "raw-loader "
67105 } ,
68106 // Root app.css file gets extracted with bundled dependencies
69107 {
@@ -79,59 +117,28 @@ module.exports = function (platform, destinationApp) {
79117 test : / \. c s s $ / ,
80118 exclude : / a p p \. c s s $ / ,
81119 loaders : [
82- "raw" ,
120+ "raw-loader " ,
83121 ]
84122 } ,
85123 // Compile TypeScript files with ahead-of-time compiler.
86124 {
87125 test : / \. t s $ / ,
88126 loaders : [
89- '@ngtools/ webpack' ,
90- 'nativescript-dev-webpack/tns-aot-loader'
127+ "nativescript-dev- webpack/tns-aot-loader" ,
128+ "@ngtools/webpack" ,
91129 ]
92130 } ,
93131 // SASS support
94132 {
95133 test : / \. s c s s $ / ,
96134 loaders : [
97- "raw" ,
135+ "raw-loader " ,
98136 "resolve-url-loader" ,
99137 "sass-loader"
100138 ]
101139 } ,
102140 ]
103141 } ,
104- plugins : [
105- new ExtractTextPlugin ( "app.css" ) ,
106- //Vendor libs go to the vendor.js chunk
107- new webpack . optimize . CommonsChunkPlugin ( {
108- name : [ "vendor" ]
109- } ) ,
110- //Define useful constants like TNS_WEBPACK
111- new webpack . DefinePlugin ( {
112- global : "global" ,
113- __dirname : "__dirname" ,
114- "global.TNS_WEBPACK" : "true" ,
115- } ) ,
116- //Copy assets to out dir. Add your own globs as needed.
117- new CopyWebpackPlugin ( [
118- { from : "app.css" } ,
119- { from : "css/**" } ,
120- { from : "**/*.jpg" } ,
121- { from : "**/*.png" } ,
122- { from : "**/*.xml" } ,
123- ] , { ignore : [ "App_Resources/**" ] } ) ,
124- //Generate a bundle starter script and activate it in package.json
125- new nsWebpack . GenerateBundleStarterPlugin ( [
126- "./vendor" ,
127- "./bundle" ,
128- ] ) ,
129- //Angular AOT compiler
130- new AotPlugin ( {
131- tsConfigPath : 'tsconfig.aot.json' ,
132- entryModule : 'app/app.module#AppModule' ,
133- typeChecking : false
134- } )
135- ] ,
142+ plugins : plugins ,
136143 } ;
137144} ;
0 commit comments