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

build(webpack): update webpack loader configure, to avoid umd bundle error #1695

Merged
merged 1 commit into from
Oct 9, 2020
Merged
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: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -136,4 +138,4 @@
}
],
"license": "MIT"
}
}
54 changes: 32 additions & 22 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -20,38 +40,28 @@ 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$/,
/** bable 只需要处理 node_modules 中的 es6 模块,src 中的交给 ts-loader 即可 */
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: [
Expand Down