配置webpack2 设置modules: false 找不到模块
今天配置的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']
},
]
},
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我查阅文档,并试了下,不论是
{resolve:{modules:false}}
还是{module:false}
,全是提示参数错误的。要补贴下webpack.config.js?我试了下,没问题,支持import/export
应该是babel的配置问题吧,module:false就不会对es6的语法(诸如:import)进行转换了,这里有说明:http://babeljs.io/docs/plugin...
看着像是没有配置 resolve 字段
resolve: {
},