-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Adds webpack-utils package; a fabric-optimized async loader #5122
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
Changes from 5 commits
d572361
7e503b1
02a2582
ddf8717
7456d77
dd239ec
13faf8a
2db5bd7
35c29f4
4098e70
4bb196a
ce9c73f
5861cb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@uifabric/webpack-utils", | ||
| "comment": "Creates a new webpack-utils package", | ||
| "type": "major" | ||
| } | ||
| ], | ||
| "packageName": "@uifabric/webpack-utils", | ||
| "email": "kchau@microsoft.com" | ||
| } | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| *.config.js | ||
| *.nuspec | ||
| *.yml | ||
| *.test.* | ||
| .editorconfig | ||
| .gitattributes | ||
| .gitignore | ||
| .vscode | ||
| coverage | ||
| dist/*.stats.html | ||
| dist/demo*.* | ||
| gulpfile.js | ||
| index.html | ||
| jsconfig.json | ||
| karma.config.js | ||
| node_modules | ||
| src | ||
| tsconfig.json | ||
| tsd.json | ||
| tslint.json | ||
| typings | ||
| webpack.config.js |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| registry=https://registry.npmjs.org/ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this the default? If so, do we need this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh wow, I keep copying stuff that I don't really need! |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| Office UI Fabric React - utilities | ||
|
|
||
| Copyright (c) Microsoft Corporation | ||
|
|
||
| All rights reserved. | ||
|
|
||
| MIT License | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
|
||
| Note: Usage of the fonts and icons referenced in Office UI Fabric is subject to the terms listed at http://aka.ms/fabric-assets-license |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Office UI Fabric React - Webpack utilities | ||
| This package contains different utilities for optimizing the use of Office UI Fabric React for the [Webpack](https://webpack.js.org) bundler. | ||
|
|
||
| ## Installation | ||
| To use any of these Webpack utilities, you must install it into your project: | ||
|
|
||
| `npm i -D @uifabric/webpack-utils` | ||
|
|
||
| or | ||
|
|
||
| `yarn add -D @uifabric/webpack-utils` | ||
|
|
||
|
|
||
| ## Fabric Async Loader | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super cool! :D
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| This is a Webpack loader that will automatically perform code splitting with no code changes needed on the Fabric or the application side. It accomplishes this through the Webpack loader mechanism filtered through the `include` property. To use this, modify your `webpack.config.js` like so: | ||
|
|
||
| ```js | ||
| module.exports = { | ||
| ..., | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.(jsx?|tsx?)$/, | ||
| include: [/office-ui-fabric-react\/lib(-commonjs)?\/components\/ContextualMenu\/ContextualMenu.js/], | ||
| loader: '@uifabric/webpack-utils/lib/FabricAsyncLoader.js' | ||
| }, | ||
| ... | ||
| } | ||
| }; | ||
| ``` | ||
|
|
||
| ### Credits | ||
| Thanks to: | ||
| * [react-loadable](https://github.com/jamiebuilds/react-loadable) by @jamiebuilds who created a delay loaded component | ||
| * [react-loadable-loader](https://github.com/baflo/react-loadable-loader) by @baflo who inspired this project; Fabric modified that implementation to work with non-default exports | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. API extractor isn't currently running and besides the entries in here are wrong.. :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The build script is geared towards building lib and lib-commonjs which isn't desired in webpack utils
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I will delete this file then. |
||
| "enabled": true, | ||
| "apiReviewFolder": "./api", | ||
| "apiJsonFolder": "./temp", | ||
| "entry": "src/index.ts" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /** Jest test setup file. */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| let path = require('path'); | ||
| let { createConfig } = require('../../scripts/tasks/jest-resources'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both of these can be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes - again, copied from utilities :) |
||
| module.exports = createConfig({ | ||
| setupFiles: [path.resolve(path.join(__dirname, 'config', 'tests.js'))] | ||
| }); | ||
|
|
||
| console.log(module.exports.setupFiles); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "name": "@uifabric/webpack-utils", | ||
| "version": "1.0.0", | ||
| "description": "Office UI Fabric utilities for Webpack bundler.", | ||
| "sideEffects": false, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/OfficeDev/office-ui-fabric-react" | ||
| }, | ||
| "license": "MIT", | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "code-style": "node ../../scripts/code-style.js", | ||
| "clean": "node ../../scripts/clean.js" | ||
| }, | ||
| "disabledTasks": [ | ||
| "copy", | ||
| "karma", | ||
| "webpack" | ||
| ], | ||
| "devDependencies": { | ||
| "@types/jest": "23.0.0", | ||
| "@types/loader-utils": "1.1.3", | ||
| "@types/webpack": "4.4.0", | ||
| "office-ui-fabric-react-tslint": ">=6.0.0 <7.0.0", | ||
| "webpack": ">=4.0.0" | ||
| }, | ||
| "dependencies": { | ||
| "loader-utils": "^1.1.0", | ||
| "tslib": "^1.7.1" | ||
| }, | ||
| "peerDependencies": { | ||
| "webpack": ">=4.0.0", | ||
| "react-loadable": ">=5.0.0" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // This code is heavily inspired by https://github.com/baflo/react-loadable-loader. | ||
| import * as webpack from 'webpack'; | ||
| import * as path from 'path'; | ||
| import * as loaderUtils from 'loader-utils'; | ||
|
|
||
| const fabricAsyncLoader: webpack.loader.Loader = (content: string) => { | ||
| return content; | ||
| }; | ||
|
|
||
| fabricAsyncLoader.pitch = (remainingRequest: string, precedingRequest: string) => { | ||
| const moduleRequest = `!!${remainingRequest}`; | ||
| const normalizedRequest = loaderUtils.stringifyRequest(this, moduleRequest); | ||
| const moduleName = path.basename(normalizedRequest).replace(/\..*$/, ''); | ||
| return [ | ||
| "import Loadable from 'react-loadable';", | ||
| `export const ${moduleName} = Loadable({`, | ||
| ` loader: async() => (await import(${loaderUtils.stringifyRequest(this, moduleRequest)})).${moduleName},`, | ||
| ` loading: () => null`, | ||
| `});` | ||
| ].join(''); | ||
| }; | ||
|
|
||
| export = fabricAsyncLoader; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add documentation to this file and also just use es6 syntax please :) (be consistent with rest of repo)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't use es6 syntax. Loaders need to be exported this way. I can add a little bit of doc but this loader doesn't do much yet (if ever?)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doc added
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had thought though that the .ts file is not used as the loader immediately, and in the compilation to js, this will turn into commonjs syntax and thereby become compatible...? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "es5", | ||
| "outDir": "lib", | ||
| "module": "commonjs", | ||
| "lib": [ | ||
| "es2017", | ||
| "dom" | ||
| ], | ||
| "jsx": "react", | ||
| "declaration": true, | ||
| "sourceMap": true, | ||
| "experimentalDecorators": true, | ||
| "importHelpers": true, | ||
| "noImplicitAny": true, | ||
| "strictNullChecks": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "moduleResolution": "node", | ||
| "preserveConstEnums": true, | ||
| }, | ||
| "include": [ | ||
| "src" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "extends": ["office-ui-fabric-react-tslint"], | ||
| "rules": { | ||
| "deprecation": false, | ||
| "prefer-const": false | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this turned off? :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just copied from utilities :P |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your first version published is going to be 2.0.0...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah maybe update the version to a 0, and do minor bumps until you're ready to do 1.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cranked it down to 0.0.1 with a minor change file