2018-05-21 15:26:46 +08:00
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
2019-01-23 11:34:19 +08:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2018-05-21 15:26:46 +08:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
|
2019-01-23 11:34:19 +08:00
|
|
|
const VueLoaderPlugin = require('vue-loader/lib/plugin');
|
2019-02-20 19:06:18 +08:00
|
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
|
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
2018-05-21 15:26:46 +08:00
|
|
|
|
|
|
|
const config = require('./config');
|
|
|
|
|
|
|
|
const isProd = process.env.NODE_ENV === 'production';
|
|
|
|
const isPlay = !!process.env.PLAY_ENV;
|
|
|
|
|
|
|
|
const webpackConfig = {
|
2019-01-23 11:34:19 +08:00
|
|
|
mode: process.env.NODE_ENV,
|
2018-05-21 15:26:46 +08:00
|
|
|
entry: isProd ? {
|
|
|
|
docs: './examples/entry.js',
|
|
|
|
'element-ui': './src/index.js'
|
|
|
|
} : (isPlay ? './examples/play.js' : './examples/entry.js'),
|
|
|
|
output: {
|
|
|
|
path: path.resolve(process.cwd(), './examples/element-ui/'),
|
|
|
|
publicPath: process.env.CI_ENV || '',
|
|
|
|
filename: '[name].[hash:7].js',
|
|
|
|
chunkFilename: isProd ? '[name].[hash:7].js' : '[name].js'
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.vue', '.json'],
|
|
|
|
alias: config.alias,
|
|
|
|
modules: ['node_modules']
|
|
|
|
},
|
|
|
|
devServer: {
|
|
|
|
host: '0.0.0.0',
|
|
|
|
port: 8085,
|
2019-04-09 18:08:28 +08:00
|
|
|
publicPath: '/'
|
2018-05-21 15:26:46 +08:00
|
|
|
},
|
2019-01-23 11:34:19 +08:00
|
|
|
performance: {
|
|
|
|
hints: false
|
|
|
|
},
|
|
|
|
stats: {
|
|
|
|
children: false
|
|
|
|
},
|
2018-05-21 15:26:46 +08:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
enforce: 'pre',
|
2019-01-23 11:34:19 +08:00
|
|
|
test: /\.(vue|jsx?)$/,
|
|
|
|
exclude: /node_modules/,
|
2018-05-21 15:26:46 +08:00
|
|
|
loader: 'eslint-loader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(jsx?|babel|es6)$/,
|
|
|
|
include: process.cwd(),
|
|
|
|
exclude: config.jsexclude,
|
|
|
|
loader: 'babel-loader'
|
|
|
|
},
|
|
|
|
{
|
2019-01-23 11:34:19 +08:00
|
|
|
test: /\.vue$/,
|
|
|
|
loader: 'vue-loader',
|
2018-05-21 15:26:46 +08:00
|
|
|
options: {
|
2019-01-23 11:34:19 +08:00
|
|
|
compilerOptions: {
|
|
|
|
preserveWhitespace: false
|
2018-05-21 15:26:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2019-02-26 16:23:26 +08:00
|
|
|
test: /\.(scss|css)$/,
|
|
|
|
use: [
|
2019-01-23 11:34:19 +08:00
|
|
|
isProd ? MiniCssExtractPlugin.loader : 'style-loader',
|
|
|
|
'css-loader',
|
|
|
|
'sass-loader'
|
|
|
|
]
|
2018-05-21 15:26:46 +08:00
|
|
|
},
|
|
|
|
{
|
2019-01-23 11:34:19 +08:00
|
|
|
test: /\.md$/,
|
2019-03-01 18:35:08 +08:00
|
|
|
use: [
|
2019-01-23 11:34:19 +08:00
|
|
|
{
|
2019-03-01 18:35:08 +08:00
|
|
|
loader: 'vue-loader',
|
2019-01-23 11:34:19 +08:00
|
|
|
options: {
|
2019-03-01 18:35:08 +08:00
|
|
|
compilerOptions: {
|
|
|
|
preserveWhitespace: false
|
|
|
|
}
|
2019-01-23 11:34:19 +08:00
|
|
|
}
|
2019-03-01 18:35:08 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: path.resolve(__dirname, './md-loader/index.js')
|
2019-01-23 11:34:19 +08:00
|
|
|
}
|
|
|
|
]
|
2018-05-21 15:26:46 +08:00
|
|
|
},
|
|
|
|
{
|
2019-01-23 11:34:19 +08:00
|
|
|
test: /\.(svg|otf|ttf|woff2?|eot|gif|png|jpe?g)(\?\S*)?$/,
|
2018-05-21 15:26:46 +08:00
|
|
|
loader: 'url-loader',
|
2019-03-01 18:35:08 +08:00
|
|
|
// todo: 这种写法有待调整
|
2018-05-21 15:26:46 +08:00
|
|
|
query: {
|
|
|
|
limit: 10000,
|
|
|
|
name: path.posix.join('static', '[name].[hash:7].[ext]')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: './examples/index.tpl',
|
|
|
|
filename: './index.html',
|
|
|
|
favicon: './examples/favicon.ico'
|
|
|
|
}),
|
|
|
|
new CopyWebpackPlugin([
|
|
|
|
{ from: 'examples/versions.json' }
|
|
|
|
]),
|
|
|
|
new ProgressBarPlugin(),
|
2019-01-23 11:34:19 +08:00
|
|
|
new VueLoaderPlugin(),
|
2019-02-28 16:00:59 +08:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.FAAS_ENV': JSON.stringify(process.env.FAAS_ENV)
|
|
|
|
}),
|
2018-05-21 15:26:46 +08:00
|
|
|
new webpack.LoaderOptionsPlugin({
|
|
|
|
vue: {
|
2019-01-23 11:34:19 +08:00
|
|
|
compilerOptions: {
|
|
|
|
preserveWhitespace: false
|
|
|
|
}
|
2018-05-21 15:26:46 +08:00
|
|
|
}
|
|
|
|
})
|
2019-02-20 19:06:18 +08:00
|
|
|
],
|
|
|
|
optimization: {
|
|
|
|
minimizer: []
|
2019-04-12 17:00:37 +08:00
|
|
|
},
|
|
|
|
devtool: '#eval-source-map'
|
2018-05-21 15:26:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
if (isProd) {
|
2019-03-01 18:35:08 +08:00
|
|
|
webpackConfig.externals = {
|
|
|
|
vue: 'Vue',
|
|
|
|
'vue-router': 'VueRouter',
|
|
|
|
'highlight.js': 'hljs'
|
|
|
|
};
|
2018-05-21 15:26:46 +08:00
|
|
|
webpackConfig.plugins.push(
|
2019-01-23 11:34:19 +08:00
|
|
|
new MiniCssExtractPlugin({
|
2018-05-21 15:26:46 +08:00
|
|
|
filename: '[name].[contenthash:7].css'
|
|
|
|
})
|
|
|
|
);
|
2019-02-20 19:06:18 +08:00
|
|
|
webpackConfig.optimization.minimizer.push(
|
|
|
|
new UglifyJsPlugin({
|
|
|
|
cache: true,
|
|
|
|
parallel: true,
|
|
|
|
sourceMap: false
|
|
|
|
}),
|
|
|
|
new OptimizeCSSAssetsPlugin({})
|
|
|
|
);
|
2019-04-12 17:00:37 +08:00
|
|
|
webpackConfig.devtool = false;
|
2018-05-21 15:26:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = webpackConfig;
|