【发布时间】:2017-12-01 15:48:35
【问题描述】:
我目前正在使用使用 babel+webpack 作为 es6 实现的应用程序。 我的 webpack 配置如下
` 常量 webpack = require('webpack'); const path = require('path');
const DEV = process.env.NODE_ENV !== 'production';
module.exports = {
bail: !DEV,
devtool: DEV ? 'cheap-module-source-map' : 'source-map',
target: 'node',
entry: './src/server/index.js',
output: {
path: path.join(__dirname,'build/server'),
filename: 'bundle.js',
publicPath: '/',
},
externals: (context, request, callback) => {
// Externalize all npm modules.
if (/^[a-z0-9-][a-z0-9-./]+$/.test(request)) {
return callback(null, `commonjs ${request}`);
}
callback();
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
// exclude: /(node_modules)/,
},
{
test: /\.json$/,
loader: 'json-loader',
},
{
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader',
},
{
test: /\.js/,
loader: 'import-glob',
exclude: /(node_modules)/
},
{
enforce: "pre",
test: /\.js$/,
exclude: /(node_modules)/,
loader: 'eslint-loader'
}
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(DEV ? 'development' : 'production'),
}),
],
node: {
console: false,
global: false,
process: false,
Buffer: false,
__filename: false,
__dirname: false,
setImmediate: false,
}
};
One of the modulenode-lyftis implemented in es6 format . when I tried to import the package it gives the es6 error which isimport 未定义`
【问题讨论】:
-
默认情况下忽略
/node_modules/下的任何内容。如果您希望 Babel 转换特定的第三方模块,您可以通过调整include或exclude选项来实现。
标签: javascript webpack ecmascript-6 babeljs