Skip to content

Commit 1f2081f

Browse files
fix: read modules from local directory instead of global (#15)
1 parent 8a11e9d commit 1f2081f

File tree

3 files changed

+49
-24
lines changed

3 files changed

+49
-24
lines changed

src/commands/serve.ts

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { command } from 'yargs'
22
import { take, tap } from 'rxjs/operators'
33
import { logInfo } from '../utilities/log'
4-
import { FuseBox, JSONPlugin } from 'fuse-box'
4+
import { FuseBox, JSONPlugin, QuantumPlugin } from 'fuse-box'
55
import { resolve } from 'path'
66
import { NgProdPlugin } from '../fusebox/ng.prod.plugin'
77
import { NgPolyfillPlugin } from '../fusebox/ng.polyfill.plugin'
@@ -60,65 +60,80 @@ import readConfig_ from '../utilities/read-config'
6060
// }
6161

6262
command(
63-
'serve [port]',
63+
'serve [port][prod]',
6464
'serve your application',
6565
args => {
6666
return args
6767
},
6868
args => {
69-
serve()
69+
serve(args.prod)
7070
}
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+
})
7680

7781
function logServeCommandStart() {
7882
logInfo('Launching Serve Command')
7983
}
8084

81-
function serve() {
85+
function serve(isProdBuild = false) {
8286
readConfig_()
8387
.pipe(
8488
tap(logServeCommandStart),
8589
take(1)
8690
)
8791
.subscribe(config => {
92+
const cache = !isProdBuild
93+
const log = config.fusebox.verbose || false
8894
const homeDir = resolve(config.fusebox.server.homeDir)
8995
const serverOutput = resolve(config.fusebox.server.outputDir)
9096
const browserOutput = resolve(config.fusebox.browser.outputDir)
97+
const modulesFolder = resolve(process.cwd(), 'node_modules')
9198

9299
const fuseBrowser = FuseBox.init({
100+
log,
101+
modulesFolder,
93102
homeDir,
94-
cache: false,
103+
cache,
95104
output: `${browserOutput}/$name.js`,
96105
target: 'browser@es5',
97106
plugins: [
98-
NgProdPlugin({ enabled: false }),
99-
NgPolyfillPlugin()
107+
NgProdPlugin({ enabled: isProdBuild }),
108+
NgPolyfillPlugin(),
100109
// NgCompilerPlugin({ enabled: opts.enableAotCompilaton }),
101110
// 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+
})
111121
] as any
112122
})
113123

114124
const fuseServer = FuseBox.init({
125+
log,
126+
modulesFolder,
115127
target: 'server@es5',
116-
cache: false,
128+
cache,
117129
homeDir,
118130
output: `${serverOutput}/$name.js`,
119131
plugins: [
120132
JSONPlugin(),
121-
NgProdPlugin({ enabled: false, fileTest: 'server.angular.module' }),
133+
NgProdPlugin({
134+
enabled: isProdBuild,
135+
fileTest: 'server.angular.module'
136+
}),
122137
NgPolyfillPlugin({
123138
isServer: true,
124139
fileTest: 'server.angular.module'

src/templates/fusebox.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
export const FUSEBOX_DEFAULTS = {
2+
verbose: false,
23
browser: {
34
homeDir: 'src',
45
outputDir: '.dist/public/js',
5-
browserModule: 'browser/app.browser.module.ts'
6+
browserModule: 'browser/app.browser.module.ts',
7+
prod: {
8+
uglify: true,
9+
treeshake: true
10+
}
611
},
712
server: {
813
homeDir: 'src',

src/utilities/read-config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ export interface FuseBoxServerConfig extends FuseBoxBaseConfig {
2121

2222
export interface FuseBoxBrowserConfig extends FuseBoxBaseConfig {
2323
readonly browserModule: string
24+
readonly prod: {
25+
readonly uglify: boolean
26+
readonly treeshake: boolean
27+
}
2428
}
2529

2630
export interface FuseBoxConfig {
2731
readonly server: FuseBoxServerConfig
2832
readonly browser: FuseBoxBrowserConfig
33+
readonly verbose: boolean
2934
}
3035

3136
export interface FusingAngularConfig {

0 commit comments

Comments
 (0)