From 00cda68456c42a4727b52426bbea01a56fb475e1 Mon Sep 17 00:00:00 2001 From: ValeraS Date: Wed, 12 Sep 2018 11:41:27 +0300 Subject: [PATCH] update frame-runner webpack config --- packages/learn/package.json | 7 +- packages/learn/webpack-frame-runner.js | 100 ++++++++----------------- 2 files changed, 35 insertions(+), 72 deletions(-) diff --git a/packages/learn/package.json b/packages/learn/package.json index 7b5bf2f31c..080c4f6e91 100644 --- a/packages/learn/package.json +++ b/packages/learn/package.json @@ -56,7 +56,6 @@ "reselect": "^3.0.1", "rxjs": "^5.5.7", "store": "^2.0.12", - "uglifyjs-webpack-plugin": "^1.2.4", "validator": "^10.3.0", "webpack-remove-serviceworker-plugin": "^1.0.0" }, @@ -66,9 +65,9 @@ "license": "MIT", "scripts": { "build": "yarn build:frame-runner && gatsby build", - "build:frame-runner": "webpack --config ./webpack-frame-runner.js", - "build:loop-protect": "webpack --config ./webpack-loop-protect.js", - "develop": "yarn build:frame-runner && gatsby develop", + "build:frame-runner": "webpack --env.production --config ./webpack-frame-runner.js", + "develop": "yarn develop:frame-runner && gatsby develop", + "develop:frame-runner": "webpack --config ./webpack-frame-runner.js", "format": "yarn format:gatsby && yarn format:src && yarn format:utils && yarn lint", "format:gatsby": "prettier --write './gatsby*.js'", "format:src": "prettier --write './src/**/*.js'", diff --git a/packages/learn/webpack-frame-runner.js b/packages/learn/webpack-frame-runner.js index 75f23d03a9..8a65f339e9 100644 --- a/packages/learn/webpack-frame-runner.js +++ b/packages/learn/webpack-frame-runner.js @@ -1,72 +1,36 @@ -const webpack = require('webpack'); const path = require('path'); -const UglifyPlugin = require('uglifyjs-webpack-plugin'); -const __DEV__ = process.env.NODE_ENV !== 'production'; - -module.exports = { - mode: __DEV__ ? 'development' : 'production', - entry: './src/client/frame-runner.js', - devtool: __DEV__ ? 'inline-source-map' : 'source-map', - node: { - // Mock Node.js modules that Babel require()s but that we don't - // particularly care about. - fs: 'empty', - module: 'empty', - net: 'empty' - }, - output: { - filename: __DEV__ ? 'frame-runner.js' : 'frame-runner-[hash].js', - path: path.join(__dirname, './static/js') - }, - stats: { - // Examine all modules - maxModules: Infinity, - // Display bailout reasons - optimizationBailout: true - }, - module: { - rules: [{ - test: /\.jsx?$/, - include: [ path.join(__dirname, 'client/') ], - use: { - loader: 'babel-loader', - options: { - babelrc: false, - presets: [ - [ 'es2015', { modules: false }], - [ 'stage-3' ] - ], - plugins: [ - 'transform-runtime', - 'lodash' - ] +module.exports = (env = {}) => { + const __DEV__ = env.production !== true; + return { + mode: __DEV__ ? 'development' : 'production', + entry: './src/client/frame-runner.js', + devtool: __DEV__ ? 'inline-source-map' : 'source-map', + output: { + filename: 'frame-runner.js', + path: path.join(__dirname, './static/js') + }, + stats: { + // Display bailout reasons + optimizationBailout: true + }, + module: { + rules: [{ + test: /\.jsx?$/, + include: [ path.join(__dirname, 'src/client/') ], + use: { + loader: 'babel-loader', + options: { + babelrc: false, + presets: [ + [ '@babel/preset-env', { modules: false } ] + ], + plugins: [ + '@babel/plugin-transform-runtime' + ] + } } - } - }] - }, - externals: { - rxjs: 'Rx' - }, - plugins: [ - new webpack.DefinePlugin({ - 'process.env': { - NODE_ENV: JSON.stringify(__DEV__ ? 'development' : 'production') - }, - __DEVTOOLS__: !__DEV__ - }), - // Use browser version of visionmedia-debug - new webpack.NormalModuleReplacementPlugin( - /debug\/node/, - 'debug/src/browser' - ) - ] + }] + } + }; }; - -module.exports.plugins.push( - new UglifyPlugin({ - test: /\.js($|\?)/i, - cache: true, - sourceMap: true - }) -);