Authored by huangyi

优化结构

... ... @@ -45,7 +45,7 @@
"compression-webpack-plugin": "^1.1.11",
"copy-webpack-plugin": "^4.5.1",
"css-loader": "^0.28.11",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"mini-css-extract-plugin":"^0.4.3",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"html-withimg-loader": "^0.1.16",
... ...
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')
}
... ...