Skip to content

Commit

Permalink
Merge pull request preactjs#454 from jgierer12/fix-win32-paths
Browse files Browse the repository at this point in the history
Fix webpack config not matching win32 paths
  • Loading branch information
ForsakenHarmony authored Jan 27, 2018
2 parents 6460ab1 + a6608c1 commit e248bf0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/lib/webpack/webpack-client-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import SWPrecacheWebpackPlugin from 'sw-precache-webpack-plugin';
import RenderHTMLPlugin from './render-html-plugin';
import PushManifestPlugin from './push-manifest';
import baseConfig from './webpack-base-config';
import { normalizePath } from '../../util';

const cleanFilename = name => name.replace(/(^\/(routes|components\/(routes|async))\/|(\/index)?\.js$)/g, '');

function clientConfig(env) {
const { isProd, source, src /*, port? */ } = env;
Expand Down Expand Up @@ -52,15 +55,15 @@ function clientConfig(env) {
loader: resolve(__dirname, './async-component-loader'),
options: {
name(filename) {
let relative = filename.replace(src, '');
let isRoute = filename.indexOf('/routes/') >= 0;

return isRoute ? 'route-' + relative.replace(/(^\/(routes|components\/(routes|async))\/|(\/index)?\.js$)/g, '') : false;
filename = normalizePath(filename);
let relative = filename.replace(normalizePath(src), '');
if (!relative.includes('/routes/')) return false;
return 'route-' + cleanFilename(relative);
},
formatName(filename) {
let relative = filename.replace(source('.'), '');
// strip out context dir & any file/ext suffix
return relative.replace(/(^\/(routes|components\/(routes|async))\/|(\/index)?\.js$)/g, '');
filename = normalizePath(filename);
let relative = filename.replace(normalizePath(source('.')), '');
return cleanFilename(relative);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import chalk from 'chalk';
import { statSync, existsSync } from 'fs';
import logSymbols from 'log-symbols';
import which from 'which';
import { normalize } from 'path';

export function isDir(str) {
return existsSync(str) && statSync(str).isDirectory();
Expand Down Expand Up @@ -29,3 +30,7 @@ export function error(text, code) {
process.stderr.write(logSymbols.error + chalk.red(' ERROR ') + text + '\n');
code && process.exit(code);
}

export function normalizePath(path) {
return normalize(path).replace(/\\/g, '/');
}

0 comments on commit e248bf0

Please sign in to comment.