-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c1e821
commit d9e8c6d
Showing
8 changed files
with
97 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const pathUtil = require('path'); | ||
const fs = require('fs'); | ||
const glob = require('glob'); | ||
|
||
const dist = pathUtil.join(__dirname, '..', '..', 'dist'); | ||
console.log(`dist: ${dist}`); | ||
|
||
const scaffoldingFiles = glob.sync('scaffolding/*.js', { | ||
cwd: dist | ||
}); | ||
console.log(`scaffolding: ${scaffoldingFiles.join(', ')}`); | ||
const scaffoldingAssets = {}; | ||
for (const path of scaffoldingFiles) { | ||
scaffoldingAssets[path] = fs.readFileSync(pathUtil.join(dist, path), 'utf-8'); | ||
} | ||
|
||
const indexPath = pathUtil.join(dist, 'index.html'); | ||
console.log(`index.html: ${indexPath}`); | ||
let indexContent = fs.readFileSync(indexPath, 'utf8'); | ||
const jsPath = pathUtil.join(dist, indexContent.match(/<script src="(.*)"><\/script>/)[1]); | ||
console.log(`packager.js: ${jsPath}`); | ||
let jsContent = fs.readFileSync(jsPath, 'utf-8'); | ||
jsContent = `window.__ASSETS__=${JSON.stringify(scaffoldingAssets)};${jsContent}`; | ||
jsContent = jsContent.replace(/<\/script>/g, '\\u003c/script>'); | ||
indexContent = indexContent.replace(/<script src=".*"><\/script>/, () => `<script>${jsContent}</script>`); | ||
|
||
const standalonePath = pathUtil.join(dist, 'standalone.html'); | ||
console.log(`standalone.html: ${standalonePath}`); | ||
fs.writeFileSync(standalonePath, indexContent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Plugin to modify webpack to interpret all dynamic imports as webpackMode: "eager" | ||
|
||
const patchParser = (parser) => { | ||
const originalParseCommentOptions = parser.parseCommentOptions; | ||
parser.parseCommentOptions = function (...args) { | ||
const result = originalParseCommentOptions.call(this, ...args); | ||
result.options.webpackMode = 'eager'; | ||
return result; | ||
}; | ||
}; | ||
|
||
class TWStandalonePlugin { | ||
apply (compiler) { | ||
compiler.hooks.normalModuleFactory.tap('TWStandalonePlugin', (normalModuleFactory) => { | ||
normalModuleFactory.hooks.parser.for('javascript/auto').tap('TWStandalonePlugin', patchParser); | ||
normalModuleFactory.hooks.parser.for('javascript/dynamic').tap('TWStandalonePlugin', patchParser); | ||
normalModuleFactory.hooks.parser.for('javascript/esm').tap('TWStandalonePlugin', patchParser); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = TWStandalonePlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters