Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require('path')
- const webpack = require('webpack')
- const ExtractTextPlugin = require('extract-text-webpack-plugin')
- const CleanWebpackPlugin = require('clean-webpack-plugin')
- const noop = require('noop-webpack-plugin')
- process.env.NODE_ENV = process.env.NODE_ENV || 'development'
- module.exports = (env) => {
- const isProduction = env === 'production'
- const clean = new CleanWebpackPlugin([path.resolve(__dirname, 'public', 'generated')])
- const extractText = new ExtractTextPlugin({
- filename: 'bundle.min.css',
- })
- const uglifyJS = isProduction ? new webpack.optimize.UglifyJsPlugin({
- comments: false,
- mangle: true,
- sourceMap: true,
- }) : noop()
- const providePlugin = new webpack.ProvidePlugin({
- $: 'jquery',
- jQuery: 'jquery',
- Raphael: 'raphael',
- 'window.$': 'jquery',
- 'window.jQuery': 'jquery',
- 'window.Raphael': 'raphael',
- })
- return {
- context: path.resolve(__dirname, 'client'),
- entry: ['babel-polyfill', './entry.js'],
- output: {
- filename: 'bundle.min.js',
- path: path.resolve(__dirname, 'public', 'generated'),
- },
- resolve: {
- extensions: ['.js'],
- alias: {
- Templates: path.resolve(__dirname, 'client', 'templates'),
- },
- },
- module: {
- loaders: [
- {
- test: require.resolve('jquery'),
- use: [{
- loader: 'expose-loader',
- options: 'jQuery',
- }, {
- loader: 'expose-loader',
- options: '$',
- }],
- },
- {
- test: /\.js$/,
- exclude: /(node_modules|public)/,
- loader: 'babel-loader',
- }, {
- test: /\.(hbs|handlebars)$/,
- exclude: /(node_modules|public)/,
- loader: 'handlebars-loader',
- },
- {
- test: /\.(ttf|eot|svg|woff2?)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
- loader: 'file-loader',
- options: {
- name: '[name].[ext]',
- publicPath: '',
- outputPath: 'fonts/',
- },
- }, {
- test: /\.(png|jpg|gif)$/,
- loader: 'file-loader',
- options: {
- name: '[name].[ext]',
- outputPath: 'images/',
- publicPath: '',
- },
- },
- {
- test: /\.(less)$/,
- loader: extractText.extract({
- publicPath: '/',
- fallback: 'style-loader',
- use: [
- {
- loader: 'css-loader',
- options: {
- sourceMap: true,
- minimize: true,
- },
- },
- {
- loader: 'less-loader',
- options: {
- sourceMap: true,
- minimize: true,
- },
- },
- ],
- }),
- },
- ],
- },
- plugins: [
- clean,
- uglifyJS,
- extractText,
- providePlugin,
- ],
- devtool: isProduction ? 'source-map' : 'inline-source-map',
- devServer: {
- contentBase: path.join(__dirname, 'public'),
- publicPath: '/generated/',
- historyApiFallback: true,
- port: 3000,
- },
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement