-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
91 lines (82 loc) · 2.77 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require('babel-polyfill');
// Webpack config for creating the production bundle.
var path = require('path');
var webpack = require('webpack');
var CleanPlugin = require('clean-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin');
var strip = require('strip-loader');
var projectRootPath = path.resolve(__dirname);
var assetsPath = path.resolve(projectRootPath, './static/dist');
// https://github.com/halt-hammerzeit/webpack-isomorphic-tools
var WebpackIsomorphicToolsPlugin = require('webpack-isomorphic-tools/plugin');
var webpackIsomorphicToolsPlugin = new WebpackIsomorphicToolsPlugin(require('./webpack-isomorphic-tools'));
module.exports = {
context: path.resolve(__dirname),
entry: {
common: ['./src/static.js'],
},
output: {
path: assetsPath,
filename: '[name].js',
chunkFilename: '[name].js',
publicPath: '/dist/',
libraryTarget: 'umd',
},
module: {
loaders: [
{ test: /\.jsx?$/, exclude: /node_modules/, loaders: [strip.loader('debug'), 'babel-loader'] },
{ test: /\.json$/, loader: 'json-loader' },
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use:
'css-loader?-autoprefixer&importLoaders=2&localIdentName=_[hash:base64:5]!postcss-loader!sass-loader?outputStyle=expanded',
}),
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader?-autoprefixer&importLoaders=1!postcss-loader'),
},
{
test: /\.(jpe?g|png|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
loader: 'base64-inline-loader?limit=50000&name=[name].[ext]',
},
{ test: webpackIsomorphicToolsPlugin.regular_expression('images'), loader: 'file-loader' },
],
},
resolve: {
modules: ['node_modules'],
extensions: ['.js', '.scss', '.json', '.jsx'],
},
plugins: [
new CleanPlugin([assetsPath], { root: projectRootPath }),
// css files from the extract-text-plugin loader
new ExtractTextPlugin('[name].css', { allChunks: true }),
new StaticSiteGeneratorPlugin({}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
__CLIENT__: true,
__SERVER__: false,
__DEVELOPMENT__: false,
__DEVTOOLS__: false,
}),
// ignore dev config
new webpack.IgnorePlugin(/\.\/dev/, /\/config$/),
// optimizations
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
}),
webpackIsomorphicToolsPlugin,
new webpack.ContextReplacementPlugin(/moment[\\/]locale$/, /^\.\/(en|zh-tw)$/),
],
node: {
fs: 'empty',
},
};