mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
feat: sourceMap improvements
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import {
|
||||
import webpack, {
|
||||
ContextExclusionPlugin,
|
||||
DefinePlugin,
|
||||
HotModuleReplacementPlugin,
|
||||
@ -44,8 +44,30 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
// resolved at runtime
|
||||
config.externals(['package.json', '~/package.json']);
|
||||
|
||||
// todo: devtool
|
||||
config.devtool('inline-source-map');
|
||||
const getSourceMapType = (map: string | boolean): Config.DevTool => {
|
||||
const defaultSourceMap = 'inline-source-map';
|
||||
|
||||
if (typeof map === 'undefined') {
|
||||
// source-maps disabled in production by default
|
||||
// enabled with --env.sourceMap=<type>
|
||||
if (mode === 'production') {
|
||||
// todo: we may set up SourceMapDevToolPlugin to generate external maps in production
|
||||
return false;
|
||||
}
|
||||
|
||||
return defaultSourceMap;
|
||||
}
|
||||
|
||||
// when --env.sourceMap=true is passed, use default
|
||||
if (typeof map === 'boolean' && map) {
|
||||
return defaultSourceMap;
|
||||
}
|
||||
|
||||
// pass any type of sourceMap with --env.sourceMap=<type>
|
||||
return map as Config.DevTool;
|
||||
};
|
||||
|
||||
config.devtool(getSourceMapType(env.sourceMap));
|
||||
|
||||
// todo: figure out easiest way to make "node" target work in ns
|
||||
// rather than the custom ns target implementation that's hard to maintain
|
||||
|
@ -2,7 +2,9 @@
|
||||
// This must be at the top BEFORE webpack is loaded so that we can extend
|
||||
// and replace the parser before webpack uses it
|
||||
// Based on the issue: https://github.com/webpack/webpack/issues/10216
|
||||
const stage3 = require('acorn-stage3');
|
||||
import stage3 from 'acorn-stage3';
|
||||
|
||||
// we use require to be able to override the exports
|
||||
const acorn = require('acorn');
|
||||
acorn.Parser = acorn.Parser.extend(stage3);
|
||||
|
||||
@ -33,6 +35,7 @@ export interface IWebpackEnv {
|
||||
// for custom platforms
|
||||
platform?: string;
|
||||
|
||||
sourceMap?: string | boolean;
|
||||
production?: boolean;
|
||||
report?: boolean;
|
||||
hmr?: boolean;
|
||||
|
Reference in New Issue
Block a user