From 33d81cfef7e7a320fc28e361b2227358142a5892 Mon Sep 17 00:00:00 2001 From: Kirill Nagaitsev Date: Tue, 23 Jun 2020 18:42:32 -0500 Subject: [PATCH] refactor(client): make log and strip ansi transpiled bundle modules --- client-src/default/index.js | 2 +- client-src/default/utils/log.js | 2 +- client-src/transpiled-modules/log.js | 3 ++ client-src/transpiled-modules/strip-ansi.js | 3 ++ .../transpiled-modules/webpack.config.js | 39 +++++++++++++++++++ package-lock.json | 9 +++++ package.json | 4 +- 7 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 client-src/transpiled-modules/log.js create mode 100644 client-src/transpiled-modules/strip-ansi.js create mode 100644 client-src/transpiled-modules/webpack.config.js diff --git a/client-src/default/index.js b/client-src/default/index.js index a8cbc10ccd..b6d22c38bc 100644 --- a/client-src/default/index.js +++ b/client-src/default/index.js @@ -7,7 +7,7 @@ window.process.env = window.process.env || {}; /* global __resourceQuery WorkerGlobalScope self */ /* eslint prefer-destructuring: off */ -const stripAnsi = require('strip-ansi'); +const stripAnsi = require('../transpiled-modules/strip-ansi'); const socket = require('./socket'); const overlay = require('./overlay'); const { log, setLogLevel } = require('./utils/log'); diff --git a/client-src/default/utils/log.js b/client-src/default/utils/log.js index 41d5ca2572..d92242f7d2 100644 --- a/client-src/default/utils/log.js +++ b/client-src/default/utils/log.js @@ -1,6 +1,6 @@ 'use strict'; -const log = require('webpack/lib/logging/runtime'); +const log = require('../../transpiled-modules/log'); const name = 'webpack-dev-server'; const defaultLevel = 'info'; diff --git a/client-src/transpiled-modules/log.js b/client-src/transpiled-modules/log.js new file mode 100644 index 0000000000..02c3765ae6 --- /dev/null +++ b/client-src/transpiled-modules/log.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('webpack/lib/logging/runtime'); diff --git a/client-src/transpiled-modules/strip-ansi.js b/client-src/transpiled-modules/strip-ansi.js new file mode 100644 index 0000000000..8f36ce2024 --- /dev/null +++ b/client-src/transpiled-modules/strip-ansi.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('strip-ansi'); diff --git a/client-src/transpiled-modules/webpack.config.js b/client-src/transpiled-modules/webpack.config.js new file mode 100644 index 0000000000..d1b38c1054 --- /dev/null +++ b/client-src/transpiled-modules/webpack.config.js @@ -0,0 +1,39 @@ +'use strict'; + +const path = require('path'); +const merge = require('webpack-merge'); + +const base = { + mode: 'production', + output: { + path: path.resolve(__dirname, '../../client/transpiled-modules'), + libraryTarget: 'commonjs2', + }, + module: { + rules: [ + { + test: /\.js$/, + use: [ + { + loader: 'babel-loader', + }, + ], + }, + ], + }, +}; + +module.exports = [ + merge(base, { + entry: path.join(__dirname, 'log.js'), + output: { + filename: 'log.js', + }, + }), + merge(base, { + entry: path.join(__dirname, 'strip-ansi.js'), + output: { + filename: 'strip-ansi.js', + }, + }), +]; diff --git a/package-lock.json b/package-lock.json index 6ad45a99d4..729a8aedf9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17981,6 +17981,15 @@ "uuid": "^3.3.2" } }, + "webpack-merge": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-4.2.2.tgz", + "integrity": "sha512-TUE1UGoTX2Cd42j3krGYqObZbOD+xF7u28WB7tfUordytSjbWTIjK/8V0amkBfTYN4/pB/GIDlJZZ657BGG19g==", + "dev": true, + "requires": { + "lodash": "^4.17.15" + } + }, "webpack-sources": { "version": "1.4.3", "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.4.3.tgz", diff --git a/package.json b/package.json index 23b9970514..3424506119 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "build:client:clients": "babel client-src/clients --out-dir client/clients", "build:client:index": "webpack --color --config client-src/default/webpack.config.js", "build:client:sockjs": "webpack --color --config client-src/sockjs/webpack.config.js", + "build:client:transpiled-modules": "webpack --color --config client-src/transpiled-modules/webpack.config.js", "build:client": "rimraf ./client/* && npm-run-all -s -l -p \"build:client:**\"", "webpack-dev-server": "node examples/run-example.js", "release": "standard-version" @@ -109,7 +110,8 @@ "typescript": "^3.9.5", "url-loader": "^4.1.0", "webpack": "^4.43.0", - "webpack-cli": "^3.3.11" + "webpack-cli": "^3.3.11", + "webpack-merge": "^4.2.2" }, "peerDependencies": { "webpack": "^4.0.0 || ^5.0.0"