From 9d983f5583f7527a283b0bdcf8a3a4e0e047c253 Mon Sep 17 00:00:00 2001 From: fushen Date: Thu, 12 Nov 2020 11:09:37 +0800 Subject: [PATCH 1/3] feat: add platform-loader --- packages/platform-loader/README.md | 3 + packages/platform-loader/package.json | 24 ++ .../src}/TraverseImport.js | 22 +- .../src}/index.js | 0 packages/rax-compile-config/README.md | 3 - packages/rax-compile-config/package.json | 51 ----- .../rax-compile-config/src/getBabelConfig.js | 121 ---------- .../rax-compile-config/src/getRouteName.js | 27 --- .../src/handleWebpackErr.js | 45 ---- .../src/hmr/formatWebpackMessages.js | 124 ----------- .../src/hmr/moduleHotAccept.loader.js | 49 ---- .../src/hmr/webpackHotDevClient.entry.js | 209 ------------------ packages/rax-compile-config/src/index.js | 16 -- .../rax-compile-config/src/setBabelAlias.js | 8 - 14 files changed, 40 insertions(+), 662 deletions(-) create mode 100644 packages/platform-loader/README.md create mode 100644 packages/platform-loader/package.json rename packages/{rax-compile-config/src/platformLoader => platform-loader/src}/TraverseImport.js (92%) rename packages/{rax-compile-config/src/platformLoader => platform-loader/src}/index.js (100%) delete mode 100644 packages/rax-compile-config/README.md delete mode 100644 packages/rax-compile-config/package.json delete mode 100644 packages/rax-compile-config/src/getBabelConfig.js delete mode 100644 packages/rax-compile-config/src/getRouteName.js delete mode 100644 packages/rax-compile-config/src/handleWebpackErr.js delete mode 100644 packages/rax-compile-config/src/hmr/formatWebpackMessages.js delete mode 100644 packages/rax-compile-config/src/hmr/moduleHotAccept.loader.js delete mode 100644 packages/rax-compile-config/src/hmr/webpackHotDevClient.entry.js delete mode 100644 packages/rax-compile-config/src/index.js delete mode 100644 packages/rax-compile-config/src/setBabelAlias.js diff --git a/packages/platform-loader/README.md b/packages/platform-loader/README.md new file mode 100644 index 000000000..d569eb1de --- /dev/null +++ b/packages/platform-loader/README.md @@ -0,0 +1,3 @@ +# rax-platform-loader [![npm](https://img.shields.io/npm/v/rax-platform-loader.svg)](https://www.npmjs.com/package/rax-platform-loader) + +For helping remove other platform code. diff --git a/packages/platform-loader/package.json b/packages/platform-loader/package.json new file mode 100644 index 000000000..d90cc925d --- /dev/null +++ b/packages/platform-loader/package.json @@ -0,0 +1,24 @@ +{ + "name": "rax-platform-loader", + "version": "1.0.0", + "description": "rax platform loader for helping remove other platform code", + "license": "BSD-3-Clause", + "main": "lib/index.js", + "repository": { + "type": "git", + "url": "git+https://github.com/raxjs/rax-scripts.git" + }, + "bugs": { + "url": "https://github.com/raxjs/rax-scripts/issues" + }, + "homepage": "https://github.com/raxjs/rax-scripts/tree/master/packages/platform-loader#readme", + "dependencies": { + "@babel/code-frame": "^7.5.5", + "@babel/generator": "^7.6.4", + "@babel/parser": "^7.6.4", + "@babel/traverse": "^7.6.3", + "@babel/types": "^7.6.3", + "loader-utils": "^1.1.0", + "source-map": "^0.7.3" + } +} diff --git a/packages/rax-compile-config/src/platformLoader/TraverseImport.js b/packages/platform-loader/src/TraverseImport.js similarity index 92% rename from packages/rax-compile-config/src/platformLoader/TraverseImport.js rename to packages/platform-loader/src/TraverseImport.js index 820c16f25..baf895986 100644 --- a/packages/rax-compile-config/src/platformLoader/TraverseImport.js +++ b/packages/platform-loader/src/TraverseImport.js @@ -3,7 +3,7 @@ const babelParser = require('@babel/parser'); const traverse = require('@babel/traverse').default; const types = require('@babel/types'); const generate = require('@babel/generator').default; -const codeFrame = require('@babel/code-frame').default; +const { codeFrameColumns } = require('@babel/code-frame').default; module.exports = function traverseImport(options, inputSource, sourceMapOption) { let specified; // Collector import specifiers @@ -102,17 +102,21 @@ module.exports = function traverseImport(options, inputSource, sourceMapOption) }); } catch (err) { if (err instanceof SyntaxError) { - err.lineNumber = err.loc.line; - err.column = err.loc.column + 1; + const location = { + start: { + line: err.loc.line, + column: err.loc.column + 1 + } + }; // remove trailing "(LINE:COLUMN)" acorn message and add in esprima syntax error message start - err.message = `Line ${err.lineNumber}: ${err.message.replace(/ \((\d+):(\d+)\)$/, '') - // add codeframe - }\n\n${ - codeFrame(inputSource, err.lineNumber, err.column, { highlightCode: true })}`; + console.log(`Line ${err.lineNumber}: ${err.message.replace(/ \((\d+):(\d+)\)$/, '') + // add codeframe + }\n\n${ + codeFrameColumns(inputSource, location, { highlightCode: true })}`); + } else { + console.log(err); } - - throw err; } traverse(ast, { diff --git a/packages/rax-compile-config/src/platformLoader/index.js b/packages/platform-loader/src/index.js similarity index 100% rename from packages/rax-compile-config/src/platformLoader/index.js rename to packages/platform-loader/src/index.js diff --git a/packages/rax-compile-config/README.md b/packages/rax-compile-config/README.md deleted file mode 100644 index 6f1630fa7..000000000 --- a/packages/rax-compile-config/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# rax-compile-config [![npm](https://img.shields.io/npm/v/rax-compile-config.svg)](https://www.npmjs.com/package/rax-compile-config) - -Configuration which is used by `rax-scripts` official plugins diff --git a/packages/rax-compile-config/package.json b/packages/rax-compile-config/package.json deleted file mode 100644 index db0bcba92..000000000 --- a/packages/rax-compile-config/package.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "rax-compile-config", - "version": "0.2.16", - "description": "rax app base plugins", - "license": "BSD-3-Clause", - "main": "src/index.js", - "repository": { - "type": "git", - "url": "git+https://github.com/raxjs/rax-scripts.git" - }, - "bugs": { - "url": "https://github.com/raxjs/rax-scripts/issues" - }, - "homepage": "https://github.com/raxjs/rax-scripts/tree/master/packages/rax-compile-config#readme", - "dependencies": { - "@babel/code-frame": "^7.5.5", - "@babel/generator": "^7.6.4", - "@babel/parser": "^7.6.4", - "@babel/plugin-proposal-class-properties": "7.2.0", - "@babel/plugin-proposal-decorators": "7.2.0", - "@babel/plugin-proposal-export-default-from": "7.2.0", - "@babel/plugin-proposal-export-namespace-from": "^7.0.0", - "@babel/plugin-proposal-function-bind": "^7.2.0", - "@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0", - "@babel/plugin-proposal-optional-chaining": "^7.0.0", - "@babel/plugin-syntax-dynamic-import": "^7.2.0", - "@babel/plugin-transform-runtime": "^7.2.0", - "@babel/preset-env": "7.2.0", - "@babel/preset-flow": "7.0.0", - "@babel/preset-react": "7.0.0", - "@babel/runtime": "^7.2.0", - "@babel/traverse": "^7.6.3", - "@babel/types": "^7.6.3", - "babel-merge": "^3.0.0", - "babel-plugin-minify-dead-code-elimination-while-loop-fixed": "^0.3.0", - "babel-plugin-transform-jsx-class": "^0.1.2", - "babel-plugin-transform-jsx-condition": "^0.1.0", - "babel-plugin-transform-jsx-fragment": "^0.1.1", - "babel-plugin-transform-jsx-list": "^0.1.0", - "babel-plugin-transform-jsx-memo": "^0.1.2", - "babel-plugin-transform-jsx-slot": "^0.1.1", - "babel-plugin-transform-jsx-stylesheet": "^0.6.8", - "babel-plugin-transform-jsx-to-html": "^0.1.0", - "babel-runtime-jsx-plus": "^0.1.3", - "chalk": "^2.4.2", - "fs-extra": "^8.1.0", - "loader-utils": "^1.1.0", - "source-map": "^0.7.3", - "strip-ansi": "^5.0.0" - } -} diff --git a/packages/rax-compile-config/src/getBabelConfig.js b/packages/rax-compile-config/src/getBabelConfig.js deleted file mode 100644 index 6c9b74d0e..000000000 --- a/packages/rax-compile-config/src/getBabelConfig.js +++ /dev/null @@ -1,121 +0,0 @@ -const chalk = require('chalk'); -const babelMerge = require('babel-merge'); - -const defaultOptions = { - disableJSXPlus: process.env.DISABLE_JSX_PLUS, - styleSheet: false, -}; - -let logOnce = true; - -module.exports = (userOptions = {}) => { - const options = Object.assign({}, defaultOptions, userOptions); - const { styleSheet, disableJSXPlus, custom = {}, isSSR, disableRegenerator = false } = options; - - const baseConfig = { - presets: [ - require.resolve('@babel/preset-flow'), - [ - require.resolve('@babel/preset-env'), - { - targets: isSSR ? { - node: '8', - } : { - chrome: '49', - ios: '8', - }, - loose: true, - modules: 'auto', - include: [ - 'transform-computed-properties', - ], - }, - ], - [ - require.resolve('@babel/preset-react'), { - 'pragma': 'createElement', - 'pragmaFrag': 'Fragment', - 'throwIfNamespace': false, - }, - ], - ], - plugins: [ - [ - require.resolve('@babel/plugin-transform-runtime'), - { - 'corejs': false, - 'helpers': false, - 'regenerator': !disableRegenerator, - 'useESModules': false, - }, - ], - require.resolve('@babel/plugin-syntax-dynamic-import'), - // Stage 0 - require.resolve('@babel/plugin-proposal-function-bind'), - // Stage 1 - require.resolve('@babel/plugin-proposal-export-default-from'), - [ - require.resolve('@babel/plugin-proposal-optional-chaining'), - { loose: true }, - ], - [ - require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'), - { loose: true }, - ], - // Stage 2 - [require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }], - require.resolve('@babel/plugin-proposal-export-namespace-from'), - // Stage 3 - [ - require.resolve('@babel/plugin-proposal-class-properties'), - { loose: true }, - ], - require.resolve('babel-plugin-minify-dead-code-elimination-while-loop-fixed'), - ], - }; - - const configArr = [baseConfig]; - - if (isSSR) { - // Must transform before other jsx transformer - configArr.push({ - plugins: [ - require.resolve('babel-plugin-transform-jsx-to-html'), - ], - }); - } - - // Enable jsx plus default. - if (!disableJSXPlus) { - configArr.push({ - plugins: [ - require.resolve('babel-plugin-transform-jsx-list'), - require.resolve('babel-plugin-transform-jsx-condition'), - require.resolve('babel-plugin-transform-jsx-memo'), - require.resolve('babel-plugin-transform-jsx-slot'), - [require.resolve('babel-plugin-transform-jsx-fragment'), { moduleName: 'rax' }], - require.resolve('babel-plugin-transform-jsx-class'), - ], - }); - - if (logOnce) { - console.log(chalk.green('JSX+ enabled, documentation: https://rax.js.org/docs/guide/jsxplus')); - logOnce = false; - } - } - - if (styleSheet) { - configArr.push({ - plugins: [ - [require.resolve('babel-plugin-transform-jsx-stylesheet'), { retainClassName: true }], - ], - }); - } - - // merge custom config - configArr.push(custom); - - const result = babelMerge.all(configArr); - - return result; -}; diff --git a/packages/rax-compile-config/src/getRouteName.js b/packages/rax-compile-config/src/getRouteName.js deleted file mode 100644 index 026c8d883..000000000 --- a/packages/rax-compile-config/src/getRouteName.js +++ /dev/null @@ -1,27 +0,0 @@ -const path = require('path'); -const fs = require('fs-extra'); - -module.exports = (route, rootDir) => { - if (route.name) { - return route.name; - } - - const appConfig = fs.readJsonSync(path.resolve(rootDir, 'src/app.json')); - - const routeName = appConfig.routeName ? appConfig.routeName : 'path'; - - if (routeName === 'path') { - return route.source.replace(/\//g, '_'); - } - - if (routeName === 'pages') { - try { - // get Home from pages/Home/index or pages/Home - const name = route.source.match(/pages\/([^/]*)/); - return name[1]; - } catch (e) { - console.error('"routeName": "pages" mode request routes in /pages directory'); - process.exit(1); - } - } -}; diff --git a/packages/rax-compile-config/src/handleWebpackErr.js b/packages/rax-compile-config/src/handleWebpackErr.js deleted file mode 100644 index df7f4116b..000000000 --- a/packages/rax-compile-config/src/handleWebpackErr.js +++ /dev/null @@ -1,45 +0,0 @@ -const chalk = require('chalk'); - -module.exports = (err, stats) => { - if (err) { - console.error(err.stack || err); - if (err.details) { - console.error(err.details); - } - return false; - } - - if (stats && stats.hasErrors()) { - let errArr = []; - try { - errArr = stats.stats.map(v => v.compilation.errors); - } catch (e) { - errArr = [stats.compilation.errors]; - } - - for (const errors of errArr) { - for (const e of errors) { - let errMessage; - let errStack; - - try { - errMessage = e.message; - errStack = e.stack; - } catch (_err) { - errMessage = e.error.message; - errStack = e.error.stack; - } - - console.log(chalk.red(` ${errors.indexOf(e) + 1}. ${errMessage} \n`)); - if (process.env.DEBUG === 'true') { - console.log(errStack); - } - } - } - - console.log(chalk.yellow('Set environment `DEBUG=true` to see detail error stacks.')); - return false; - } - - return true; -}; diff --git a/packages/rax-compile-config/src/hmr/formatWebpackMessages.js b/packages/rax-compile-config/src/hmr/formatWebpackMessages.js deleted file mode 100644 index 5f8949450..000000000 --- a/packages/rax-compile-config/src/hmr/formatWebpackMessages.js +++ /dev/null @@ -1,124 +0,0 @@ - - -// WARNING: this code is untranspiled and is used in browser too. -// Please make sure any changes are in ES5 or contribute a Babel compile step. - -// Some custom utilities to prettify Webpack output. -// This is quite hacky and hopefully won't be needed when Webpack fixes this. -// https://github.com/webpack/webpack/issues/2878 - -const chalk = require('chalk'); - -const friendlySyntaxErrorLabel = 'Syntax error:'; - -function isLikelyASyntaxError(message) { - return message.indexOf(friendlySyntaxErrorLabel) !== -1; -} - -// Cleans up webpack error messages. -// eslint-disable-next-line no-unused-vars -function formatMessage(message, isError) { - let lines = message.split('\n'); - - if (lines.length > 2 && lines[1] === '') { - // Remove extra newline. - lines.splice(1, 1); - } - - // Remove webpack-specific loader notation from filename. - // Before: - // ./~/css-loader!./~/postcss-loader!./src/App.css - // After: - // ./src/App.css - if (lines[0].lastIndexOf('!') !== -1) { - lines[0] = lines[0].substr(lines[0].lastIndexOf('!') + 1); - } - - lines = lines.filter(function(line) { - // Webpack adds a list of entry points to warning messages: - // @ ./src/index.js - // @ multi react-scripts/~/react-dev-utils/webpackHotDevClient.js ... - // It is misleading (and unrelated to the warnings) so we clean it up. - // It is only useful for syntax errors but we have beautiful frames for them. - return line.indexOf(' @ ') !== 0; - }); - - // line #0 is filename - // line #1 is the main error message - if (!lines[0] || !lines[1]) { - return lines.join('\n'); - } - - // Cleans up verbose "module not found" messages for files and packages. - if (lines[1].indexOf('Module not found: ') === 0) { - lines = [ - lines[0], - // Clean up message because "Module not found: " is descriptive enough. - lines[1] - .replace("Cannot resolve 'file' or 'directory' ", '') - .replace('Cannot resolve module ', '') - .replace('Error: ', '') - .replace('[CaseSensitivePathsPlugin] ', ''), - ]; - } - - // Cleans up syntax error messages. - if (lines[1].indexOf('Module build failed: ') === 0) { - lines[1] = lines[1].replace( - 'Module build failed: SyntaxError:', - friendlySyntaxErrorLabel, - ); - } - - // Clean up export errors. - // TODO: we should really send a PR to Webpack for this. - const exportError = /\s*(.+?)\s*(")?export '(.+?)' was not found in '(.+?)'/; - if (lines[1].match(exportError)) { - lines[1] = lines[1].replace( - exportError, - "$1 '$4' does not contain an export named '$3'.", - ); - } - - lines[0] = chalk.inverse(lines[0]); - - // Reassemble the message. - message = lines.join('\n'); - // Internal stacks are generally useless so we strip them... with the - // exception of stacks containing `webpack:` because they're normally - // from user code generated by WebPack. For more information see - // https://github.com/facebookincubator/create-react-app/pull/1050 - message = message.replace( - /^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, - '', - ); // at ... ...:x:y - - return message.trim(); -} - -function formatWebpackMessages(json) { - const formattedErrors = json.errors.map(function(message) { - return formatMessage(message, true); - }); - const formattedWarnings = json.warnings.map(function(message) { - return formatMessage(message, false); - }); - const result = { - errors: formattedErrors, - warnings: formattedWarnings, - }; - if (result.errors.some(isLikelyASyntaxError)) { - // If there are any syntax errors, show just them. - // This prevents a confusing ESLint parsing error - // preceding a much more useful Babel syntax error. - result.errors = result.errors.filter(isLikelyASyntaxError); - } - // Only keep the first error. Others are often indicative - // of the same problem, but confuse the reader with noise. - if (result.errors.length > 1) { - result.errors.length = 1; - } - return result; -} - -module.exports = formatWebpackMessages; diff --git a/packages/rax-compile-config/src/hmr/moduleHotAccept.loader.js b/packages/rax-compile-config/src/hmr/moduleHotAccept.loader.js deleted file mode 100644 index b8e8739e1..000000000 --- a/packages/rax-compile-config/src/hmr/moduleHotAccept.loader.js +++ /dev/null @@ -1,49 +0,0 @@ - - -const loaderUtils = require('loader-utils'); - -/** - * append 'modult.hot.accept()' to entry point source. - */ -module.exports = function(source, inputMap) { - if (this.cacheable) { - this.cacheable(true); - } - - const callback = this.async(); - - if (/\bmodule.hot\b/.test(source)) { - return callback(null, source, inputMap); - } - - const options = loaderUtils.getOptions(this); - const resourcePath = this.resourcePath; - const resourcePathInEntry = options.appIndex && options.appIndex.startsWith(resourcePath); - - if (!resourcePathInEntry) { - return callback(null, source, inputMap); - } - - return callback( - null, - `${source} - -// HMR append by rax-scripts/loaders/module-hot-accept.js -// @see https://github.com/raxjs/rax-scripts -if (module.hot) { - module.hot.accept(function(err) { - if (err) { - console.log(err); - } else { - if (typeof App !== 'undefined') { - render() - } else { - console.error('\`App\` components must exist!') - } - } - }); -} -`, - inputMap, - ); -}; diff --git a/packages/rax-compile-config/src/hmr/webpackHotDevClient.entry.js b/packages/rax-compile-config/src/hmr/webpackHotDevClient.entry.js deleted file mode 100644 index 4278a18d1..000000000 --- a/packages/rax-compile-config/src/hmr/webpackHotDevClient.entry.js +++ /dev/null @@ -1,209 +0,0 @@ - - -const stripAnsi = require('strip-ansi'); -const formatWebpackMessages = require('./formatWebpackMessages'); - -let wsProtocol = 'ws'; -if (process.env.SOCK_PROTOCOL) { - wsProtocol = process.env.SOCK_PROTOCOL; -} else if (window.location.protocol === 'https:') { - wsProtocol = 'wss'; -} - -const wsHost = process.env.SOCK_HOST || window.location.hostname; -const wsPort = process.env.SOCK_PORT || window.location.port; - -const wsUrl = `${wsProtocol}://${wsHost}:${wsPort}/sockjs-node/websocket`; -// Connect to WebpackDevServer via a socket. -const connection = new WebSocket(wsUrl); - -// Unlike WebpackDevServer client, we won't try to reconnect -// to avoid spamming the console. Disconnect usually happens -// when developer stops the server. -connection.onclose = function() { - console.info('The development server has disconnected.\nRefresh the page if necessary.'); -}; - -connection.onopen = function() { - console.info('The development server has connected!'); -}; - -connection.onerror = function() { - console.info('The development server connect faild!'); -}; - -// Remember some state related to hot module replacement. -let isFirstCompilation = true; -let mostRecentCompilationHash = null; -let hasCompileErrors = false; - -function clearOutdatedErrors() { - // Clean up outdated compile errors, if any. - if (hasCompileErrors && typeof console.clear === 'function') { - console.clear(); - } -} - -// Successful compilation. -function handleSuccess() { - clearOutdatedErrors(); - - const isHotUpdate = !isFirstCompilation; - isFirstCompilation = false; - hasCompileErrors = false; - - // Attempt to apply hot updates or reload. - if (isHotUpdate) { - tryApplyUpdates(function onHotUpdateSuccess() { - // Only destroy it when we're sure it's a hot update. - // Otherwise it would flicker right before the reload. - }); - } -} - -// Compilation with warnings (e.g. ESLint). -function handleWarnings(warnings) { - clearOutdatedErrors(); - - const isHotUpdate = !isFirstCompilation; - isFirstCompilation = false; - hasCompileErrors = false; - - function printWarnings() { - // Print warnings to the console. - const formatted = formatWebpackMessages({ - warnings, - errors: [], - }); - - for (let i = 0; i < formatted.warnings.length; i++) { - console.warn(stripAnsi(formatted.warnings[i])); - } - } - - // Attempt to apply hot updates or reload. - if (isHotUpdate) { - tryApplyUpdates(function onSuccessfulHotUpdate() { - // Only print warnings if we aren't refreshing the page. - // Otherwise they'll disappear right away anyway. - printWarnings(); - // Only destroy it when we're sure it's a hot update. - // Otherwise it would flicker right before the reload. - }); - } else { - // Print initial warnings immediately. - printWarnings(); - } -} - -// Compilation with errors (e.g. syntax error or missing modules). -function handleErrors(errors) { - clearOutdatedErrors(); - - isFirstCompilation = false; - hasCompileErrors = true; - - // "Massage" webpack messages. - const formatted = formatWebpackMessages({ - errors, - warnings: [], - }); - - // Also log them to the console. - for (let i = 0; i < formatted.errors.length; i++) { - console.error(stripAnsi(formatted.errors[i])); - } - - // Do not attempt to reload now. - // We will reload on next success instead. -} - -// There is a newer version of the code available. -function handleAvailableHash(hash) { - // Update last known compilation hash. - mostRecentCompilationHash = hash; -} - -// Handle messages from the server. -connection.onmessage = function(e) { - const message = JSON.parse(e.data); - switch (message.type) { - case 'hash': - handleAvailableHash(message.data); - break; - case 'still-ok': - case 'ok': - handleSuccess(); - break; - case 'content-changed': - // Triggered when a file from `contentBase` changed. - window.location.reload(); - break; - case 'warnings': - handleWarnings(message.data); - break; - case 'errors': - handleErrors(message.data); - break; - default: - // Do nothing. - } -}; - -// Is there a newer version of this code available? -function isUpdateAvailable() { - /* globals __webpack_hash__ */ - // __webpack_hash__ is the hash of the current compilation. - // It's a global variable injected by Webpack. - return mostRecentCompilationHash !== __webpack_hash__; // eslint-disable-line -} - -// Webpack disallows updates in other states. -function canApplyUpdates() { - return module.hot.status() === 'idle'; -} - -// Attempt to update code on the fly, fall back to a hard reload. -function tryApplyUpdates(onHotUpdateSuccess) { - if (!module.hot) { - // HotModuleReplacementPlugin is not in Webpack configuration. - window.location.reload(); - return; - } - - if (!isUpdateAvailable() || !canApplyUpdates()) { - return; - } - - function handleApplyUpdates(err, updatedModules) { - if (err || !updatedModules) { - window.location.reload(); - return; - } - - if (typeof onHotUpdateSuccess === 'function') { - // Maybe we want to do something. - onHotUpdateSuccess(); - } - - if (isUpdateAvailable()) { - // While we were updating, there was a new update! Do it again. - tryApplyUpdates(); - } - } - - // https://webpack.github.io/docs/hot-module-replacement.html#check - const result = module.hot.check(/* autoApply */ true, handleApplyUpdates); - - // // Webpack 2 returns a Promise instead of invoking a callback - if (result && result.then) { - result.then( - function(updatedModules) { - handleApplyUpdates(null, updatedModules); - }, - function(err) { - handleApplyUpdates(err, null); - }, - ); - } -} diff --git a/packages/rax-compile-config/src/index.js b/packages/rax-compile-config/src/index.js deleted file mode 100644 index 0f12ec48d..000000000 --- a/packages/rax-compile-config/src/index.js +++ /dev/null @@ -1,16 +0,0 @@ -const getBabelConfig = require('./getBabelConfig'); -const setBabelAlias = require('./setBabelAlias'); -const handleWebpackErr = require('./handleWebpackErr'); -const getRouteName = require('./getRouteName'); -const platformLoader = require('./platformLoader'); - -const hmrClient = require.resolve('./hmr/webpackHotDevClient.entry'); - -module.exports = { - getRouteName, - getBabelConfig, - setBabelAlias, - hmrClient, - handleWebpackErr, - platformLoader, -}; diff --git a/packages/rax-compile-config/src/setBabelAlias.js b/packages/rax-compile-config/src/setBabelAlias.js deleted file mode 100644 index 15665e9a6..000000000 --- a/packages/rax-compile-config/src/setBabelAlias.js +++ /dev/null @@ -1,8 +0,0 @@ -const path = require('path'); - -module.exports = (config) => { - config.resolve.alias - .set('babel-runtime-jsx-plus', require.resolve('babel-runtime-jsx-plus')) - // @babel/runtime has no index - .set('@babel/runtime', path.dirname(require.resolve('@babel/runtime/package.json'))); -}; From 7bc02ff77bfe4a9f72d4bf34f837b47ec847f9ed Mon Sep 17 00:00:00 2001 From: fushen Date: Thu, 12 Nov 2020 11:11:42 +0800 Subject: [PATCH 2/3] chore: lint --- packages/platform-loader/package.json | 2 +- packages/platform-loader/src/TraverseImport.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/platform-loader/package.json b/packages/platform-loader/package.json index d90cc925d..e0c57a311 100644 --- a/packages/platform-loader/package.json +++ b/packages/platform-loader/package.json @@ -1,6 +1,6 @@ { "name": "rax-platform-loader", - "version": "1.0.0", + "version": "1.0.0-0", "description": "rax platform loader for helping remove other platform code", "license": "BSD-3-Clause", "main": "lib/index.js", diff --git a/packages/platform-loader/src/TraverseImport.js b/packages/platform-loader/src/TraverseImport.js index baf895986..f10ecfe52 100644 --- a/packages/platform-loader/src/TraverseImport.js +++ b/packages/platform-loader/src/TraverseImport.js @@ -112,8 +112,8 @@ module.exports = function traverseImport(options, inputSource, sourceMapOption) // remove trailing "(LINE:COLUMN)" acorn message and add in esprima syntax error message start console.log(`Line ${err.lineNumber}: ${err.message.replace(/ \((\d+):(\d+)\)$/, '') // add codeframe - }\n\n${ - codeFrameColumns(inputSource, location, { highlightCode: true })}`); + }\n\n${ + codeFrameColumns(inputSource, location, { highlightCode: true })}`); } else { console.log(err); } From 78d8b09545365c9b454164607819af8ab1899214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=B4=E6=BE=9C?= Date: Thu, 12 Nov 2020 16:01:04 +0800 Subject: [PATCH 3/3] Update package.json --- packages/platform-loader/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/platform-loader/package.json b/packages/platform-loader/package.json index e0c57a311..d90cc925d 100644 --- a/packages/platform-loader/package.json +++ b/packages/platform-loader/package.json @@ -1,6 +1,6 @@ { "name": "rax-platform-loader", - "version": "1.0.0-0", + "version": "1.0.0", "description": "rax platform loader for helping remove other platform code", "license": "BSD-3-Clause", "main": "lib/index.js",