feat: initial angular support + clean up tests

This commit is contained in:
Igor Randjelovic
2020-11-25 17:44:00 +01:00
parent 015d337e2a
commit d9a93040fe
17 changed files with 651 additions and 48 deletions

View File

@@ -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;
}

View File

@@ -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
View File

@@ -0,0 +1 @@
declare var __TEST__: boolean;

View File

@@ -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() {

View File

@@ -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);
}