|
1 | 1 | import { command } from 'yargs'
|
2 | 2 | import { take, tap } from 'rxjs/operators'
|
3 | 3 | import { logInfo } from '../utilities/log'
|
4 |
| -import { FuseBox, JSONPlugin } from 'fuse-box' |
| 4 | +import { FuseBox, JSONPlugin, QuantumPlugin } from 'fuse-box' |
5 | 5 | import { resolve } from 'path'
|
6 | 6 | import { NgProdPlugin } from '../fusebox/ng.prod.plugin'
|
7 | 7 | import { NgPolyfillPlugin } from '../fusebox/ng.polyfill.plugin'
|
@@ -60,65 +60,80 @@ import readConfig_ from '../utilities/read-config'
|
60 | 60 | // }
|
61 | 61 |
|
62 | 62 | command(
|
63 |
| - 'serve [port]', |
| 63 | + 'serve [port][prod]', |
64 | 64 | 'serve your application',
|
65 | 65 | args => {
|
66 | 66 | return args
|
67 | 67 | },
|
68 | 68 | args => {
|
69 |
| - serve() |
| 69 | + serve(args.prod) |
70 | 70 | }
|
71 |
| -).option('port', { |
72 |
| - alias: 'p', |
73 |
| - default: 5000, |
74 |
| - description: 'Http server port number' |
75 |
| -}) |
| 71 | +) |
| 72 | + .option('prod', { |
| 73 | + default: false, |
| 74 | + description: 'Run with optimizations enabled' |
| 75 | + }) |
| 76 | + .option('port', { |
| 77 | + default: 5000, |
| 78 | + description: 'Http server port number' |
| 79 | + }) |
76 | 80 |
|
77 | 81 | function logServeCommandStart() {
|
78 | 82 | logInfo('Launching Serve Command')
|
79 | 83 | }
|
80 | 84 |
|
81 |
| -function serve() { |
| 85 | +function serve(isProdBuild = false) { |
82 | 86 | readConfig_()
|
83 | 87 | .pipe(
|
84 | 88 | tap(logServeCommandStart),
|
85 | 89 | take(1)
|
86 | 90 | )
|
87 | 91 | .subscribe(config => {
|
| 92 | + const cache = !isProdBuild |
| 93 | + const log = config.fusebox.verbose || false |
88 | 94 | const homeDir = resolve(config.fusebox.server.homeDir)
|
89 | 95 | const serverOutput = resolve(config.fusebox.server.outputDir)
|
90 | 96 | const browserOutput = resolve(config.fusebox.browser.outputDir)
|
| 97 | + const modulesFolder = resolve(process.cwd(), 'node_modules') |
91 | 98 |
|
92 | 99 | const fuseBrowser = FuseBox.init({
|
| 100 | + log, |
| 101 | + modulesFolder, |
93 | 102 | homeDir,
|
94 |
| - cache: false, |
| 103 | + cache, |
95 | 104 | output: `${browserOutput}/$name.js`,
|
96 | 105 | target: 'browser@es5',
|
97 | 106 | plugins: [
|
98 |
| - NgProdPlugin({ enabled: false }), |
99 |
| - NgPolyfillPlugin() |
| 107 | + NgProdPlugin({ enabled: isProdBuild }), |
| 108 | + NgPolyfillPlugin(), |
100 | 109 | // NgCompilerPlugin({ enabled: opts.enableAotCompilaton }),
|
101 | 110 | // NgOptimizerPlugin({ enabled: opts.enableAngularBuildOptimizer }),
|
102 |
| - // opts.productionBuild && QuantumPlugin({ |
103 |
| - // warnings: false, |
104 |
| - // uglify: false, |
105 |
| - // treeshake: false, |
106 |
| - // bakeApiIntoBundle: 'vendor' |
107 |
| - // // replaceProcessEnv: false, |
108 |
| - // // processPolyfill: true, |
109 |
| - // // ensureES5: true |
110 |
| - // }) |
| 111 | + isProdBuild && |
| 112 | + QuantumPlugin({ |
| 113 | + warnings: false, |
| 114 | + uglify: config.fusebox.browser.prod.uglify, |
| 115 | + treeshake: config.fusebox.browser.prod.treeshake, |
| 116 | + bakeApiIntoBundle: 'vendor' |
| 117 | + // replaceProcessEnv: false, |
| 118 | + // processPolyfill: true, |
| 119 | + // ensureES5: true |
| 120 | + }) |
111 | 121 | ] as any
|
112 | 122 | })
|
113 | 123 |
|
114 | 124 | const fuseServer = FuseBox.init({
|
| 125 | + log, |
| 126 | + modulesFolder, |
115 | 127 | target: 'server@es5',
|
116 |
| - cache: false, |
| 128 | + cache, |
117 | 129 | homeDir,
|
118 | 130 | output: `${serverOutput}/$name.js`,
|
119 | 131 | plugins: [
|
120 | 132 | JSONPlugin(),
|
121 |
| - NgProdPlugin({ enabled: false, fileTest: 'server.angular.module' }), |
| 133 | + NgProdPlugin({ |
| 134 | + enabled: isProdBuild, |
| 135 | + fileTest: 'server.angular.module' |
| 136 | + }), |
122 | 137 | NgPolyfillPlugin({
|
123 | 138 | isServer: true,
|
124 | 139 | fileTest: 'server.angular.module'
|
|
0 commit comments