Skip to content

Commit

Permalink
separate hasMultiTargets & add extendLoader (electrode-io#1209)
Browse files Browse the repository at this point in the history
  • Loading branch information
1846689910 authored and jchip committed Apr 15, 2019
1 parent cbe0da0 commit 34382d2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ const babelConfigSpec = {
env: "ENV_TARGET",
type: "string",
default: "default"
},
// `extendLoader` is used to override `babel-loader` only when `hasMultiTargets=true`
extendLoader: {
type: "json",
default: {}
}
};

Expand Down Expand Up @@ -114,3 +119,7 @@ module.exports = Object.assign(
config,
xenvConfig(topConfigSpec, _.pick(userConfig, Object.keys(topConfigSpec)), { merge })
);
module.exports.babel.hasMultiTargets =
Object.keys(module.exports.babel.envTargets)
.sort()
.join(",") !== "default,node";
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ const plugins = basePlugins.concat(
);

const targets = archetype.babel.envTargets[archetype.babel.target];
const hasOtherTargets =
Object.keys(archetype.babel.envTargets)
.sort()
.join(",") !== "default,node";
const useBuiltIns = hasOtherTargets
const useBuiltIns = archetype.babel.hasMultiTargets
? { useBuiltIns: "entry", corejs: "2" }
: {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ module.exports = function(options) {

return {
module: {
rules: [assign({}, babelLoaderConfig, archetype.webpack.extendBabelLoader)]
rules: [
assign(
{},
babelLoaderConfig,
archetype.babel.hasMultiTargets ? archetype.babel.extendLoader : {}
)
]
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ const { AppMode, babel } = archetype;

const inspectpack = process.env.INSPECTPACK_DEBUG === "true";

const { target, envTargets } = babel;
const hasOtherTargets =
Object.keys(envTargets).filter(x => x !== "default" && x !== "node").length > 0;

const getOutputFilename = () => {
let filename = "[name].bundle.[hash].js";

if (AppMode.hasSubApps) {
filename = "[name].bundle.js";
} else if (hasOtherTargets) {
filename = `${target}.[name].bundle.js`;
} else if (babel.hasMultiTargets) {
filename = `${babel.target}.[name].bundle.js`;
}

return filename;
Expand All @@ -26,7 +22,7 @@ const getOutputPath = () => {
if (process.env.WEBPACK_DEV === "true") {
return "/"; // simulate the behavior of webpack-dev-server, which sets output path to /
} else {
return Path.resolve(target !== "default" ? `dist-${target}` : "dist", "js");
return Path.resolve(babel.target !== "default" ? `dist-${babel.target}` : "dist", "js");
}
};

Expand All @@ -35,7 +31,7 @@ module.exports = {
path: getOutputPath(),
pathinfo: inspectpack, // Enable path information for inspectpack
publicPath: "/js/",
chunkFilename: hasOtherTargets ? `${target}.[hash].[name].js` : "[hash].[name].js",
chunkFilename: babel.hasMultiTargets ? `${babel.target}.[hash].[name].js` : "[hash].[name].js",
filename: getOutputFilename()
}
};

0 comments on commit 34382d2

Please sign in to comment.