Skip to content

Make images smaller using best-in-class codecs, right in the browser.

JavaScript

Fixing windows build (#849)

Jake Archibald30b628c1b92d
diff --git a/lib/client-bundle-plugin.js b/lib/client-bundle-plugin.js
index b798b4da..5b73e40b 100644
--- a/lib/client-bundle-plugin.js
+++ b/lib/client-bundle-plugin.js
@@ -11,6 +11,7 @@
* limitations under the License.
*/
import rollup from 'rollup';
+import * as path from 'path';
const prefix = 'client-bundle:';
const entryPathPlaceholder = 'CLIENT_BUNDLE_PLUGIN_ENTRY_PATH';
@@ -119,9 +120,10 @@ export default function (inputOptions, outputOptions, resolveFileUrl) {
return;
}
- const id = entryPointPlaceholderMap.get(num);
+ const id = path.normalize(entryPointPlaceholderMap.get(num));
const clientEntry = clientOutput.find(
- (item) => item.facadeModuleId === id,
+ (item) =>
+ item.facadeModuleId && path.normalize(item.facadeModuleId) === id,
);
if (property.startsWith(entryPathPlaceholder)) {
diff --git a/lib/css-plugin.js b/lib/css-plugin.js
index 7bee09b2..1e1ba6d1 100644
--- a/lib/css-plugin.js
+++ b/lib/css-plugin.js
@@ -18,6 +18,8 @@ import {
resolve as resolvePath,
dirname,
normalize as nomalizePath,
+ sep as pathSep,
+ posix,
} from 'path';
import postcss from 'postcss';
@@ -172,14 +174,15 @@ export default function (resolveFileUrl) {
return `export default ${cssStr};`;
}
if (id.startsWith(addPrefix)) {
- const path = id.slice(addPrefix.length);
+ const path = nomalizePath(id.slice(addPrefix.length));
return (
- `import css from 'css:${path}';\n` +
+ `import css from ${JSON.stringify('css:' + path)};\n` +
`import appendCss from '${appendCssModule}';\n` +
`appendCss(css);\n`
);
}
if (id.endsWith(moduleSuffix)) {
+ const path = nomalizePath(id.slice(0, -moduleSuffix.length));
if (!pathToResult.has(id)) {
throw Error(`Cannot find ${id} in pathToResult`);
}
diff --git a/lib/initial-css-plugin.js b/lib/initial-css-plugin.js
index c01b8f65..055a2740 100644
--- a/lib/initial-css-plugin.js
+++ b/lib/initial-css-plugin.js
@@ -19,15 +19,16 @@ import glob from 'glob';
const globP = promisify(glob);
const moduleId = 'initial-css:';
+const initialCssModule = '\0initialCss';
export default function initialCssPlugin() {
return {
name: 'initial-css-plugin',
resolveId(id) {
- if (id === moduleId) return moduleId;
+ if (id === moduleId) return initialCssModule;
},
async load(id) {
- if (id !== moduleId) return;
+ if (id !== initialCssModule) return;
const matches = await globP('shared/initial-app/**/*.css', {
nodir: true,
diff --git a/lib/resolve-dirs-plugin.js b/lib/resolve-dirs-plugin.js
index 24354741..2479c087 100644
--- a/lib/resolve-dirs-plugin.js
+++ b/lib/resolve-dirs-plugin.js
@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import { posix as pathUtils } from 'path';
+import { posix as pathUtils, isAbsolute } from 'path';
export default function resolveDirs(paths) {
const pathBaseDir = paths.map((path) => [
@@ -30,6 +30,7 @@ export default function resolveDirs(paths) {
if (!resolveResult) {
throw new Error(`Couldn't find ${'./' + id}`);
}
+ if (isAbsolute(resolveResult.id)) return resolveResult.id;
return pathUtils.resolve(resolveResult.id);
},
};
diff --git a/lib/simple-ts.js b/lib/simple-ts.js
index 758e0e3a..93d04d1e 100644
--- a/lib/simple-ts.js
+++ b/lib/simple-ts.js
@@ -127,15 +127,6 @@ export default function simpleTS(mainPath, { noBuild, watch } = {}) {
relative(process.cwd(), id),
).replace(extRe, '.js');
- console.log(
- `simple-ts mapping`,
- id,
- 'to',
- newId,
- 'with outDir',
- config.options.outDir,
- );
-
return fsp.readFile(newId, { encoding: 'utf8' });
},
};
diff --git a/rollup.config.js b/rollup.config.js
index 29ccc638..9b5b4ead 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -52,7 +52,7 @@ function jsFileName(chunkInfo) {
const parsedPath = path.parse(chunkInfo.facadeModuleId);
if (parsedPath.name !== 'index') return jsPath;
// Come up with a better name than 'index'
- const name = parsedPath.dir.split('/').slice(-1);
+ const name = parsedPath.dir.split(/\\|\//).slice(-1);
return jsPath.replace('[name]', name);
}