feat: env based replacements (#9286)

* feat: file replacement handling for TS and pure file copy replacements

* test: add tests for replacements & refactor a bit

Co-authored-by: Igor Randjelovic <rigor789@gmail.com>
This commit is contained in:
Nathan Walker
2021-03-28 16:13:51 -07:00
committed by GitHub
parent 0b32d5a88d
commit 7594d00ed9
11 changed files with 211 additions and 322 deletions

View File

@ -15,6 +15,7 @@ import { hasDependency } from '../helpers/dependencies';
import { applyDotEnvPlugin } from '../helpers/dotEnv';
import { env as _env, IWebpackEnv } from '../index';
import { getIPS } from '../helpers/host';
import { applyFileReplacements } from '../helpers/fileReplacements';
import {
getPlatformName,
getAbsoluteDistPath,
@ -81,9 +82,9 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
config.watchOptions({
ignored: [
`${getProjectFilePath('platforms')}/**`,
`${env.appResourcesPath ?? getProjectFilePath('App_Resources')}/**`
]
})
`${env.appResourcesPath ?? getProjectFilePath('App_Resources')}/**`,
],
});
// Set up Terser options
config.optimization.minimizer('TerserPlugin').use(TerserPlugin, [
@ -136,14 +137,15 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
// resolve symlinks
config.resolve.symlinks(true);
config.module.rule('bundle')
config.module
.rule('bundle')
.enforce('post')
.test(entryPath)
.use('nativescript-hot-loader')
.loader('nativescript-hot-loader')
.options({
injectHMRRuntime: true
})
injectHMRRuntime: true,
});
// set up ts support
config.module
@ -202,7 +204,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
.exclude.add(/node_modules/)
.end()
.use('nativescript-worker-loader')
.loader('nativescript-worker-loader')
.loader('nativescript-worker-loader');
// default PostCSS options to use
// projects can change settings
@ -301,6 +303,9 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
// enable DotEnv
applyDotEnvPlugin(config);
// replacements
applyFileReplacements(config);
// set up default copy rules
addCopyRule('assets/**');
addCopyRule('fonts/**');