|
| 1 | +const glob = require('glob'), |
| 2 | + path = require('path'), |
| 3 | + CompressionPlugin = require('compression-webpack-plugin'), |
| 4 | + ExtractTextPlugin = require('extract-text-webpack-plugin'), |
| 5 | + PurifyCSSPlugin = require('purifycss-webpack'), |
| 6 | + autoprefixer = require('autoprefixer'), |
| 7 | + webpackConfig = require('./webpack.config.base'), |
| 8 | + helpers = require('./helpers'), |
| 9 | + DefinePlugin = require('webpack/lib/DefinePlugin'), |
| 10 | + env = require('../environment/prod.env'); |
| 11 | + |
| 12 | +const extractSass = new ExtractTextPlugin({ |
| 13 | + filename: 'css/[name].[contenthash].css', |
| 14 | + disable: process.env.NODE_ENV === 'development' |
| 15 | +}); |
| 16 | + |
| 17 | +const purifyCss = new PurifyCSSPlugin({ |
| 18 | + paths: glob.sync(path.join(__dirname, '../src/**/*.html')), |
| 19 | + purifyOptions: { |
| 20 | + info: true, |
| 21 | + whitelist: [] |
| 22 | + } |
| 23 | +}); |
| 24 | + |
| 25 | +webpackConfig.output = { |
| 26 | + path: helpers.root('/dist'), |
| 27 | + filename: 'index.js', |
| 28 | + library: '[name]', |
| 29 | + libraryTarget: 'umd', |
| 30 | + umdNamedDefine: true |
| 31 | +}; |
| 32 | + |
| 33 | +webpackConfig.externals = { |
| 34 | + 'axios': 'axios', |
| 35 | + 'vue': 'vue', |
| 36 | + 'vue-class-component': 'vue-class-component', |
| 37 | + 'vue-property-decorator': 'vue-property-decorator', |
| 38 | + 'vue-router': 'vue-router' |
| 39 | +}; |
| 40 | + |
| 41 | +webpackConfig.module.rules = [...webpackConfig.module.rules, |
| 42 | + { |
| 43 | + test: /\.scss$/, |
| 44 | + use: extractSass.extract({ |
| 45 | + use: [{ |
| 46 | + loader: 'css-loader', |
| 47 | + options: { |
| 48 | + minimize: true, |
| 49 | + sourceMap: true, |
| 50 | + importLoaders: 2 |
| 51 | + } |
| 52 | + }, |
| 53 | + { |
| 54 | + loader: 'postcss-loader', |
| 55 | + options: { |
| 56 | + plugins: () => [autoprefixer] |
| 57 | + } |
| 58 | + }, |
| 59 | + { |
| 60 | + loader: 'sass-loader', |
| 61 | + options: { |
| 62 | + outputStyle: 'expanded', |
| 63 | + sourceMap: true, |
| 64 | + sourceMapContents: true |
| 65 | + } |
| 66 | + } |
| 67 | + ], |
| 68 | + // use style-loader in development |
| 69 | + fallback: 'style-loader' |
| 70 | + }) |
| 71 | + }, |
| 72 | + { |
| 73 | + test: /\.(jpg|png|gif)$/, |
| 74 | + loader: 'file-loader?name=assets/img/[name].[ext]' |
| 75 | + }, |
| 76 | + { |
| 77 | + test: /\.(eot|svg|ttf|woff|woff2)$/, |
| 78 | + loader: 'file-loader?name=fonts/[name].[ext]' |
| 79 | + } |
| 80 | +]; |
| 81 | + |
| 82 | +// ensure ts lint fails the build |
| 83 | +webpackConfig.module.rules[0].options = { |
| 84 | + failOnHint: true |
| 85 | +}; |
| 86 | + |
| 87 | +webpackConfig.plugins = [...webpackConfig.plugins, |
| 88 | + extractSass, |
| 89 | + purifyCss, |
| 90 | + new CompressionPlugin({ |
| 91 | + asset: '[path].gz[query]', |
| 92 | + test: /\.min\.js$/ |
| 93 | + }), |
| 94 | + new DefinePlugin({ |
| 95 | + 'process.env': env |
| 96 | + }) |
| 97 | +]; |
| 98 | + |
| 99 | +module.exports = webpackConfig; |
0 commit comments