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

[assets] Adds support for publicPath to enable serving assets from different locations. #280

Closed
wants to merge 1 commit into from
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
1 change: 1 addition & 0 deletions packages/metro-config/src/defaults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({
postMinifyProcess: x => x,
transformVariants: {default: {}},
workerPath: 'metro/src/DeltaBundler/Worker',
publicPath: '/assets',
},
cacheStores: [
new FileStore({
Expand Down
3 changes: 2 additions & 1 deletion packages/metro/src/Assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ async function getAssetData(
localPath: string,
assetDataPlugins: $ReadOnlyArray<string>,
platform: ?string = null,
publicPath: ?string = '/assets',
): Promise<AssetData> {
let assetUrlPath = path.join('/assets', path.dirname(localPath));
let assetUrlPath = `${publicPath}/${path.dirname(localPath)}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is causing the end to end snapshot tests to fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I haven't addressed any tests yet, I need to get around the Server assumptions, but I'm not sure how to handle that.


// On Windows, change backslashes to slashes to get proper URL path from file path.
if (path.sep === '\\') {
Expand Down
1 change: 1 addition & 0 deletions packages/metro/src/DeltaBundler/Transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Transformer {
enableBabelRCLookup: this._config.transformer.enableBabelRCLookup,
minifierPath: this._config.transformer.minifierPath,
optimizationSizeLimit: this._config.transformer.optimizationSizeLimit,
publicPath: this._config.transformer.publicPath,
},
};

Expand Down
2 changes: 2 additions & 0 deletions packages/metro/src/JSTransformer/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export type JsTransformerConfig = {|
+enableBabelRCLookup: boolean,
+minifierPath: string,
+optimizationSizeLimit: number,
+publicPath: string,
|};

export type CustomTransformOptions = {[string]: mixed, __proto__: null};
Expand Down Expand Up @@ -179,6 +180,7 @@ class JsTransformer {
// is used by other tooling, and this would affect it.
inlineRequires: false,
projectRoot: this._projectRoot,
publicPath: this._config.publicPath,
},
plugins: [],
src: sourceCode,
Expand Down
1 change: 1 addition & 0 deletions packages/metro/src/assetTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async function transform(
filename,
assetDataPlugins,
options.platform,
options.publicPath,
);

return {
Expand Down