SHARE
TWEET

Untitled

a guest Jul 19th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //webpack
  2. const HtmlWebPackPlugin = require("html-webpack-plugin");
  3. const path = require("path");
  4.  
  5. module.exports = {
  6.   entry: [path.join(__dirname, "../src/client/index.jsx")],
  7.   output: {
  8.     path: path.resolve(__dirname, "../dist"),
  9.     filename: " bundle.js",
  10.     publicPath: "/"
  11.   },
  12.   module: {
  13.     rules: [
  14.       {
  15.         test: /\.jsx?$/,
  16.         include: path.join(__dirname, "../src/client"),
  17.         loader: "babel-loader"
  18.       },
  19.       {
  20.         test: /\.html$/,
  21.         loader: "html-loader"
  22.       },
  23.       {
  24.         test: /\.(png|jpg|gif|svg)$/,
  25.         use: [
  26.           {
  27.             loader: "file-loader",
  28.             options: {
  29.               name: "[name].[ext]",
  30.               outputPath: "img/"
  31.             }
  32.           }
  33.         ]
  34.       },
  35.       {
  36.         test: /\.(otf|ttf)$/,
  37.         loader: "file-loader",
  38.         options: {
  39.           name: "[name].[ext]",
  40.           outputPath: "fonts/"
  41.         }
  42.       }
  43.     ]
  44.   },
  45.   resolve: {
  46.     extensions: [".js", ".jsx"],
  47.     alias: {
  48.       "@components": path.resolve(__dirname, "../src/client/components"),
  49.       "@shared": path.resolve(__dirname, "../src/shared"),
  50.       "@utils": path.resolve(__dirname, "../src/shared/utils"),
  51.       "@assets": path.resolve(__dirname, "../src/client/assets"),
  52.       "@images": path.resolve(__dirname, "../src/client/assets/img"),
  53.       "@fonts": path.resolve(__dirname, "../src/client/assets/fonts"),
  54.       "@serverMiddlewares": path.resolve(__dirname, "../src/server/middlewares")
  55.     }
  56.   },
  57.   plugins: [
  58.     new HtmlWebPackPlugin({
  59.       template: "./src/client/public/index.html"
  60.     })
  61.   ]
  62. };
  63.  
  64. //webpack-dev-server.js
  65. import webpack from "webpack";
  66. import webpackDevMiddleware from "webpack-dev-middleware";
  67. import webpackConfigDev from "../../webpack/webpack.dev";
  68. import webpackConfigProd from "../../webpack/webpack.prod";
  69.  
  70. export default function webpackDevServer(app) {
  71.   const env = (process.env.NODE_ENV || "development").trim();
  72.  
  73.   const compiler = webpack(
  74.     env === "production" ? webpackConfigProd : webpackConfigDev
  75.   );
  76.   app.use(webpackDevMiddleware(compiler));
  77.  
  78.   app.set("env", env);
  79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top