Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack updates #1120

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,7 @@ module.exports = function babelConfig(api) {
"lodash"
];
if (api.env("development")) {
if (process.env.BABEL_EXTENSION_PATH && !process.env.BABEL_EXTENSION_PATH.includes(__dirname)) {
utils.verbose("Not using react-hot-loader/babel plugin with auspice extensions as this produces an error. TO FIX.");
/* with extensions from a dir not within the main auspice directory we get the error:
* Module not found: Error: Can't resolve 'react-hot-loader' in ...extension directory...
* Which I can't fix. Tried:
* require.resolve("react-hot-loader/babel")
* setting babelrcRoots
* but google seems to have failed me.
* It may be a bug with "react-hot-loader/babel" as the other plugins work just fine!
*/
} else {
plugins.push("react-hot-loader/babel");
}
plugins.push("react-hot-loader/babel");
}
if (process.env.BABEL_INCLUDE_TIMING_FUNCTIONS === "false") {
plugins.push(["strip-function-call", {strip: ["timerStart", "timerEnd"]}]);
Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@babel/preset-env": "^7.3.4",
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.8.7",
"@hot-loader/react-dom": "^16.13.0",
"argparse": "^1.0.10",
"awesomplete": "^1.1.2",
"babel-eslint": "^10.0.1",
Expand Down
40 changes: 30 additions & 10 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,37 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
/* which directories should be parsed by babel and other loaders? */
const directoriesToTransform = [path.join(__dirname, 'src')];

// Pins all react stuff, and uses hot loader's dom (can be used safely in production)
// Format is either "libName" or "libName:libPath"
const coreDeps = [
"react",
"react-hot-loader",
"react-dom"
];

// Actively searches for the "good" root starting from auspice dir and going backwards
let baseDir = __dirname;
let foundNodeModules = false;
while (!foundNodeModules) {
foundNodeModules = true;
for (const coreDep of coreDeps) {
const modulePath = path.join(baseDir, "node_modules", coreDep.split(":")[1] || coreDep);
foundNodeModules = foundNodeModules && fs.existsSync(modulePath);
}
baseDir = foundNodeModules ? baseDir : path.resolve(baseDir, "..");
}
const libDir = path.join(baseDir, "node_modules");

/* webpack alias' used in code import / require statements */
const aliasesToResolve = {
"@extensions": '.', /* must provide a default, else it won't compile */
"@auspice": path.join(__dirname, 'src'),
"@libraries": path.join(__dirname, 'node_modules')
"@libraries": libDir
};
for (const coreDep of coreDeps) {
const modParts = coreDep.split(":");
aliasesToResolve[modParts[0] || coreDep] = path.join(libDir, modParts[1] || coreDep);
}

let extensionData;
if (extensionPath) {
Expand Down Expand Up @@ -63,13 +88,7 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
plugins.push(new BundleAnalyzerPlugin());
}

const entry = [
"babel-polyfill",
"./src/index"
];
if (devMode) {
entry.splice(1, 0, "webpack-hot-middleware/client");
}
const entry = [...(devMode ? ["webpack-hot-middleware/client"] : []), "babel-polyfill", "./src/index"];

/* Where do we want the output to be saved?
* For development we use the (virtual) "devel" directory
Expand All @@ -85,6 +104,8 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
const config = {
mode: devMode ? 'development' : 'production',
context: __dirname,
// Better to get a proper full source map in dev mode, this one is pretty fast on rebuild
devtool: !devMode ? undefined : "eval-source-map",
entry,
output: {
path: outputPath,
Expand All @@ -93,6 +114,7 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
publicPath: "/dist/"
},
resolve: {
mainFields: ['browser', 'main', 'module'],
alias: aliasesToResolve
},
node: {
Expand Down Expand Up @@ -124,8 +146,6 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
}
};

config.devtool = 'cheap-module-source-map';

return config;
};

Expand Down