diff --git a/.gitignore b/.gitignore index 07fc524..d9606f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /release/ /node_modules/ +package-lock.json diff --git a/README.md b/README.md index d647c5f..f312d40 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/package.json b/package.json index b7305c2..61caf80 100644 --- a/package.json +++ b/package.json @@ -7,14 +7,15 @@ "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": { @@ -22,6 +23,7 @@ "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" } } diff --git a/serve.config.js b/serve.config.js new file mode 100644 index 0000000..5afcd22 --- /dev/null +++ b/serve.config.js @@ -0,0 +1,5 @@ +module.exports = { + devMiddleware: { + publicPath: "/release/" + } +} diff --git a/webpack.config.js b/webpack.config.js index 0c55868..d6df7ce 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -25,7 +25,7 @@ module.exports = { entry: "js/bootstrap", output: { path: path.join(__dirname, "release"), - publicPath: "release/", + publicPath: "/release/", pathinfo: true, filename: "bundle.js" }, @@ -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 @@ -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