Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support webpack5 target's new type #6

Open
wants to merge 1 commit into
base: webpack5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NavigationPage {

getName() {
const modules = this.stat.compilation.modules;
const target = this.compiler.options.target;
const target = utils.getTarget(this.compiler.options.target);
if (target === 'node') {
return 'Server';
}
Expand Down Expand Up @@ -44,7 +44,7 @@ class NavigationPage {
resolve() {
const webpackConfig = this.compiler.options;
const easyInfo = easyHelper.getEasyInfo();
const target = webpackConfig.target || 'web';
const target = utils.getTarget(webpackConfig.target) || 'web';
const port = easyInfo[target].port || this.config.port - 1;
const publicPath = this.normalizePublicPath(webpackConfig.output.publicPath, port);
const assets = Object.keys(this.stat.compilation.assets).sort().map(name => {
Expand Down
4 changes: 2 additions & 2 deletions lib/tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class WebpackTool {
}

normalizeHotEntry(webpackConfig) {
const target = webpackConfig.target;
const target = utils.getTarget(webpackConfig.target);
if (target === 'web') {
const port = this.getPort(target);
utils.normalizeHotEntry(webpackConfig, port);
Expand Down Expand Up @@ -218,7 +218,7 @@ class WebpackTool {
createWebpackServer(compiler, options = {}) {
const offset = options.offset;
const webpackConfig = compiler.options;
const target = webpackConfig.target;
const target = utils.getTarget(webpackConfig.target);
const output = webpackConfig.output;
const { devServer = {} } = this.config;
const { before, after, historyApiFallback, proxy = {} } = devServer;
Expand Down
19 changes: 19 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,23 @@ utils.getWebpack = () => {
return require('webpack');
};

/**
* Why: https://webpack.js.org/configuration/target/
*
* @param {string|string[]|false} target
*/
utils.getTarget = (target) => {
if (typeof target === 'string') return target;
if (Array.isArray(target)) {
if (target.includes('web')) {
return 'web';
}
if (target.includes('node')) {
return 'node';
}
}

return target;
}

module.exports = utils;