Skip to content

Commit 2eb0d2a

Browse files
feat: Recursive tree-shake support (#111)
* feat: Tree shaking support Basic implementation working * chore: moved demo to static serve fix: addressed issues with missing chunks chore: preparing codebase for queue groups in require extension * fix: stable parallel chunk resolution improving resolution tactics updated style resolution remove useless chunk registration checks * refactor: moving code back into webpack template scope * refactor: removing old code * refactor: decouple loader scripts from the main bundle * docs: adding comments * fix: adding error handling for CSS * fix: fixed error handling on CSS and JS promises * perf: split chunks into 50kb fragments * refactor: cleanup unused code removing old template code removing old functions * style: linting interleaveFn * fix: use yarn workspaces on demo * feat: resolve and return required module No longer need to use a webpack_require inside another promise. You can now just use `__webpack_require__.interleaved()` * build: fixing rogue prod build * chore: remove encryption * style: fixing various linting issues * refactor: deleting old template files * docs: updating readme with fixed require chains you now no longer need to __webpack_require__ inside require.interleaved * ci: running multiple scripts in the build stage * docs: update license to BSD-3 * refactor: removing old files removing and .npmignore'ing files and folders * refactor: removing old files removing and .npmignore'ing files and folders * ci: improve build speed
1 parent 9d7493d commit 2eb0d2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1320
-22002
lines changed

.npmignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ test
33
.idea
44
.travis.yml
55
secure-src
6-
.nodecipherrc
6+
.nodecipherrc
7+
.gitignore
8+
.travis.yml
9+
yarn.lock
10+
renovate.json
11+
src
12+
test

.travis.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
language: node_js
22
node_js:
33
- 10
4+
before_install: rm -rf manual
45
install: yarn --ignore-engines # ignore engines to test node 6, otherwise it fails on engine check
56
cache: yarn
67
jobs:
78
include:
8-
- stage: Build
9-
name: Travis Status
10-
script: yarn travis-github-status
11-
- stage: Linting
12-
name: ESlint
13-
script: npm run lint
9+
- stage: Verify
10+
script:
11+
- yarn travis-github-status
12+
- yarn lint
1413
- stage: Release
14+
if: branch = master
1515
deploy:
1616
provider: script
1717
skip_cleanup: true
1818
script:
19-
- yarn semantic-release
19+
- yarn semantic-release

LICENSE

Lines changed: 27 additions & 678 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,19 @@ npm install webpack-external-import --save
4747
```sh
4848
yarn add webpack-external-import
4949
```
50+
5051
### Version 2.0!
51-
Major rewrite which has taken the original concept and built it directly into webpack runtime.
52-
If you want to read me about what this tool does.
5352

53+
Major rewrite which has taken the original concept and built it directly into webpack runtime.
54+
A big achievement in this release is **tree-shaking support**
55+
56+
If you want to read me about what this tool does.
5457

5558
Read the following:
59+
5660
- https://link.medium.com/L5zHiwylI3
5761
- working on more use cases and writing about V2
62+
5863
## Getting Started
5964

6065
1. Add `webpack-external-import/webpack` to your webpack plugins:
@@ -131,11 +136,12 @@ Below is an example of interleaving a module from `website-2`
131136
```js
132137
// import a chunk from another website build with webpack-external-import
133138

134-
__webpack_require__.interleaved("website-2/ValidationRules").then(() => {
135-
const validationRules = __webpack_require__("ValidationRules");
136-
// proceed to use as a you would with a normal require statement
137-
validationRules.validateObject(someObject);
138-
});
139+
__webpack_require__
140+
.interleaved("website-2/ValidationRules")
141+
.then(validationRules => {
142+
// proceed to use as a you would with a normal require statement
143+
validationRules.validateObject(someObject);
144+
});
139145
```
140146

141147
### With JSX
@@ -149,9 +155,9 @@ class SomeComponent extends Component {
149155
return (
150156
<div>
151157
<ExternalComponent
152-
interleave={__webpack_require__
153-
.interleaved("website-2/TitleComponent")
154-
.then(() => __webpack_require__("TitleComponent"))}
158+
interleave={__webpack_require__.interleaved(
159+
"website-2/TitleComponent"
160+
)}
155161
export="Title"
156162
title="Some Heading"
157163
/>
@@ -215,7 +221,7 @@ For example:
215221
// website-one App.js
216222
__webpack_require__
217223
.interleaved("website-3/TitleComponentWithCSSFile")
218-
.then(() => __webpack_require__("TitleComponentWithCSSFile"));
224+
.then(TitleComponentWithCSSFile => <TitleComponentWithCSSFile />);
219225
```
220226

221227
This ensures a easy way for other consumers, teams, engineers to look up what another project or team is willing
@@ -245,7 +251,9 @@ class App extends Component {
245251
componentDidMount() {
246252
__webpack_require__
247253
.interleaved("website-3/TitleComponentWithCSSFile")
248-
.then(() => __webpack_require__("TitleComponentWithCSSFile"));
254+
.then(TitleComponentWithCSSFile =>
255+
console.log(TitleComponentWithCSSFile)
256+
);
249257
}
250258

251259
renderDynamic = () => {
@@ -260,18 +268,18 @@ class App extends Component {
260268
<HelloWorld />
261269

262270
<ExternalComponent
263-
interleave={__webpack_require__
264-
.interleaved("website-2/TitleComponent")
265-
.then(() => __webpack_require__("TitleComponent"))}
271+
interleave={__webpack_require__.interleaved(
272+
"website-2/TitleComponent"
273+
)}
266274
export="Title"
267275
module="TitleComponent"
268276
title="Some Heading"
269277
/>
270278

271279
<ExternalComponent
272-
interleave={__webpack_require__
273-
.interleaved("website-3/TitleComponentWithCSSFile")
274-
.then(() => __webpack_require__("TitleComponentWithCSSFile"))}
280+
interleave={__webpack_require__.interleaved(
281+
"website-3/TitleComponentWithCSSFile"
282+
)}
275283
export="Title"
276284
title="Title Component With CSS File Import"
277285
/>
@@ -326,7 +334,6 @@ module.exports = {
326334
publicPath: `//localhost:3002/`,
327335
transformExtensions: /^(gz|map)$/i,
328336
writeToFileEmit: false,
329-
seed: null,
330337
filter: null,
331338
debug: true,
332339
map: null,
@@ -353,8 +360,7 @@ module.exports = {
353360
filter: null,
354361
debug: true,
355362
map: null,
356-
generate: null,
357-
sort: null
363+
generate: null
358364
})
359365
]
360366
};
@@ -405,18 +411,6 @@ Default: `src`
405411

406412
Test resource path to see if plugin should apply transformations
407413

408-
### `options.map`
409-
410-
Type: `Function(FileDescriptor): FileDescriptor`
411-
412-
Modify files details before the manifest is created. [FileDescriptor typings](#filedescriptor)
413-
414-
### `options.sort`
415-
416-
Type: `Function(FileDescriptor): number`
417-
418-
Sort files before they are passed to `generate`. [FileDescriptor typings](#filedescriptor)
419-
420414
### `options.generate`
421415

422416
Type: `Function(Object, FileDescriptor): Object`<br>
@@ -458,9 +452,8 @@ componentDidMount() {
458452
corsImport('http://localhost:3002/importManifest.js').then(() => {
459453
const Title = __webpack_require__
460454
.interleaved("website-two/TitleComponent")
461-
.then(() => __webpack_require__("TitleComponent"))
462455

463-
console.log(Title) // => Module {default: ()=>{}, Title: ()=>{}}
456+
Title.then(console.log) // => Module {default: ()=>{}, Title: ()=>{}}
464457
});
465458
}
466459
```

decrypt.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

encrypt.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

manual/Website1/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"author": "Zack Jackson <[email protected]> (https://github.com/ScriptedAlchemy)",
99
"scripts": {
10-
"manual:prod": "cross-env NODE_ENV=production node node_modules/webpack-dev-server/bin/webpack-dev-server.js",
10+
"manual:prod": "cross-env NODE_ENV=production webpack && cp serve.json dist/serve.json && serve dist -l 3001",
1111
"manual:dev": "cross-env NODE_ENV=development node node_modules/webpack-dev-server/bin/webpack-dev-server.js"
1212
},
1313
"devDependencies": {
@@ -33,15 +33,20 @@
3333
"crc-32": "^1.2.0",
3434
"cross-env": "^7.0.0",
3535
"html-webpack-plugin": "^4.0.0-beta.8",
36+
"lodash": "^4.17.15",
37+
"lodash-es": "^4.17.15",
3638
"mini-css-extract-plugin": "^0.9.0",
39+
"mobx": "^5.15.4",
3740
"moment": "^2.24.0",
3841
"optimize-css-assets-webpack-plugin": "^5.0.1",
39-
"react-select": "3.0.4",
4042
"react": "file:../../node_modules/react",
4143
"react-dom": "file:../../node_modules/react-dom",
44+
"react-select": "3.0.4",
4245
"regenerator-runtime": "^0.13.2",
4346
"scriptjs": "^2.5.9",
44-
"webpack-external-import": "*",
47+
"serve": "^11.3.0",
48+
"tiny-mobx-form": "^0.8.3",
49+
"webpack-external-import": "file:../../",
4550
"webpack-merge": "^4.2.1"
4651
}
4752
}

manual/Website1/serve.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"headers": [
3+
{
4+
"source": "**/*.@(jpg|jpeg|gif|png|txt|css)",
5+
"headers": [
6+
{
7+
"key": "Access-Control-Allow-Origin",
8+
"value": "*"
9+
},
10+
{
11+
"key": "Access-Control-Allow-Headers",
12+
"value": "Origin, X-Requested-With, Content-Type, Accept, Range"
13+
}
14+
]
15+
}
16+
]
17+
}

manual/Website1/src/App.jsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React, { Component } from "react";
2-
import {
3-
ExternalComponent,
4-
} from "webpack-external-import";
2+
import { ExternalComponent } from "webpack-external-import";
53
import HelloWorld from "./components/goodbye-world";
64
import "react-select";
5+
import { Form } from "tiny-mobx-form";
76

87
class App extends Component {
98
constructor(props) {
@@ -13,31 +12,40 @@ class App extends Component {
1312
manifestLoaded: false,
1413
loaded: false
1514
};
16-
}
1715

18-
componentDidMount() {
19-
__webpack_require__
20-
.interleaved("website-3/TitleComponentWithCSSFile")
21-
.then(() => __webpack_require__("TitleComponentWithCSSFile"))
16+
console.log("Tree Shake Form", Form);
2217
}
2318

19+
// componentDidMount() {
20+
// setTimeout(() => {
21+
// console.log("Tree Shake Form", Form);
22+
// }, 3000);
23+
// __webpack_require__
24+
// .interleaved("website-2/TitleComponent")
25+
// .then(() => __webpack_require__("TitleComponent"));
26+
//
27+
// __webpack_require__
28+
// .interleaved("website-3/TitleComponentWithCSSFile")
29+
// .then(() => __webpack_require__("TitleComponentWithCSSFile"));
30+
// }
31+
2432
render() {
2533
return (
2634
<div>
2735
<HelloWorld />
2836

2937
<ExternalComponent
30-
interleave={__webpack_require__
31-
.interleaved("website-2/TitleComponent")
32-
.then(() => __webpack_require__("TitleComponent"))}
38+
interleave={__webpack_require__.interleaved(
39+
"website-2/TitleComponent"
40+
)}
3341
export="Title"
3442
title="Some Heading"
3543
/>
3644

3745
<ExternalComponent
38-
interleave={__webpack_require__
39-
.interleaved("website-3/TitleComponentWithCSSFile")
40-
.then(() => __webpack_require__("TitleComponentWithCSSFile"))}
46+
interleave={__webpack_require__.interleaved(
47+
"website-3/TitleComponentWithCSSFile"
48+
)}
4149
export="Title"
4250
title="Title Component With CSS File Import"
4351
/>

0 commit comments

Comments
 (0)