From e4d4f79e95f5c394a412726898989d898519673e Mon Sep 17 00:00:00 2001 From: hustcc Date: Fri, 9 Oct 2020 20:21:31 +0800 Subject: [PATCH] build(webpack): update webpack loader configure --- package.json | 4 +++- webpack.config.js | 54 ++++++++++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index b073533bff..e1899bd390 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,9 @@ "devDependencies": { "@antv/gatsby-theme-antv": "^1.0.0-beta.8", "@babel/core": "^7.10.4", + "@babel/plugin-transform-runtime": "^7.11.5", "@babel/preset-env": "^7.10.4", + "@babel/runtime": "^7.11.2", "@commitlint/cli": "^8.2.0", "@commitlint/config-angular": "^8.2.0", "@types/jest": "^25.2.1", @@ -136,4 +138,4 @@ } ], "license": "MIT" -} \ No newline at end of file +} diff --git a/webpack.config.js b/webpack.config.js index 38268e6231..f39f479dc3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,6 +2,26 @@ const webpack = require('webpack'); const resolve = require('path').resolve; const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; +const BABEL_OPTIONS = { + presets: [ + [ + '@babel/preset-env', + { + targets: '> 0.25%, not dead', + }, + ], + ], + plugins: [ + [ + '@babel/transform-runtime', + { + helpers: false, + regenerator: true, + }, + ], + ], +}; + module.exports = { entry: { g2plot: './src/index.ts', @@ -20,12 +40,18 @@ module.exports = { rules: [ { test: /\.ts$/, - use: { - loader: 'ts-loader', - options: { - transpileOnly: true, + use: [ + { + loader: 'babel-loader', + options: BABEL_OPTIONS, }, - }, + { + loader: 'ts-loader', + options: { + transpileOnly: true, + }, + }, + ] }, { test: /\.js$/, @@ -33,25 +59,9 @@ module.exports = { include: /node_modules/, use: { loader: 'babel-loader', - options: { - presets: ['@babel/preset-env'], - }, + options: BABEL_OPTIONS, }, }, - { - test: /\.less$/, - use: [ - { - loader: 'style-loader', // creates style nodes from JS strings - }, - { - loader: 'css-loader', // translates CSS into CommonJS - }, - { - loader: 'less-loader', // compiles Less to CSS - }, - ], - }, ], }, plugins: [