style: run prettier on webpack5 files

This commit is contained in:
Igor Randjelovic
2021-03-29 01:24:23 +02:00
parent c55782bfaf
commit c922e77129
13 changed files with 138 additions and 110 deletions

View File

@@ -1,6 +1,6 @@
import Config from 'webpack-chain';
import { getEntryPath, getEntryDirPath } from "../helpers/platform";
import { getEntryPath, getEntryDirPath } from '../helpers/platform';
import { addVirtualEntry } from '../helpers/virtualModules';
import { env as _env, IWebpackEnv } from '../index';
import base from './base';
@@ -36,15 +36,14 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
config.module
.rule('hmr-core')
.test(/\.js$/)
.exclude
.add(/node_modules/)
.exclude.add(/node_modules/)
.add(entryPath)
.end()
.use('nativescript-hot-loader')
.loader('nativescript-hot-loader')
.options({
appPath: getEntryDirPath()
})
appPath: getEntryDirPath(),
});
return config;
}

View File

@@ -53,14 +53,12 @@ function getSvelteConfigPreprocessor(): any {
}
interface ISvelteConfig {
preprocess: any
preprocess: any;
}
function getSvelteConfig(): ISvelteConfig | undefined {
try {
return require(
getProjectFilePath('svelte.config.js')
) as ISvelteConfig;
return require(getProjectFilePath('svelte.config.js')) as ISvelteConfig;
} catch (err) {
error('Could not find svelte.config.js.', err);
}

View File

@@ -1,6 +1,6 @@
import Config from 'webpack-chain';
import { getEntryDirPath, getEntryPath } from "../helpers/platform";
import { getEntryDirPath, getEntryPath } from '../helpers/platform';
import { addVirtualEntry } from '../helpers/virtualModules';
import { env as _env, IWebpackEnv } from '../index';
import base from './base';
@@ -36,15 +36,14 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
config.module
.rule('hmr-core')
.test(/\.(js|ts)$/)
.exclude
.add(/node_modules/)
.exclude.add(/node_modules/)
.add(entryPath)
.end()
.use('nativescript-hot-loader')
.loader('nativescript-hot-loader')
.options({
appPath: getEntryDirPath()
})
appPath: getEntryDirPath(),
});
return config;
}

View File

@@ -3,10 +3,10 @@ import { merge } from 'webpack-merge';
import Config from 'webpack-chain';
import fs from 'fs';
import { hasDependency } from "../helpers/dependencies";
import { hasDependency } from '../helpers/dependencies';
import { getPlatformName } from '../helpers/platform';
import { env as _env, IWebpackEnv } from '../index';
import { error } from "../helpers/log";
import { error } from '../helpers/log';
import base from './base';
export default function (config: Config, env: IWebpackEnv = _env): Config {
@@ -15,8 +15,8 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
const platform = getPlatformName();
// we need to patch VueLoader if we want to enable hmr
if(env.hmr) {
patchVueLoaderForHMR()
if (env.hmr) {
patchVueLoaderForHMR();
}
// resolve .vue files
@@ -82,12 +82,15 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
*/
function patchVueLoaderForHMR() {
try {
const vueLoaderPath = require.resolve('vue-loader/lib/index.js')
const vueLoaderPath = require.resolve('vue-loader/lib/index.js');
const source = fs.readFileSync(vueLoaderPath).toString();
const patchedSource = source.replace(/(isServer\s=\s)(target\s===\s'node')/g, '$1false;')
fs.writeFileSync(vueLoaderPath, patchedSource)
delete require.cache[vueLoaderPath]
const patchedSource = source.replace(
/(isServer\s=\s)(target\s===\s'node')/g,
'$1false;'
);
fs.writeFileSync(vueLoaderPath, patchedSource);
delete require.cache[vueLoaderPath];
} catch (err) {
error('Failed to patch VueLoader - HMR may not work properly!')
error('Failed to patch VueLoader - HMR may not work properly!');
}
}