我正在使用以下webpack配置:
var path = require('path');
var webpack = require('webpack');
module.exports = {
plugins: [
new webpack.ProvidePlugin({
'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch'
})
],
entry: {
demo1 : ['babel-polyfill', './src/js/page/demo1.js']
},
output: {
path: 'dist/js/page',
filename: '[name].js'
},
devtool: 'eval-source-map',
module: {
loaders: [
{
test: /\.js$/,
include: [
path.resolve(__dirname, "src")
],
exclude: path.resolve(__dirname, "node_modules"),
loader: "babel-loader",
query: {
plugins: ['transform-runtime'],
presets: ['es2015', 'react']
}
},
{ test: /\.scss$/, loader: 'style!css!sass?sourceMap'}
]
},
resolve: {
root: path.resolve(__dirname, "src"),
extensions: ['', '.js', '.json', '.scss']
}
};
如此展示的,我将整个babel-polyfill模块与入口文件demo1.js合并以支持Array.from。但我认为这样做不是一个好主意,因为它会使入口文件变得更加沉重。
那么有没有适用于webpack的加载器/插件/预设,可以像babel-polyfill一样支持Array.from呢?
'transform-runtime'
。 - loganfsmythwebpack.config.js
中添加新的入口文件时都要添加babel-polyfill
(在使用插件的情况下,我只需要添加入口文件即可)。那么有没有插件可以替换transform-runtime
并支持Array.from
呢? - VaJoy Larn