mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 13:51:27 +08:00
feat: external config loading
+refactor many pieces
This commit is contained in:

committed by
Nathan Walker

parent
04d989c2e6
commit
575130c712
@ -1,10 +1,8 @@
|
||||
import Config from 'webpack-chain';
|
||||
import { IWebpackEnv, Platform } from '../index';
|
||||
import { IWebpackEnv } from '../index';
|
||||
import {
|
||||
getAbsoluteDistPath,
|
||||
getDistPath,
|
||||
getEntryPath,
|
||||
getPackageJson,
|
||||
getPlatform,
|
||||
} from '../helpers/project';
|
||||
|
||||
@ -17,19 +15,21 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
|
||||
export default function (config: Config, env: IWebpackEnv): Config {
|
||||
const entryPath = getEntryPath();
|
||||
const platform = getPlatform();
|
||||
const packageJson = getPackageJson();
|
||||
const mode = env.production ? 'production' : 'development';
|
||||
|
||||
// set mode
|
||||
config.mode(mode);
|
||||
|
||||
// package.json is generated by the CLI with runtime options
|
||||
// this ensures it's not included in the bundle
|
||||
config.externals(['package.json']);
|
||||
|
||||
// todo: devtool
|
||||
config.devtool('inline-source-map');
|
||||
|
||||
// todo: figure out easiest way to make "node" target work in ns,
|
||||
// todo: figure out easiest way to make "node" target work in ns
|
||||
// rather than the custom ns target implementation that's hard to maintain
|
||||
// appears to be working - but we still have to deal with HMR
|
||||
config.target('node');
|
||||
|
||||
config.entry('bundle').add(entryPath);
|
||||
@ -62,11 +62,6 @@ export default function (config: Config, env: IWebpackEnv): Config {
|
||||
priority: -10,
|
||||
name: 'vendor',
|
||||
chunks: 'all',
|
||||
// test: (module) => {
|
||||
// const moduleName = module.nameForCondition ? module.nameForCondition() : '';
|
||||
// return /[\\/]node_modules[\\/]/.test(moduleName);
|
||||
// },
|
||||
// enforce: true
|
||||
},
|
||||
},
|
||||
});
|
||||
@ -74,6 +69,7 @@ export default function (config: Config, env: IWebpackEnv): Config {
|
||||
// look for loaders in
|
||||
// - node_modules/@nativescript/webpack/dist/loaders
|
||||
// - node_modules
|
||||
// allows for cleaner rules, without having to specify full paths to loaders
|
||||
config.resolveLoader.modules
|
||||
.add('node_modules/@nativescript/webpack/dist/loaders')
|
||||
.add('node_modules');
|
||||
@ -149,6 +145,9 @@ export default function (config: Config, env: IWebpackEnv): Config {
|
||||
config.module
|
||||
.rule('scss')
|
||||
.test(/\.scss$/)
|
||||
.use('apply-css-loader')
|
||||
.loader('apply-css-loader')
|
||||
.end()
|
||||
.use('css2json-loader')
|
||||
.loader('css2json-loader')
|
||||
.end()
|
||||
@ -159,18 +158,22 @@ export default function (config: Config, env: IWebpackEnv): Config {
|
||||
config.plugin('CleanWebpackPlugin').use(CleanWebpackPlugin, [
|
||||
{
|
||||
cleanOnceBeforeBuildPatterns: [`${getAbsoluteDistPath()}/**/*`],
|
||||
verbose: true,
|
||||
verbose: !!env.verbose,
|
||||
},
|
||||
]);
|
||||
|
||||
// todo: refine defaults
|
||||
config.plugin('DefinePlugin').use(DefinePlugin, [
|
||||
{
|
||||
'global.NS_WEBPACK': true,
|
||||
'global.isAndroid': platform === 'android',
|
||||
'global.isIOS': platform === 'ios',
|
||||
__DEV__: mode === 'development',
|
||||
__NS_WEBPACK__: true,
|
||||
__CSS_PARSER__: JSON.stringify('css-tree'), // todo: replace from config value
|
||||
__ANDROID__: platform === 'android',
|
||||
__IOS__: platform === 'ios',
|
||||
/* for compat only */ 'global.isAndroid': platform === 'android',
|
||||
/* for compat only */ 'global.isIOS': platform === 'ios',
|
||||
process: 'global.process',
|
||||
profile: '() => {}',
|
||||
/* todo: remove if fixed in core? */ profile: '() => {}',
|
||||
},
|
||||
]);
|
||||
|
||||
@ -183,6 +186,7 @@ export default function (config: Config, env: IWebpackEnv): Config {
|
||||
// },
|
||||
// ]);
|
||||
|
||||
// todo: make opt-in with a flag
|
||||
config.plugin('BundleAnalyzerPlugin').use(BundleAnalyzerPlugin);
|
||||
|
||||
// add the WatchStateLogger plugin used to notify the CLI of build state
|
||||
|
Reference in New Issue
Block a user