|
|
import webpack,{DefinePlugin} from 'webpack';
|
|
|
import webpack, {DefinePlugin} from 'webpack';
|
|
|
import path from 'path';
|
|
|
import ExtractTextPlugin from "extract-text-webpack-plugin";
|
|
|
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
|
import CleanWebpackPlugin from 'clean-webpack-plugin';
|
|
|
import HtmlWebpackPlugin from "html-webpack-plugin";
|
|
|
import config from "./config";
|
...
|
...
|
@@ -17,7 +17,12 @@ let baseArr = [ |
|
|
new DefinePlugin({//全局变量
|
|
|
PRODUCTION: false
|
|
|
}),
|
|
|
new ExtractTextPlugin('css/[name].[chunkhash:8].css'),//css分离
|
|
|
new MiniCssExtractPlugin({
|
|
|
// Options similar to the same options in webpackOptions.output
|
|
|
// both options are optional
|
|
|
filename: "css/[name].css",
|
|
|
chunkFilename: "css/[id].css"
|
|
|
}),//css分离
|
|
|
new CleanWebpackPlugin(pathsToClean, cleanOptions),//清除历史版本
|
|
|
];
|
|
|
let htmls = function () {
|
...
|
...
|
@@ -46,7 +51,7 @@ module.exports = { |
|
|
//项目输出目录
|
|
|
output: {
|
|
|
chunkFilename: 'routes/[name].[chunkhash:8].chunk.js',
|
|
|
path: path.resolve(__dirname, 'build'),
|
|
|
path: path.resolve(__dirname, 'dist'),
|
|
|
filename: '[name].[chunkhash:8].js',
|
|
|
},
|
|
|
//插件
|
...
|
...
|
@@ -64,25 +69,13 @@ module.exports = { |
|
|
]
|
|
|
},
|
|
|
{
|
|
|
test:/\.css$/,
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
fallback: 'style-loader',
|
|
|
use: 'css-loader'
|
|
|
}),
|
|
|
},
|
|
|
{
|
|
|
test: /\.scss$/,
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
use: [{
|
|
|
loader: "css-loader"
|
|
|
}, {
|
|
|
loader: "sass-loader"
|
|
|
}, {
|
|
|
loader: "postcss-loader"
|
|
|
}],
|
|
|
// 在开发环境使用 style-loader
|
|
|
fallback: "style-loader"
|
|
|
})
|
|
|
test: /\.(sa|sc|c)ss$/,
|
|
|
use: [
|
|
|
MiniCssExtractPlugin.loader ,
|
|
|
'css-loader',
|
|
|
'postcss-loader',
|
|
|
'sass-loader',
|
|
|
],
|
|
|
},
|
|
|
{
|
|
|
test: /\.(png|jpg|gif)$/,
|
...
|
...
|
@@ -92,14 +85,14 @@ module.exports = { |
|
|
{test: /\.json$/, use: 'json-loader'}
|
|
|
]
|
|
|
},
|
|
|
devServer: {
|
|
|
devServer: {
|
|
|
publicPath: config.routerPath[config.currentApp],
|
|
|
port: 8080,
|
|
|
disableHostCheck: true,
|
|
|
},
|
|
|
devtool: "source-map",
|
|
|
//模块路径
|
|
|
resolve:{
|
|
|
resolve: {
|
|
|
alias: {
|
|
|
'@': path.resolve(__dirname, 'src')
|
|
|
}
|
...
|
...
|
|