|
| 1 | +const path = require('path') |
| 2 | +const HtmlWebpackPlugin = require('html-webpack-plugin') |
| 3 | + |
| 4 | +const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin') |
| 5 | +// Cleans dist folder before building for fresh build |
| 6 | +const { CleanWebpackPlugin } = require('clean-webpack-plugin') |
| 7 | +const { VueLoaderPlugin } = require('vue-loader') |
| 8 | +// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin |
| 9 | +const PurgecssPlugin = require('purgecss-webpack-plugin') |
| 10 | +const WebpackPwaManifest = require('webpack-pwa-manifest'); |
| 11 | +const glob = require('glob-all') |
| 12 | + |
| 13 | +// Custom PurgeCSS extractor for Tailwind that allows special characters in |
| 14 | +// class names. |
| 15 | +// |
| 16 | +// https://github.com/FullHuman/purgecss#extractor |
| 17 | +class TailwindExtractor { |
| 18 | + static extract (content) { |
| 19 | + return content.match(/[A-z0-9-:\/]+/g) || [] |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +module.exports = env => { |
| 24 | + return { |
| 25 | + mode: env.NODE_ENV === 'prod' ? 'production' : 'development', |
| 26 | + resolve: { |
| 27 | + extensions: ['.vue', '.css', '.js'] |
| 28 | + }, |
| 29 | + node: { |
| 30 | + fs: 'empty' |
| 31 | + }, |
| 32 | + entry: { |
| 33 | + 'main': './src/main.js' |
| 34 | + }, |
| 35 | + output: { |
| 36 | + filename: 'bundle.js?[hash]', |
| 37 | + publicPath: env.NODE_ENV === 'prod' ? './' : '/' |
| 38 | + }, |
| 39 | + devServer: { |
| 40 | + contentBase: path.join(__dirname, 'dist'), |
| 41 | + port: 8081, |
| 42 | + historyApiFallback: true, |
| 43 | + // Enable to allow other (than localhost) machines to access the aepp on your computer |
| 44 | + disableHostCheck: false, |
| 45 | + host: '0.0.0.0' |
| 46 | + }, |
| 47 | + devtool: env.NODE_ENV === 'prod' ? '' : 'eval-source-map', |
| 48 | + plugins: [ |
| 49 | + new HtmlWebpackPlugin({ |
| 50 | + inject: true, |
| 51 | + // chunks: ['main'], |
| 52 | + title: 'Governance Aepp', |
| 53 | + template: './src/index.html', |
| 54 | + filename: path.join(__dirname, 'dist', 'index.html'), |
| 55 | + // Avoids building twice for dev |
| 56 | + alwaysWriteToDisk: true |
| 57 | + }), |
| 58 | + new PurgecssPlugin({ |
| 59 | + // Specify the locations of any files you want to scan for class names. |
| 60 | + paths: glob.sync([ |
| 61 | + path.join(__dirname, './src/**/*.vue'), |
| 62 | + path.join(__dirname, './src/index.html') |
| 63 | + ]), |
| 64 | + extractors: [ |
| 65 | + { |
| 66 | + extractor: TailwindExtractor, |
| 67 | + // Specify the file extensions to include when scanning for |
| 68 | + // class names. |
| 69 | + extensions: ['html', 'js', 'vue'] |
| 70 | + } |
| 71 | + ] |
| 72 | + }), |
| 73 | + new HtmlWebpackHarddiskPlugin(), |
| 74 | + new CleanWebpackPlugin(), |
| 75 | + new VueLoaderPlugin(), |
| 76 | + new WebpackPwaManifest({ |
| 77 | + name: 'Example Aepp', |
| 78 | + short_name: 'Example', |
| 79 | + description: 'Your average aepp.', |
| 80 | + background_color: '#ff0d6a' |
| 81 | + }) |
| 82 | + ], |
| 83 | + module: { |
| 84 | + rules: [ |
| 85 | + // this will apply to both plain `.js` files |
| 86 | + // AND `<script>` blocks in `.vue` files |
| 87 | + { |
| 88 | + test: /\.js$/, |
| 89 | + include: [ |
| 90 | + path.resolve(__dirname, 'src'), |
| 91 | + path.resolve(__dirname, 'node_modules/@aeternity'), |
| 92 | + path.resolve(__dirname, 'node_modules/rlp'), |
| 93 | + // Contains 'const' or 'let' |
| 94 | + path.resolve(__dirname, 'node_modules/base-x') |
| 95 | + ], |
| 96 | + loader: 'babel-loader' |
| 97 | + }, |
| 98 | + { |
| 99 | + type: 'javascript/auto', |
| 100 | + test: /\.mjs$/, |
| 101 | + include: [ |
| 102 | + path.resolve(__dirname, 'node_modules/@download/blockies') |
| 103 | + ], |
| 104 | + loader: 'babel-loader' |
| 105 | + }, |
| 106 | + // this will apply to both plain `.css` files |
| 107 | + // AND `<style>` blocks in `.vue` files |
| 108 | + { |
| 109 | + test: /\.css$/, |
| 110 | + use: [ |
| 111 | + 'vue-style-loader', |
| 112 | + 'css-loader', |
| 113 | + { |
| 114 | + loader: 'postcss-loader', |
| 115 | + options: { |
| 116 | + config: { |
| 117 | + path: 'postcss.config.js' |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + ] |
| 122 | + }, |
| 123 | + // allows vue compoents in '<template><html><script><style>' syntax |
| 124 | + { |
| 125 | + test: /\.vue$/, |
| 126 | + loader: 'vue-loader', |
| 127 | + options: { |
| 128 | + loaders: { |
| 129 | + js: 'babel-loader' |
| 130 | + } |
| 131 | + // extractCSS: true |
| 132 | + // other vue-loader options go here |
| 133 | + } |
| 134 | + }, |
| 135 | + { |
| 136 | + test: /\.aes$/, |
| 137 | + use: [ |
| 138 | + 'raw-loader' |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + test: /\.(woff(2)?|ttf|eot|svg|png)(\?v=\d+\.\d+\.\d+)?$/, |
| 143 | + use: [{ |
| 144 | + loader: 'file-loader', |
| 145 | + options: { |
| 146 | + name: '[name].[ext]', |
| 147 | + outputPath: 'assets/' |
| 148 | + } |
| 149 | + }] |
| 150 | + } |
| 151 | + ] |
| 152 | + } |
| 153 | + } |
| 154 | +} |
0 commit comments