Created
December 4, 2018 22:17
-
-
Save Danetag/524daa54c1bfe0edb2827c5d75389591 to your computer and use it in GitHub Desktop.
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
| const devServer = {}; | |
| const webpack = require("webpack"); | |
| const ENV = process.env.NODE_ENV === "production" ? "production" : "development"; | |
| const outputPath = | |
| ENV === "production" | |
| ? path.resolve(__dirname + "../../static/") | |
| : path.resolve(__dirname + "/dist/"); | |
| const plugins = []; | |
| const devtool = ENV === "production" ? false : "inline-source-map"; | |
| const entry = ["whatwg-fetch", __dirname + "/src/js/app.js"]; | |
| const watch = ENV === "production"; | |
| const filename = ENV === "production" ? "[name].[chunkhash].js" : "bundle.js"; | |
| const publicPath = ENV === "production" | |
| ? "/wp-content/themes/my-theme/static/" | |
| : "http://localhost:8080/" | |
| if (ENV !== "production") { | |
| plugins.push(new webpack.HotModuleReplacementPlugin()); | |
| entry.push("webpack/hot/dev-server"); | |
| devServer = { | |
| contentBase: "./dist", | |
| hot: true, | |
| publicPath: "http://localhost:8080/", | |
| headers: { | |
| "Access-Control-Allow-Origin": "*", | |
| "Access-Control-Allow-Methods": "POST, GET, PUT, DELETE, OPTIONS" | |
| } | |
| }; | |
| } | |
| module.exports = { | |
| mode: ENV, | |
| entry: entry, | |
| output: { | |
| // options related to how webpack emits results | |
| path: outputPath, | |
| // output path for the bundle, set on top depending on the environment | |
| filename: filename, | |
| // the filename template for entry chunks, set on top depending on the environment | |
| chunkFilename: "[name]-[chunkhash].js", | |
| publicPath: publicPath | |
| }, | |
| watch: watch, | |
| target: "web", | |
| devtool: devtool | |
| ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment