forked from jd-opensource/nutui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.base.conf.js
116 lines (115 loc) · 3.81 KB
/
webpack.base.conf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const webpack = require('webpack');
const config = require('../package.json');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const moment = require('moment');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
var WebpackBuildNotifierPlugin = require('webpack-build-notifier');
const isDev = process.env.NODE_ENV === 'development';
var test = process.env.NODE_ENV === 'test';
const path = require('path');
const HappyPack = require('happypack');
const os = require('os');
const chalk= require('chalk');
const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
module.exports = {
stats: {
entrypoints: false,
children: false
},
stats: 'errors-only',
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
}
},
module: {
rules: [
!test ? {
test: /\.(sa|sc|c)ss$/,
use: [
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
{
loader: 'sass-loader',
options: {
data: `@import "./src/styles/index.scss"; `,
},
}
],
}:{},
{
test: /\.svg$/,
use: 'raw-loader'
},
{
test: /\.vue$/,
use: [
'cache-loader',
{
loader: 'vue-loader',
options: {
/* preLoaders: {
js: 'istanbul-instrumenter-loader?esModules=true'
}, */
loaders: {
sass: [isDev ? 'style-loader' : MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader', 'postcss-loader']
}
}
}
]
},
{
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /node_modules/
},
{
test: /\.js$/,
exclude: /node_modules/,
use: ['happypack/loader?id=Babel']
},
{
test: /\.(png|jpg|gif|webp)$/,
loader: 'url-loader',
options: {
limit: 3000,
name: 'img/[name].[ext]',
}
},]
},
plugins: [
new webpack.BannerPlugin({
banner: `NutUI v${config.version} - [filebase], [hash], ${moment().format()}
(c) 2017-2019 JDC
Released under the MIT License.`
}),
new HappyPack({
//用id来标识 happypack处理那里类文件
id: 'Babel',
//如何处理 用法和loader 的配置一样
loaders: [{
loader: 'babel-loader?cacheDirectory=true',
}],
//共享进程池
threadPool: happyThreadPool,
//允许 HappyPack 输出日志
verbose: false,
}),
new VueLoaderPlugin(),
new ProgressBarPlugin({
format: ' build [:bar] ' + chalk.green.bold(':percent') + ' (:elapsed seconds)',
clear: false,
width: 100
}),
new WebpackBuildNotifierPlugin({
title: "NutUI Webpack Build",
suppressSuccess: true
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
],
}