-
Notifications
You must be signed in to change notification settings - Fork 12k
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
ServerBuilder: allow to configure file-loader option emitFile #12878
Labels
area: @angular-devkit/build-angular
freq1: low
Only reported by a handful of users who observe it rarely
severity2: inconvenient
type: bug/fix
Milestone
Comments
alan-agius4
added
the
freq1: low
Only reported by a handful of users who observe it rarely
label
Nov 7, 2018
Patch example which implements server builder option diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/models/build-options.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/models/build-options.ts
index 5a33f1e3..84b1cb98 100644
--- a/packages/angular_devkit/build_angular/src/angular-cli-files/models/build-options.ts
+++ b/packages/angular_devkit/build_angular/src/angular-cli-files/models/build-options.ts
@@ -65,6 +65,7 @@ export interface BuildOptions {
lazyModules: string[];
platform?: 'browser' | 'server';
fileReplacements: CurrentFileReplacement[];
+ fileLoaderEmitFile?: boolean;
}
export interface WebpackTestOptions extends BuildOptions {
diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts
index 699dafdb..dd1b1323 100644
--- a/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts
+++ b/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts
@@ -270,6 +270,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
loader: 'file-loader',
options: {
name: `[name]${hashFormat.file}.[ext]`,
+ emitFile: 'fileLoaderEmitFile' in buildOptions ? buildOptions.fileLoaderEmitFile : true,
},
},
{
diff --git a/packages/angular_devkit/build_angular/src/server/schema.d.ts b/packages/angular_devkit/build_angular/src/server/schema.d.ts
index 24b57542..5bfd94fb 100644
--- a/packages/angular_devkit/build_angular/src/server/schema.d.ts
+++ b/packages/angular_devkit/build_angular/src/server/schema.d.ts
@@ -132,6 +132,11 @@ export interface BuildWebpackServerSchema {
* Enable and define the file watching poll time period in milliseconds.
*/
poll?: number;
+ /**
+ * Enable emit files from the file-loader. If false, the file-loader will return
+ * a public URI but will not emit files.
+ */
+ fileLoaderEmitFile?: boolean;
}
/**
diff --git a/packages/angular_devkit/build_angular/src/server/schema.json b/packages/angular_devkit/build_angular/src/server/schema.json
index 119d4909..30bd5045 100644
--- a/packages/angular_devkit/build_angular/src/server/schema.json
+++ b/packages/angular_devkit/build_angular/src/server/schema.json
@@ -169,6 +169,11 @@
"poll": {
"type": "number",
"description": "Enable and define the file watching poll time period in milliseconds."
+ },
+ "fileLoaderEmitFile": {
+ "type": "boolean",
+ "description": "Enable emit files from the file-loader. If false, the file-loader will return a public URI but will not emit files.",
+ "default": true
}
},
"additionalProperties": false,
|
This was referenced Oct 28, 2019
vikerman
pushed a commit
that referenced
this issue
Oct 30, 2019
… server build The server should serve the assets emitted by the browser builder. In fact the nguniversal schematics are configured to serve the assets from the browser folder https://github.com/angular/universal/blob/a0cc9ab97a70370eff872664ac46391a193aa45e/modules/express-engine/schematics/install/files/__serverFileName%40stripTsExtension__.ts#L26 Closes #12878
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
area: @angular-devkit/build-angular
freq1: low
Only reported by a handful of users who observe it rarely
severity2: inconvenient
type: bug/fix
Bug Report or Feature Request (mark with an
x
)Command (mark with an
x
)Versions
Repro steps
The main purpose is to build an universal angular application.
To achieve that we need two projects:
@angular-devkit/build-angular:browser
builder to create a bundle which will run in browser for client side rendering (more often called single page application) ;@angular-devkit/build-angular:server
builder to create a bundle which will run in server with nodejs for server side rendering.In addition, the bundle server serves statically the bundle browser assets.
The
angular.json
below show how to configure the build of the both bundles.That works as expected and we can run our universal angular application.
But the bundle server includes every assets emitted by the file-loader which is common to the both webpack configs generated dynamically.
We doesn't need (and doesn't use/serve) that server assets because there are already present in the bundle browser: we can remove them and our application still works well.
The log given by the failure
Below, that is the tree of the dist folder after build browser and server bundles for production.
We can notice that
foo-img.[hash].png
exists in bothbrowser
andserver
folders because we import and use this image inapp.component.ts
.Desired functionality
I think the architect server builder needs a new option which can set the file-loader option
emitFile
tofalse
.How about flag
fileLoaderEmitFile
which istrue
by default?"server": { "builder": "@angular-devkit/build-angular:server", "options": { "outputPath": "dist/app/server", "main": "src/main.server.ts", "tsConfig": "src/tsconfig.server.json", + "fileLoaderEmitFile": false }, "configurations": { "production": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "outputHashing": "media" } } },
Mention any other details that might be useful
In my opinion, some other file-loader options can be useful as
outputPath
.But the
emitFile
option is required to optimize building.The text was updated successfully, but these errors were encountered: