mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
refactor: simplify copy handling
This commit is contained in:
@ -39,7 +39,6 @@
|
|||||||
"sass-loader": "^10.1.0",
|
"sass-loader": "^10.1.0",
|
||||||
"sax": "^1.2.4",
|
"sax": "^1.2.4",
|
||||||
"source-map": "^0.7.3",
|
"source-map": "^0.7.3",
|
||||||
"svelte-native-preprocessor": "^0.2.0",
|
|
||||||
"terser-webpack-plugin": "^5.0.3",
|
"terser-webpack-plugin": "^5.0.3",
|
||||||
"ts-dedent": "^2.0.0",
|
"ts-dedent": "^2.0.0",
|
||||||
"ts-loader": "^8.0.11",
|
"ts-loader": "^8.0.11",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { DefinePlugin, HotModuleReplacementPlugin } from 'webpack';
|
import { DefinePlugin, HotModuleReplacementPlugin } from 'webpack';
|
||||||
import Config from 'webpack-chain';
|
import Config from 'webpack-chain';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
|
||||||
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
|
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
|
||||||
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
|
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
|
||||||
@ -10,6 +11,7 @@ import TerserPlugin from 'terser-webpack-plugin';
|
|||||||
import { PlatformSuffixPlugin } from '../plugins/PlatformSuffixPlugin';
|
import { PlatformSuffixPlugin } from '../plugins/PlatformSuffixPlugin';
|
||||||
import { addCopyRule, applyCopyRules } from '../helpers/copyRules';
|
import { addCopyRule, applyCopyRules } from '../helpers/copyRules';
|
||||||
import { WatchStatePlugin } from '../plugins/WatchStatePlugin';
|
import { WatchStatePlugin } from '../plugins/WatchStatePlugin';
|
||||||
|
import { getProjectRootPath } from '../helpers/project';
|
||||||
import { hasDependency } from '../helpers/dependencies';
|
import { hasDependency } from '../helpers/dependencies';
|
||||||
import { IWebpackEnv } from '../index';
|
import { IWebpackEnv } from '../index';
|
||||||
import {
|
import {
|
||||||
@ -18,8 +20,6 @@ import {
|
|||||||
getEntryDirPath,
|
getEntryDirPath,
|
||||||
getEntryPath,
|
getEntryPath,
|
||||||
} from '../helpers/platform';
|
} from '../helpers/platform';
|
||||||
import { getProjectRootPath } from '../helpers/project';
|
|
||||||
import { resolve } from 'path';
|
|
||||||
|
|
||||||
export default function (config: Config, env: IWebpackEnv): Config {
|
export default function (config: Config, env: IWebpackEnv): Config {
|
||||||
const entryPath = getEntryPath();
|
const entryPath = getEntryPath();
|
||||||
@ -269,13 +269,15 @@ export default function (config: Config, env: IWebpackEnv): Config {
|
|||||||
|
|
||||||
config.when(env.report, (config) => {
|
config.when(env.report, (config) => {
|
||||||
const projectRoot = getProjectRootPath();
|
const projectRoot = getProjectRootPath();
|
||||||
config.plugin('BundleAnalyzerPlugin').use(BundleAnalyzerPlugin, [{
|
config.plugin('BundleAnalyzerPlugin').use(BundleAnalyzerPlugin, [
|
||||||
|
{
|
||||||
analyzerMode: 'static',
|
analyzerMode: 'static',
|
||||||
generateStatsFile: true,
|
generateStatsFile: true,
|
||||||
openAnalyzer: false,
|
openAnalyzer: false,
|
||||||
reportFilename: resolve(projectRoot, 'report', 'report.html'),
|
reportFilename: resolve(projectRoot, 'report', 'report.html'),
|
||||||
statsFilename: resolve(projectRoot, 'report', 'stats.json'),
|
statsFilename: resolve(projectRoot, 'report', 'stats.json'),
|
||||||
}]);
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import svelteNativePreprocessor from 'svelte-native-preprocessor';
|
|
||||||
import Config from 'webpack-chain';
|
import Config from 'webpack-chain';
|
||||||
|
|
||||||
import { getProjectRootPath } from '../helpers/project';
|
import { getProjectRootPath } from '../helpers/project';
|
||||||
import { env as _env, IWebpackEnv } from '../index';
|
|
||||||
import { getPlatformName } from '../helpers/platform';
|
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';
|
import base from './base';
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
||||||
import { relative, resolve } from 'path';
|
import { relative, resolve } from 'path';
|
||||||
import { env } from '..';
|
import Config from 'webpack-chain';
|
||||||
import { getEntryDirPath } from './platform';
|
|
||||||
import { getProjectRootPath } from './project';
|
import { getProjectRootPath } from './project';
|
||||||
|
import { getEntryDirPath } from './platform';
|
||||||
|
import { env } from '..';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -37,17 +39,28 @@ export function removeCopyRule(glob: string) {
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export function applyCopyRules(config) {
|
export function applyCopyRules(config: Config) {
|
||||||
|
const entryDir = getEntryDirPath();
|
||||||
|
// todo: handle empty appResourcesPath?
|
||||||
|
// (the CLI should always pass the path - maybe not required)
|
||||||
|
const appResourcesFullPath = resolve(
|
||||||
|
getProjectRootPath(),
|
||||||
|
env.appResourcesPath
|
||||||
|
);
|
||||||
|
|
||||||
|
const globOptions = {
|
||||||
|
dot: false,
|
||||||
|
ignore: [
|
||||||
|
// ignore everything in App_Resources (regardless where they are located)
|
||||||
|
`${relative(entryDir, appResourcesFullPath)}/**`,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
const context = getEntryDirPath();
|
|
||||||
const projectRoot = getProjectRootPath();
|
|
||||||
const appResourcesFullPath = resolve(projectRoot, env.appResourcesPath);
|
|
||||||
const globOptions = { dot: false, ignore: [`**/${relative(context, appResourcesFullPath)}/**`] };
|
|
||||||
config.plugin('CopyWebpackPlugin').use(CopyWebpackPlugin, [
|
config.plugin('CopyWebpackPlugin').use(CopyWebpackPlugin, [
|
||||||
{
|
{
|
||||||
patterns: Array.from(copyRules).map((glob) => ({
|
patterns: Array.from(copyRules).map((glob) => ({
|
||||||
from: glob,
|
from: glob,
|
||||||
context,
|
context: entryDir,
|
||||||
noErrorOnMissing: true,
|
noErrorOnMissing: true,
|
||||||
globOptions,
|
globOptions,
|
||||||
})),
|
})),
|
||||||
|
Reference in New Issue
Block a user