Advertisement
Guest User

framework7_webpack.config.js

a guest
May 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const webpack = require('webpack');
  2. const CopyWebpackPlugin = require('copy-webpack-plugin');
  3. const HtmlWebpackPlugin = require('html-webpack-plugin');
  4. const VueLoaderPlugin = require('vue-loader/lib/plugin');
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6. const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
  7. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  8.  
  9.  
  10. const path = require('path');
  11.  
  12. function resolvePath(dir) {
  13.   return path.join(__dirname, '..', dir);
  14. }
  15.  
  16. const env = process.env.NODE_ENV || 'development';
  17. const target = process.env.TARGET || 'web';
  18. const isCordova = target === 'cordova';
  19.  
  20.  
  21. module.exports = {
  22.   mode: env,
  23.   entry: [
  24.     './src/js/app.js',
  25.   ],
  26.   output: {
  27.     path: resolvePath(isCordova ? 'cordova/www' : 'www'),
  28.     filename: 'js/app.js',
  29.     publicPath: '',
  30.     hotUpdateChunkFilename: 'hot/hot-update.js',
  31.     hotUpdateMainFilename: 'hot/hot-update.json',
  32.   },
  33.   resolve: {
  34.     extensions: ['.js', '.vue', '.json'],
  35.     alias: {
  36.       vue$: 'vue/dist/vue.esm.js',
  37.       '@': resolvePath('src'),
  38.     },
  39.   },
  40.   devtool: env === 'production' ? 'source-map' : 'eval',
  41.   devServer: {
  42.     hot: true,
  43.     open: true,
  44.     compress: true,
  45.     contentBase: '/www/',
  46.     disableHostCheck: true,
  47.     watchOptions: {
  48.       poll: 1000,
  49.     },
  50.   },
  51.   module: {
  52.     rules: [
  53.       {
  54.         test: /\.(js|jsx)$/,
  55.         use: 'babel-loader',
  56.         include: [
  57.           resolvePath('src'),
  58.           resolvePath('node_modules/framework7'),
  59.           resolvePath('node_modules/framework7-vue'),
  60.  
  61.           resolvePath('node_modules/template7'),
  62.           resolvePath('node_modules/dom7'),
  63.           resolvePath('node_modules/ssr-window'),
  64.         ],
  65.       },
  66.  
  67.       {
  68.         test: /\.vue$/,
  69.         use: 'vue-loader',
  70.       },
  71.       {
  72.         test: /\.css$/,
  73.         use: [
  74.           (env === 'development' ? 'style-loader' : {
  75.             loader: MiniCssExtractPlugin.loader,
  76.             options: {
  77.               publicPath: '../'
  78.             }
  79.           }),
  80.           'css-loader',
  81.           'postcss-loader',
  82.         ],
  83.       },
  84.       {
  85.         test: /\.styl(us)?$/,
  86.         use: [
  87.           (env === 'development' ? 'style-loader' : {
  88.             loader: MiniCssExtractPlugin.loader,
  89.             options: {
  90.               publicPath: '../'
  91.             }
  92.           }),
  93.           'css-loader',
  94.           'postcss-loader',
  95.           'stylus-loader',
  96.         ],
  97.       },
  98.       {
  99.         test: /\.less$/,
  100.         use: [
  101.           (env === 'development' ? 'style-loader' : {
  102.             loader: MiniCssExtractPlugin.loader,
  103.             options: {
  104.               publicPath: '../'
  105.             }
  106.           }),
  107.           'css-loader',
  108.           'postcss-loader',
  109.           'less-loader',
  110.         ],
  111.       },
  112.       {
  113.         test: /\.(sa|sc)ss$/,
  114.         use: [
  115.           (env === 'development' ? 'style-loader' : {
  116.             loader: MiniCssExtractPlugin.loader,
  117.             options: {
  118.               publicPath: '../'
  119.             }
  120.           }),
  121.           'css-loader',
  122.           'postcss-loader',
  123.           'sass-loader',
  124.         ],
  125.       },
  126.       {
  127.         test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  128.         loader: 'url-loader',
  129.         options: {
  130.           limit: 10000,
  131.           name: 'images/[name].[ext]',
  132.  
  133.         },
  134.       },
  135.       {
  136.         test: /\.(mp4|webm|ogg|mp3|wav|flac|aac|m4a)(\?.*)?$/,
  137.         loader: 'url-loader',
  138.         options: {
  139.           limit: 10000,
  140.           name: 'media/[name].[ext]',
  141.  
  142.         },
  143.       },
  144.       {
  145.         test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  146.         loader: 'url-loader',
  147.         options: {
  148.           limit: 10000,
  149.           name: 'fonts/[name].[ext]',
  150.  
  151.         },
  152.       },
  153.     ],
  154.   },
  155.   plugins: [
  156.     new webpack.DefinePlugin({
  157.       'process.env.NODE_ENV': JSON.stringify(env),
  158.       'process.env.TARGET': JSON.stringify(target),
  159.     }),
  160.     new VueLoaderPlugin(),
  161.     ...(env === 'production' ? [
  162.       // Production only plugins
  163.       new UglifyJsPlugin({
  164.         uglifyOptions: {
  165.           compress: {
  166.             warnings: false,
  167.           },
  168.         },
  169.         sourceMap: true,
  170.         parallel: true,
  171.       }),
  172.       new OptimizeCSSPlugin({
  173.         cssProcessorOptions: {
  174.           safe: true,
  175.           map: { inline: false },
  176.         },
  177.       }),
  178.       new webpack.optimize.ModuleConcatenationPlugin(),
  179.     ] : [
  180.       // Development only plugins
  181.       new webpack.HotModuleReplacementPlugin(),
  182.       new webpack.NamedModulesPlugin(),
  183.     ]),
  184.     new HtmlWebpackPlugin({
  185.       filename: './index.html',
  186.       template: './src/index.html',
  187.       inject: true,
  188.       minify: env === 'production' ? {
  189.         collapseWhitespace: true,
  190.         removeComments: true,
  191.         removeRedundantAttributes: true,
  192.         removeScriptTypeAttributes: true,
  193.         removeStyleLinkTypeAttributes: true,
  194.         useShortDoctype: true
  195.       } : false,
  196.     }),
  197.     new MiniCssExtractPlugin({
  198.       filename: 'css/app.css',
  199.     }),
  200.     new CopyWebpackPlugin([
  201.       {
  202.         from: resolvePath('src/static'),
  203.         to: resolvePath(isCordova ? 'cordova/www/static' : 'www/static'),
  204.       },
  205.  
  206.     ]),
  207.  
  208.  
  209.   ],
  210. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement