Skip to content
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"promise-polyfill": "^6.0.2",
"raw-loader": "^0.5.1",
"recursive-copy": "^2.0.6",
"require-relative": "^0.8.7",
"rimraf": "^2.6.1",
"script-ext-html-webpack-plugin": "^1.8.0",
"simplehttp2server": "^2.0.0",
Expand Down
10 changes: 9 additions & 1 deletion src/lib/webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ProgressBarPlugin from 'progress-bar-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import ReplacePlugin from 'webpack-plugin-replace';
import SWPrecacheWebpackPlugin from 'sw-precache-webpack-plugin';
import requireRelative from 'require-relative';
import createBabelConfig from './babel-config';
import prerender from './prerender';
import PushManifestPlugin from './push-manifest';
Expand All @@ -43,6 +44,13 @@ function readJson(file) {
}
readJson.cache = {};

// attempt to resolve a dependency, giving $CWD/node_modules priority:
function resolveDep(dep, cwd) {
try { return requireRelative.resolve(dep, cwd || process.cwd()); } catch (e) {}
try { return require.resolve(dep); } catch (e) {}
return dep;
}

export default env => {
let isProd = env && env.production;
let cwd = env.cwd = resolve(env.cwd || process.cwd());
Expand Down Expand Up @@ -77,7 +85,7 @@ export default env => {
'preact-cli-entrypoint': src('index.js'),
'preact-cli-polyfills': resolve(__dirname, 'polyfills.js'),
style: src('style'),
preact$: isProd ? 'preact/dist/preact.min.js' : 'preact',
preact$: resolveDep(isProd ? 'preact/dist/preact.min.js' : 'preact', env.cwd),
// preact-compat aliases for supporting React dependencies:
react: 'preact-compat',
'react-dom': 'preact-compat',
Expand Down