123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- const path = require('path');
- const webpack = require('webpack');
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
- const CopyWebpackPlugin = require('copy-webpack-plugin');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const ProgressBarPlugin = require('progress-bar-webpack-plugin');
- const VueLoaderPlugin = require('vue-loader/lib/plugin');
- const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
- const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
- const config = require('./config');
- const isProd = process.env.NODE_ENV === 'production';
- const isPlay = !!process.env.PLAY_ENV;
- const webpackConfig = {
- mode: process.env.NODE_ENV,
- entry: isProd ? {
- docs: './examples/entry.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,
- publicPath: '/',
- hot: true
- },
- performance: {
- hints: false
- },
- stats: {
- children: false
- },
- module: {
- rules: [
- {
- enforce: 'pre',
- test: /\.(vue|jsx?)$/,
- exclude: /node_modules/,
- loader: 'eslint-loader'
- },
- {
- test: /\.(jsx?|babel|es6)$/,
- include: process.cwd(),
- exclude: config.jsexclude,
- loader: 'babel-loader'
- },
- {
- test: /\.vue$/,
- loader: 'vue-loader',
- options: {
- compilerOptions: {
- preserveWhitespace: false
- }
- }
- },
- {
- test: /\.(scss|css)$/,
- use: [
- isProd ? MiniCssExtractPlugin.loader : 'style-loader',
- 'css-loader',
- 'sass-loader'
- ]
- },
- {
- test: /\.md$/,
- use: [
- {
- loader: 'vue-loader',
- options: {
- compilerOptions: {
- preserveWhitespace: false
- }
- }
- },
- {
- loader: path.resolve(__dirname, './md-loader/index.js')
- }
- ]
- },
- {
- test: /\.(svg|otf|ttf|woff2?|eot|gif|png|jpe?g)(\?\S*)?$/,
- loader: 'url-loader',
- // todo: 这种写法有待调整
- query: {
- limit: 10000,
- name: path.posix.join('static', '[name].[hash:7].[ext]')
- }
- }
- ]
- },
- plugins: [
- new webpack.HotModuleReplacementPlugin(),
- new HtmlWebpackPlugin({
- template: './examples/index.tpl',
- filename: './index.html',
- favicon: './examples/favicon.ico'
- }),
- new CopyWebpackPlugin([
- { from: 'examples/versions.json' }
- ]),
- new ProgressBarPlugin(),
- new VueLoaderPlugin(),
- new webpack.DefinePlugin({
- 'process.env.FAAS_ENV': JSON.stringify(process.env.FAAS_ENV)
- }),
- new webpack.LoaderOptionsPlugin({
- vue: {
- compilerOptions: {
- preserveWhitespace: false
- }
- }
- })
- ],
- optimization: {
- minimizer: []
- },
- devtool: '#eval-source-map'
- };
- if (isProd) {
- webpackConfig.externals = {
- vue: 'Vue',
- 'vue-router': 'VueRouter',
- 'highlight.js': 'hljs'
- };
- webpackConfig.plugins.push(
- new MiniCssExtractPlugin({
- filename: '[name].[contenthash:7].css'
- })
- );
- webpackConfig.optimization.minimizer.push(
- new UglifyJsPlugin({
- cache: true,
- parallel: true,
- sourceMap: false
- }),
- new OptimizeCSSAssetsPlugin({})
- );
- // https://webpack.js.org/configuration/optimization/#optimizationsplitchunks
- webpackConfig.optimization.splitChunks = {
- cacheGroups: {
- vendor: {
- test: /\/src\//,
- name: 'element-ui',
- chunks: 'all'
- }
- }
- };
- webpackConfig.devtool = false;
- }
- module.exports = webpackConfig;
|