Skip to content

Commit

Permalink
Merge pull request #5 from crubier/patch-1
Browse files Browse the repository at this point in the history
Support PnP in 4 combinations of configurations
  • Loading branch information
rot1024 committed May 27, 2019
2 parents 3cf1aa1 + 146dc6b commit 14893d6
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions index.js
Expand Up @@ -5,8 +5,30 @@ const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackIncludeAssetPlugin = require("html-webpack-include-assets-plugin");

const cesiumSource = "node_modules/cesium/Source";
const cesiumWorkers = "../Build/Cesium/Workers";
let pnp;

try {
pnp = require(`pnpapi`);
} catch (error) {
// not in PnP; not a problem
}

let cesiumSource;

if (pnp) {
// console.log("Craco Cesium using Pnp");
const topLevelLocation = pnp.getPackageInformation(pnp.topLevel)
.packageLocation;
cesiumSource = path.resolve(
pnp.resolveToUnqualified("cesium", topLevelLocation, {
considerBuiltins: false
}),
"Source"
);
} else {
// console.log("Craco Cesium using normal module");
cesiumSource = path.resolve(__dirname, "node_modules/cesium/Source");
}

module.exports = (
{ loadPartially, loadCSSinHTML } = {
Expand All @@ -25,7 +47,7 @@ module.exports = (
webpackConfig.module.push({
test: /.js$/,
enforce: "pre",
include: path.resolve(__dirname, cesiumSource),
include: cesiumSource,
use: [
{
loader: "strip-pragma-loader",
Expand All @@ -48,15 +70,15 @@ module.exports = (
webpackConfig.plugins.push(
new CopyWebpackPlugin([
{
from: path.join(cesiumSource, cesiumWorkers),
from: path.resolve(cesiumSource, "../Build/Cesium/Workers"),
to: "cesium/Workers"
},
{
from: path.join(cesiumSource, "Assets"),
from: path.resolve(cesiumSource, "Assets"),
to: "cesium/Assets"
},
{
from: path.join(cesiumSource, "Widgets"),
from: path.resolve(cesiumSource, "Widgets"),
to: "cesium/Widgets"
}
]),
Expand Down Expand Up @@ -96,7 +118,10 @@ module.exports = (
webpackConfig.plugins.push(
new CopyWebpackPlugin([
{
from: `node_modules/cesium/Build/Cesium${prod ? "" : "Unminified"}`,
from: path.resolve(
cesiumSource,
`../Build/Cesium${prod ? "" : "Unminified"}`
),
to: "cesium"
}
]),
Expand Down

0 comments on commit 14893d6

Please sign in to comment.