azazeln28

webpack

Sep 25th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import webpack from "webpack";
  2. import HtmlPlugin from "html-webpack-plugin";
  3. import ExtractTextPlugin from "extract-text-webpack-plugin";
  4. import NpmInstallPlugin from "npm-install-webpack-plugin";
  5. import path from "path";
  6.  
  7. function dist(...args) {
  8.   return path.resolve(__dirname, "dist", ...args);
  9. }
  10.  
  11. function src(...args) {
  12.   return path.resolve(__dirname, "src", ...args);
  13. }
  14.  
  15. const config = {
  16.  
  17.   entry: [
  18.     src("index.js"),
  19.     src("index.styl")
  20.   ],  
  21.  
  22.   output: {
  23.     path: dist(),
  24.     filename: "index.js"
  25.   },  
  26.  
  27.   resolve: {
  28.     extensions: [".js",".jsx"]
  29.   },
  30.  
  31.   externals: ["shaka"],
  32.  
  33.   module: {
  34.     rules: [
  35.       {  
  36.         test: /\.jsx?$/,
  37.         use: "babel-loader"
  38.       },
  39.       {
  40.         test: /\.styl$/,
  41.         use: ExtractTextPlugin.extract({
  42.           use: [{
  43.             loader: "css-loader",
  44.             options: {
  45.               module: true
  46.             }  
  47.           },"stylus-loader"]
  48.         })  
  49.       }  
  50.     ]  
  51.   },  
  52.  
  53.   plugins: [
  54.     new NpmInstallPlugin(),
  55.     new HtmlPlugin({
  56.       title: "Sync PoC",
  57.       template: src("index.html")
  58.     }),
  59.     new ExtractTextPlugin("index.css"),
  60.     new webpack.DefinePlugin({
  61.       "process.env": {
  62.         "NODE_ENV": JSON.stringify(process.env.NODE_ENV || "development")
  63.       }  
  64.     }),
  65.     new webpack.HotModuleReplacementPlugin(),
  66.     new webpack.optimize.UglifyJsPlugin()
  67.   ],  
  68.  
  69.   devtool: "source-map",
  70.  
  71.   devServer: {
  72.     historyApiFallback: true,
  73.     contentBase: dist(),
  74.     port: process.env.PORT || 4000,
  75.     hot: true
  76.   }
  77.  
  78. };
  79.  
  80. export default config;
Add Comment
Please, Sign In to add comment