Skip to content

Instantly share code, notes, and snippets.

@ByJC
Last active February 7, 2020 23:27
Show Gist options
  • Select an option

  • Save ByJC/85c58e0d71f4548bde96 to your computer and use it in GitHub Desktop.

Select an option

Save ByJC/85c58e0d71f4548bde96 to your computer and use it in GitHub Desktop.

Revisions

  1. ByJC revised this gist Mar 18, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion webpack.config.js
    Original file line number Diff line number Diff line change
    @@ -53,7 +53,7 @@ module.exports = {
    }, {
    test: /\.js$/,
    exclude: /node_modules/,
    loader: "ng-annotate?add=true!babel"
    loader: "babel"
    }, {
    test: [
    /\.svg/,
  2. ByJC revised this gist Mar 18, 2016. 1 changed file with 0 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions webpack.config.js
    Original file line number Diff line number Diff line change
    @@ -69,11 +69,5 @@ module.exports = {
    }
    ]
    },
    resolve: {
    alias: {
    txt: 'raw-loader',
    img: path.join(__dirname, 'lib/img')
    }
    },
    plugins: pluginsWebpack
    };
  3. ByJC created this gist Mar 18, 2016.
    79 changes: 79 additions & 0 deletions webpack.config.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    var path = require('path'),
    webpack = require("webpack"),
    libPath = path.join(__dirname, 'lib'),
    wwwPath = path.join(__dirname, 'www'),
    pkg = require('./package.json'),
    HtmlWebpackPlugin = require('html-webpack-plugin'),
    ExtractTextPlugin = require("extract-text-webpack-plugin");

    var bundleCss = ("production" === process.env.NODE_ENV) ? "bundle-[hash:6].css" : "bundle.css";
    var pluginsWebpack = [
    new ExtractTextPlugin(bundleCss),
    new HtmlWebpackPlugin({
    filename: 'index.html',
    pkg: pkg,
    template: path.join(libPath, 'index.html')
    })
    ];

    if (process.env.NODE_ENV === "production") {
    var prodEnv = [
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin(),
    new webpack.optimize.DedupePlugin()
    ];

    pluginsWebpack.concat(pluginsWebpack, prodEnv);
    }

    module.exports = {
    entry: path.join(libPath, 'index.js'),
    devtool: ("production" === process.env.NODE_ENV) ? "source-map" : "eval-source-map",
    output: {
    path: path.join(wwwPath),
    filename: ("production" === process.env.NODE_ENV) ? 'bundle-[hash:6].js' : 'bundle.js'
    },
    babel: {
    presets: ['es2015']
    },
    module: {
    loaders: [
    {
    test: /\.html$/,
    loader: ("production" === process.env.NODE_ENV) ? 'file?name=templates/[name]-[hash:6].html' : 'file?name=templates/[name].html'
    }, {
    test: /\.(png|jpg|gif)$/,
    loader: 'file?name=img/[name].[ext]' // inline base64 URLs for <=10kb images, direct URLs for the rest
    }, {
    test: /\.css$/,
    loader: ExtractTextPlugin.extract("style", "css!postcss")
    }, {
    test: /\.scss$/,
    loader: ExtractTextPlugin.extract("style", "css!postcss!sass")
    }, {
    test: /\.js$/,
    exclude: /node_modules/,
    loader: "ng-annotate?add=true!babel"
    }, {
    test: [
    /\.svg/,
    /\.eot/,
    /\.ttf/,
    /\.woff/,
    /\.woff2/
    ],
    loader: 'file?name=fonts/[name].[ext]'
    }, {
    test: /\.(json)$/,
    loader: 'json' // inline base64 URLs for <=10kb images, direct URLs for the rest
    }
    ]
    },
    resolve: {
    alias: {
    txt: 'raw-loader',
    img: path.join(__dirname, 'lib/img')
    }
    },
    plugins: pluginsWebpack
    };