From dc867bad37ad19ca3dd7124e7ceae2d301dedd14 Mon Sep 17 00:00:00 2001 From: netpro2k <netpro2k@gmail.com> Date: Mon, 30 Jul 2018 16:24:40 -0700 Subject: [PATCH] Revert merge issue with webpack.config.js --- webpack.config.js | 71 ++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index b17d5a4ce..07dcf72f6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -9,7 +9,6 @@ const HTMLWebpackPlugin = require("html-webpack-plugin"); const ExtractTextPlugin = require("extract-text-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin"); const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); -const _ = require("lodash"); function createHTTPSConfig() { // Generate certs for the local webpack-dev-server. @@ -58,21 +57,6 @@ function createHTTPSConfig() { } } -class LodashTemplatePlugin { - constructor(options) { - this.options = options; - } - - apply(compiler) { - compiler.plugin("compilation", compilation => { - compilation.plugin("html-webpack-plugin-before-html-processing", async data => { - data.html = _.template(data.html, this.options)(); - return data; - }); - }); - } -} - module.exports = (env, argv) => ({ entry: { index: path.join(__dirname, "src", "index.js"), @@ -118,9 +102,7 @@ module.exports = (env, argv) => ({ loader: "html-loader", options: { // <a-asset-item>'s src property is overwritten with the correct transformed asset url. - attrs: ["img:src", "a-asset-item:src", "audio:src", "source:src"], - // You can get transformed asset urls in an html template using ${require("pathToFile.ext")} - interpolate: "require" + attrs: ["img:src", "a-asset-item:src", "audio:src", "source:src"] } }, { @@ -187,33 +169,57 @@ module.exports = (env, argv) => ({ } ] }, - // necessary due to https://github.com/visionmedia/debug/issues/547 + optimization: { - minimizer: [new UglifyJsPlugin({ uglifyOptions: { compress: { collapse_vars: false } } })] + // necessary due to https://github.com/visionmedia/debug/issues/547 + minimizer: [new UglifyJsPlugin({ uglifyOptions: { compress: { collapse_vars: false } } })], + splitChunks: { + cacheGroups: { + engine: { + test: /[\\/]node_modules[\\/](aframe|cannon|three\.js)/, + priority: 100, + name: "engine", + chunks: "all" + }, + vendors: { + test: /([\\/]node_modules[\\/]|[\\/]vendor[\\/])/, + priority: 50, + name: "vendor", + chunks: "all" + } + } + } }, plugins: [ // Each output page needs a HTMLWebpackPlugin entry new HTMLWebpackPlugin({ filename: "index.html", template: path.join(__dirname, "src", "index.html"), - // Chunks correspond with the entries you wish to include in your html template - chunks: ["index"] + chunks: ["vendor", "index"] }), new HTMLWebpackPlugin({ filename: "hub.html", template: path.join(__dirname, "src", "hub.html"), - chunks: ["hub"], - inject: "head" + chunks: ["vendor", "engine", "hub"], + inject: "head", + meta: [ + { + "http-equiv": "origin-trial", + "data-feature": "WebVR (For Chrome M62+)", + "data-expires": process.env.ORIGIN_TRIAL_EXPIRES, + content: process.env.ORIGIN_TRIAL_TOKEN + } + ] }), new HTMLWebpackPlugin({ filename: "link.html", template: path.join(__dirname, "src", "link.html"), - chunks: ["link"] + chunks: ["vendor", "link"] }), new HTMLWebpackPlugin({ filename: "avatar-selector.html", template: path.join(__dirname, "src", "avatar-selector.html"), - chunks: ["avatar-selector"], + chunks: ["vendor", "engine", "avatar-selector"], inject: "head" }), new CopyWebpackPlugin([ @@ -233,17 +239,6 @@ module.exports = (env, argv) => ({ filename: "assets/stylesheets/[name]-[md5:contenthash:hex:20].css", disable: argv.mode !== "production" }), - // Transform the output of the html-loader using _.template - // before passing the result to html-webpack-plugin - new LodashTemplatePlugin({ - // expose these variables to the lodash template - // ex: <%= ORIGIN_TRIAL_TOKEN %> - imports: { - NODE_ENV: argv.mode, - ORIGIN_TRIAL_EXPIRES: process.env.ORIGIN_TRIAL_EXPIRES, - ORIGIN_TRIAL_TOKEN: process.env.ORIGIN_TRIAL_TOKEN - } - }), // Define process.env variables in the browser context. new webpack.DefinePlugin({ "process.env": JSON.stringify({ -- GitLab