今天配置的webpack2,想用一下对es6的import支持,在我{ modules: false }设置上时,然后编译酒会出现找不到模块的错误信息,明显是webpack2不能解析import语法,请问这是什么问题呢?
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin"); //CSS 模块加载
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://127.0.0.1:3001',
'webpack/hot/dev-server',
"./js/src/Unique_main.jsx"
],
output: {
path: path.join(__dirname, 'js/dist'),
// path: __dirname,
filename: "bundle.js",
publicPath: '/assets/',
chunkFilename: '[name].[chunkhash:10].chunk.js',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new ExtractTextPlugin({
filename: "Respectively.css",
disable: false,
allChunks: true
}),
new HtmlWebpackPlugin({ title: 'Tree-shaking' })
],
module: {
// loaders:[
rules: [
{
test: /\.jsx$/,
exclude: /node_modules/,
// loader: 'babel-loader',
use:[
{
loader:"babel-loader",
options: {
presets: ['es2015',{ modules: false },'stage-2'],
//按需加载模块,antd...
plugins:[["import",[
{
"libraryName": "antd",
"libraryDirectory": "lib",
"style": true
},
{
"libraryName": "antd-mobile",
"libraryDirectory": "component",
},
]],
"transform-decorators-legacy",
"transform-class-properties"
]
}
},
]
{
test:/\.css$/,
exclude:/node_modules/,
use:ExtractTextPlugin.extract({
fallback: "style-loader",
use:["css-loader"]
// publicPath: "/dist"
})
},
{
test:/\.(png|jpg|svg)$/,
use:['file-loader'],
},
{
test:/\.less$/,
use:['style-loader','css-loader','less-loader']
},
]
},
}
我查阅文档,并试了下,不论是
{resolve:{modules:false}}
还是{module:false}
,全是提示参数错误的。要补贴下webpack.config.js?我试了下,没问题,支持import/export