Skip to content

Commit

Permalink
Add 'serve' script to use webpack-serve to host sample app locally
Browse files Browse the repository at this point in the history
  • Loading branch information
SequoiaBuild committed Aug 8, 2018
1 parent a5fa638 commit aceff72
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/release/
/node_modules/
package-lock.json
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# dojo-webpack-plugin-sample

[Sample application](https://openntf.github.io/dojo-webpack-plugin-sample/test.html) demonstrating the use of [dojo-webpack-plugin](https://github.com/OpenNTF/dojo-webpack-plugin) with [webpack](https://webpack.github.io/). The sample can be run as a webpack application (the default) or as an [unpacked application](https://openntf.github.io/dojo-webpack-plugin-sample/test.html?nopack=1) that uses the Dojo loader by specifying the ?nopack=1 query arg in the URL. It demonstrates how to construct a [Dojo loader config](https://github.com/OpenNTF/dojo-webpack-plugin-sample/blob/master/js/loaderConfig.js) that can be used in both weback and non-webpack versions of a Dojo application. You may want to support non-webpack versions during the development phase of your application in order to avoid build overhead during development.
[Sample application](https://openntf.github.io/dojo-webpack-plugin-sample/test.html) demonstrating the use of [dojo-webpack-plugin](https://github.com/OpenNTF/dojo-webpack-plugin) with [webpack](https://webpack.github.io/). The sample can be run as a webpack application (the default) or as an [unpacked application](https://openntf.github.io/dojo-webpack-plugin-sample/test.html?nopack=1) that uses the native Dojo loader by specifying the ?nopack=1 query arg in the URL. It demonstrates how to construct a [Dojo loader config](https://github.com/OpenNTF/dojo-webpack-plugin-sample/blob/master/js/loaderConfig.js) that can be used in both weback and non-webpack versions of a Dojo application. You may want to support non-webpack versions during the development phase of your application in order to avoid build overhead during development.

```
npm install
npm run build
npm run [build|serve]
```

The built files will be located in `./release`. You can launch the app by loading `./test.html` in a browser. Note that loading the app from the file system works only for the packed application. The non-packed version of the app (?nopack=1) loads Dojo from a CDN, so cross-origin restrictions in browsers require that you load the non-packed app from an http server. Alternatively, you could modify test.html and js/loaderConfig.js to use the locally installed Dojo for the unpacked application as well.
The `build` script builds the sample application, placing the deployable artifacts in the `release` directory. The `serve` script builds the sample application and uses [webpack-serve](https://www.npmjs.com/package/webpack-serve) to host the application locally at http://localhost:8080/test.html. It automatically launches a browser to load and run the application.

[@GordonSmith](https://github.com/GordonSmith) provides a fork of the sample app with some variations in [here](https://github.com/OpenNTF/dojo-webpack-plugin-sample/issues/40).
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
"dijit": "1.13.0",
"dojo": "1.13.0",
"dojo-util": "1.13.0",
"dojo-webpack-plugin": "2.7.1",
"dojo-webpack-plugin": "2.7.4",
"dojox": "1.12.2",
"less": "2.7.1",
"less-loader": "4.1.0",
"style-loader": "0.20.3",
"url-loader": "1.0.1",
"webpack": "4.2.0",
"webpack-cli": "2.0.11"
"webpack-cli": "2.0.11",
"webpack-serve": "2.0.2"
},
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/OpenNTF/dojo-webpack-plugin-sample.git"
},
"scripts": {
"build": "node node_modules/webpack/bin/webpack.js --config webpack.config.js"
"build": "webpack --config webpack.config.js",
"serve": "webpack-serve --open-path test.html"
}
}
5 changes: 5 additions & 0 deletions serve.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
devMiddleware: {
publicPath: "/release/"
}
}
9 changes: 5 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
entry: "js/bootstrap",
output: {
path: path.join(__dirname, "release"),
publicPath: "release/",
publicPath: "/release/",
pathinfo: true,
filename: "bundle.js"
},
Expand All @@ -40,14 +40,15 @@ module.exports = {
}
}
]
}]
}]
},
plugins: [
new DojoWebpackPlugin({
loaderConfig: require("./js/loaderConfig"),
environment: {dojoRoot: "release"}, // used at run time for non-packed resources (e.g. blank.gif)
buildEnvironment: {dojoRoot: "node_modules"}, // used at build time
locales: ["en"]
locales: ["en"],
noConsole: true
}),

// Copy non-packed resources needed by the app to the release directory
Expand All @@ -69,7 +70,7 @@ module.exports = {
resolveLoader: {
modules: ["node_modules"]
},
mode: "production",
mode: process.env.WEBPACK_SERVE ? 'development' : 'production',
optimization: {
minimizer: [
// we specify a custom UglifyJsPlugin here to get source maps in production
Expand Down

0 comments on commit aceff72

Please sign in to comment.