Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
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"

Copy link
Copy Markdown
Contributor

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...

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Copy Markdown
Contributor Author

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

}
],
"packageName": "@uifabric/webpack-utils",
"email": "kchau@microsoft.com"
}
1,466 changes: 746 additions & 720 deletions common/config/rush/npm-shrinkwrap.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions packages/webpack-utils/.npmignore
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
2 changes: 2 additions & 0 deletions packages/webpack-utils/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
registry=https://registry.npmjs.org/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this the default? If so, do we need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh wow, I keep copying stuff that I don't really need!


15 changes: 15 additions & 0 deletions packages/webpack-utils/LICENSE
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
35 changes: 35 additions & 0 deletions packages/webpack-utils/README.md
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Super cool! :D

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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
6 changes: 6 additions & 0 deletions packages/webpack-utils/config/api-extractor.json.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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"
}
1 change: 1 addition & 0 deletions packages/webpack-utils/config/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** Jest test setup file. */
7 changes: 7 additions & 0 deletions packages/webpack-utils/jest.config.js
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');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Both of these can be consts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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);
36 changes: 36 additions & 0 deletions packages/webpack-utils/package.json
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"
}
}
23 changes: 23 additions & 0 deletions packages/webpack-utils/src/fabricAsyncLoader.ts
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

doc added

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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...?

24 changes: 24 additions & 0 deletions packages/webpack-utils/tsconfig.json
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"
]
}
7 changes: 7 additions & 0 deletions packages/webpack-utils/tslint.json
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this turned off? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just copied from utilities :P

}
}
16 changes: 13 additions & 3 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"versionPolicyName": "lockedMajor",
"shouldPublish": true
},
{
"packageName": "@uifabric/webpack-utils",
"projectFolder": "packages/webpack-utils",
"shouldPublish": true
},
{
"packageName": "@uifabric/experiments",
"projectFolder": "packages/experiments",
Expand Down Expand Up @@ -46,14 +51,19 @@
"packageName": "@uifabric/example-app-base",
"projectFolder": "packages/example-app-base",
"versionPolicyName": "lockedMajor",
"cyclicDependencyProjects": ["office-ui-fabric-react"],
"cyclicDependencyProjects": [
"office-ui-fabric-react"
],
"shouldPublish": true
},
{
"packageName": "@uifabric/styling",
"projectFolder": "packages/styling",
"versionPolicyName": "lockedMajor",
"cyclicDependencyProjects": ["office-ui-fabric-react", "@uifabric/example-app-base"],
"cyclicDependencyProjects": [
"office-ui-fabric-react",
"@uifabric/example-app-base"
],
"shouldPublish": true
},
{
Expand Down Expand Up @@ -111,4 +121,4 @@
"shouldPublish": false
}
]
}
}