Skip to content

Conversation

mwistrand
Copy link
Contributor

Read, copy, and hash assets read from <img src>, <script src>, and <link href> tags in an application's index.html. Remote file paths and those beginning with / are ignored. Resources can still be read from the src/ directory, with the caveat that script and CSS files that have been parsed from index.html are treated as independent from the main build pipeline (e.g., a src/custom-styles.css file that's bundles with main.css but directly imported in src/index.html will result in an additional custom-styles.[hash].css being output).

Also updates the image loader to keep the original file name in hashed output.

Resolves #124

Parse `<img src>`, `<script src>`, and `<link href>` assets from
`src/index.html`. If the asset is not in the `/assets` directory, is not
a remote resource, and its file name does not begin with "/", then copy
it to the output and hash its file name.
@mwistrand mwistrand changed the base branch from master to next August 8, 2018 20:22
@codecov
Copy link

codecov bot commented Aug 8, 2018

Codecov Report

Merging #127 into next will decrease coverage by 0.04%.
The diff coverage is 25%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next     #127      +/-   ##
==========================================
- Coverage   59.76%   59.71%   -0.05%     
==========================================
  Files           8        8              
  Lines         425      427       +2     
  Branches       93       91       -2     
==========================================
+ Hits          254      255       +1     
- Misses        171      172       +1
Impacted Files Coverage Δ
src/base.config.ts 28.57% <25%> (+0.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e1cd821...b6e0606. Read the comment docs.

@@ -336,7 +365,7 @@ export default function webpackConfigFactory(args: any): WebpackConfiguration {
include: allPaths,
test: /\.css$/,
exclude: /\.m\.css$/,
use: cssLoader
oneOf: [{ issuer: indexHtmlPattern, use: 'identity-loader' }, { use: cssLoader }]
Copy link
Contributor

Choose a reason for hiding this comment

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

although this works and is neat (conditionally applying a loader on issuer), we need to fix these loader paths unrelated to the PR anyway as we shouldn’t be processing modules outside of src or test regardless of issuer. We currently have side effects elsewhere due to this (ie we are processing external/node_modules css through these loaders).

@mwistrand
Copy link
Contributor Author

@matt-gadd I updated the include rules for each loader and tested the changes locally with a sandbox app that imports reset-css and bootstrap from node modules, todo-mvc-kitchensink, and hnpwa. We still need the identity-loader to not process CSS that's loaded from index.html, though.

@mwistrand mwistrand merged commit 7518ec0 into dojo:next Aug 9, 2018
mwistrand added a commit to mwistrand/cli-build-app that referenced this pull request Aug 13, 2018
- Parse, copy, and hash `<img src>`, `<script src>`, and `<link href>`
   assets from `src/index.html`.
- Update the CSS rules to limit processing to the `src/` and `tests/`
   directories.
- Ignore all assets imported from the `assets/` directory.
- Change Dojo 2 to Dojo in README.md.
- Add the `ico` extension to the images rule.
mwistrand added a commit to mwistrand/cli-build-app that referenced this pull request Aug 13, 2018
- Parse, copy, and hash `<img src>`, `<script src>`, and `<link href>`
   assets from `src/index.html`.
- Update the CSS rules to limit processing to the `src/` and `tests/`
   directories.
- Ignore all assets imported from the `assets/` directory.
- Change Dojo 2 to Dojo in README.md.
- Add the `ico` extension to the images rule.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants