mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: initial angular support + clean up tests
This commit is contained in:
@@ -1,10 +1,48 @@
|
||||
import Config from 'webpack-chain';
|
||||
import path from 'path';
|
||||
|
||||
import { IWebpackEnv } from '../index';
|
||||
import { getEntryPath, getProjectRootPath } from '../helpers/project';
|
||||
import { env as _env, IWebpackEnv } from '../index';
|
||||
import base from './base';
|
||||
|
||||
export default function (config: Config, env: IWebpackEnv): Config {
|
||||
export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
base(config, env);
|
||||
|
||||
const tsConfigPath = path.join(getProjectRootPath(), 'tsconfig.json');
|
||||
|
||||
// remove default ts rule
|
||||
config.module.rules.delete('ts');
|
||||
|
||||
config.module
|
||||
.rule('angular')
|
||||
.test(/(?:\.ngfactory.js|\.ngstyle\.js|\.ts)$/)
|
||||
.use('@ngtools/webpack')
|
||||
.loader('@ngtools/webpack');
|
||||
|
||||
config.module
|
||||
.rule('@angular/core')
|
||||
.test(/[\/\\]@angular[\/\\]core[\/\\].+\.js$/)
|
||||
.parser({ system: true });
|
||||
|
||||
// set up html
|
||||
config.module
|
||||
.rule('html')
|
||||
.test(/\.html$/)
|
||||
.use('raw-loader')
|
||||
.loader('raw-loader');
|
||||
|
||||
config.plugin('AngularCompilerPlugin').use(getAngularCompilerPlugin(), [
|
||||
{
|
||||
tsConfigPath,
|
||||
mainPath: getEntryPath(),
|
||||
platformTransformers: [require('../transformers/NativeClass').default],
|
||||
},
|
||||
]);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
function getAngularCompilerPlugin() {
|
||||
const { AngularCompilerPlugin } = require('@ngtools/webpack');
|
||||
return AngularCompilerPlugin;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ function getSvelteConfig(): { preprocess: any } | undefined {
|
||||
});
|
||||
return require(resolvedPath);
|
||||
} catch (err) {
|
||||
// todo: remove when jest supports mocking require.resolve
|
||||
if (__TEST__) return;
|
||||
error('Could not find svelte.config.js.', err);
|
||||
}
|
||||
}
|
||||
|
||||
1
packages/webpack5/src/globals.d.ts
vendored
Normal file
1
packages/webpack5/src/globals.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
declare var __TEST__: boolean;
|
||||
@@ -16,7 +16,7 @@ export function getAbsoluteDistPath() {
|
||||
export function getEntryPath() {
|
||||
const packageJson = getPackageJson();
|
||||
|
||||
return resolve(packageJson.main);
|
||||
return resolve(getProjectRootPath(), packageJson.main);
|
||||
}
|
||||
|
||||
export function getDistPath() {
|
||||
|
||||
@@ -59,8 +59,10 @@ export function useConfig(config: keyof typeof defaultConfigs | false) {
|
||||
}
|
||||
|
||||
export function chainWebpack(
|
||||
chainFn: (config: Config, env: IWebpackEnv) => any
|
||||
chainFn: (config: Config, env: IWebpackEnv) => any,
|
||||
options?: { last?: boolean }
|
||||
) {
|
||||
// todo: handle options.last by storing them in a separate array?
|
||||
webpackChains.push(chainFn);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user