如题:
webpack版本:3.0
编译是不通过:报错如下
如果把exclude: /node_modules/,去掉编译通过:但是浏览器报错如下:
webpack.base.config.js配置
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const SRC_PATH = path.resolve('./src');
const ASSETS_BUILD_PATH = path.resolve('./dist');
const ASSETS_PUBLIC_PATH = '/assets/';
module.exports = {
context: SRC_PATH,
entry: {
app: './app.js',
},
output: {
path: ASSETS_BUILD_PATH,
filename: './[name].js',
publicPath: ASSETS_PUBLIC_PATH,
chunkFilename: '[name].chunk.js',
},
resolve: {
extensions: ['.js', '.jsx', '.css', '.scss', '.vue'],
modules: ['node_modules', path.join(__dirname, './node_modules')],
},
module: {
rules:[]
},
plugins: [
new CleanWebpackPlugin([ASSETS_BUILD_PATH], { verbose: false }),
new webpack.optimize.ModuleConcatenationPlugin(),
new CopyWebpackPlugin([{
from: path.resolve(__dirname, './dll'),
to: ASSETS_BUILD_PATH,
ignore: ['.*'],
}]),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./manifest.json'),
}),
],
};
webpack.dev.config.js配置文件
const webpack = require('webpack');
const path = require('path');
const config = require('./webpack.base.config.js');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
config.devServer = {
contentBase: './',
hot: true,
publicPath: '/assets/'
};
config.module.rules.push({
test: /.js(x)*$/,
exclude: /node_modules/,
loader: 'babel-loader?cacheDirectory=true'
}, {
test: /\.json$/,
loader: 'json-loader?cacheDirectory=true',
},{
test: /\.css$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader']
})
}, {
test: /\.(sass|scss)$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
});
Object.keys(config.entry).forEach((key) => {
if (Array.isArray(config.entry[key])) {
config.entry[key].unshift(
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server'
);
}
});
config.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new ExtractTextPlugin({
filename: '[name].css',
allChunks: true,
ignoreOrder: true
})
);
module.exports = config;