This repository was archived by the owner on Nov 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
docs(README): add example #45
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| node_modules | ||
| node_modules | ||
| example/dist | ||
| example/node_modules |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -21,6 +21,9 @@ npm install --save-dev script-loader | |
|
|
||
| Executes JS script once in global context. | ||
|
|
||
| It converts the script into a plain string, and upon runtime, the exported string is passed to `window.eval` or `window.executeScript` depending on the browser. | ||
| Doing so, the code loaded with this loader is ran on the topmost scope. | ||
|
|
||
| > :warning: Doesn't work in NodeJS | ||
|
|
||
| ### Config (recommended) | ||
|
|
@@ -49,6 +52,10 @@ module.exports = { | |
| import exec from 'script-loader!./script.js'; | ||
| ``` | ||
|
|
||
| ### Example | ||
|
|
||
| Take a look at the example provided in the [./example](example) folder | ||
|
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. Please add a small example(s) directly to the README here |
||
|
|
||
| <h2 align="center">Maintainers</h2> | ||
|
|
||
| <table> | ||
|
|
||
This file contains hidden or 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,37 @@ | ||
| # Script loader example | ||
|
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. I'm sry, but we try to avoid adding (new) |
||
|
|
||
| This example demonstrates how to configure and how `script-loader` behaves. | ||
|
|
||
| ## Run | ||
|
|
||
| To run install the `example` dependencies and run webpack with: | ||
|
|
||
| ``` cli | ||
| npm i | ||
| npm start | ||
| ``` | ||
|
|
||
| Than open a browser and point it to: http://localhost:8080/assets/ | ||
|
|
||
| You will notice an output from the two scripts now packed into `example/dist/index.js` bundle: | ||
|
|
||
| ``` | ||
| List of the script.exec.js fields : | ||
| this fields : | ||
| - this[postMessage] = function | ||
| - this[blur] = function | ||
| - this[focus] = function | ||
| - this[close] = function | ||
| .... | ||
| arguments fields : | ||
| Nothing to show here | ||
| List of the entry.js fields : | ||
| this fields : | ||
| Nothing to show here | ||
| arguments fields : | ||
| arguments[[object Object]] = object | ||
| arguments[[object Object]] = object | ||
| ``` | ||
|
|
||
| Also note that code inside `script.exec.js` was executed without calling or using `exec` into the `entry.js` | ||
This file contains hidden or 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,10 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Script loader example</title> | ||
| </head> | ||
| <body> | ||
| <script src="../dist/index.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or 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,28 @@ | ||
| import exec from './script.exec.js'; | ||
|
|
||
| // List variables | ||
| var buffer = 'List of the <code>entry.js</code> fields : \n'; | ||
|
|
||
| buffer += '<em>this</em> fields : \n'; | ||
| var hasFieldsInThis = false; | ||
| for (var name in this) { | ||
| hasFieldsInThis = true; | ||
| buffer += '\t- this[' + name + '] = ' + typeof this[name] + '\n'; | ||
| } | ||
| if (!hasFieldsInThis) { | ||
| buffer += '\t<em>Nothing to show here<\em>\n'; | ||
| } | ||
|
|
||
| buffer += '<em>arguments</em> fields : \n'; | ||
| if (typeof arguments !== 'undefined') { | ||
| for (var x of arguments) { | ||
| buffer += '\targuments[' + x + '] = ' + typeof x + '\n'; | ||
| } | ||
| } else { | ||
| buffer += '\t<em>Nothing to show here<em>\n'; | ||
| } | ||
|
|
||
|
|
||
| var pre = document.createElement('pre'); | ||
| pre.innerHTML = buffer; | ||
| document.body.appendChild(pre); |
This file contains hidden or 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,32 @@ | ||
| { | ||
| "name": "script-loader-example", | ||
| "version": "0.0.1", | ||
| "author": "Tiberiu CORBU @tiberiucorbu", | ||
| "description": "Showcase the use of script-loader", | ||
| "license": "MIT", | ||
| "main": "dist/index.js", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "start": "webpack && webpack-dev-server" | ||
| }, | ||
| "dependencies": {}, | ||
| "devDependencies": { | ||
| "script-loader": "../", | ||
| "webpack": "^3.1.0", | ||
| "webpack-dev-server": "^2.9.1" | ||
| }, | ||
| "homepage": "http://github.com/webpack-contrib/extract-text-webpack-plugin", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/webpack-contrib/script-loader.git" | ||
| }, | ||
| "pre-commit": "lint-staged", | ||
| "lint-staged": { | ||
| "*.js": [ | ||
| "eslint --fix", | ||
| "git add" | ||
| ] | ||
| } | ||
| } |
This file contains hidden or 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,25 @@ | ||
| var buffer = 'List of the <code>script.exec.js</code> fields : \n'; | ||
|
|
||
| buffer += '<em>this</em> fields : \n'; | ||
| var hasFieldsInThis = false; | ||
| for (var name in this) { | ||
| hasFieldsInThis = true; | ||
| buffer += '\t- this[' + name + '] = ' + typeof this[name] + '\n'; | ||
| } | ||
| if (!hasFieldsInThis) { | ||
| buffer += '\t<em>Nothing to show here<\em>\n'; | ||
| } | ||
|
|
||
| buffer += '<em>arguments</em> fields : \n'; | ||
| if (typeof arguments !== 'undefined') { | ||
| for (var x of arguments) { | ||
| buffer += '\targuments[' + x + '] = ' + typeof x + '\n'; | ||
| } | ||
| } else { | ||
| buffer += '\t<em>Nothing to show here<em>\n'; | ||
| } | ||
|
|
||
|
|
||
| var pre = document.createElement('pre'); | ||
| pre.innerHTML = buffer; | ||
| document.body.appendChild(pre); |
This file contains hidden or 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,16 @@ | ||
| module.exports = { | ||
| entry: { | ||
| index: "./entry.js", | ||
| }, | ||
| output: { | ||
| filename: "[name].js?[hash]", | ||
| chunkFilename: "[name].js?[hash]-[chunkhash]", | ||
| path: __dirname + "/dist" | ||
| }, | ||
| module: { | ||
| loaders: [ | ||
| { test: /exec\.js$/, loader: "script-loader" } | ||
| ] | ||
| }, | ||
| devtool: "source-map" | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.