1 | const _ = require('lodash');
|
2 | const fs = require('fs-extra');
|
3 | const path = require('path');
|
4 | const webpack = require('webpack');
|
5 | const CleanPlugin = require('clean-webpack-plugin');
|
6 | const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
7 | const strip = require('strip-loader');
|
8 | const relativeAssetsPath = 'static/dist';
|
9 | const cwd = process.cwd();
|
10 | const assetsPath = path.join(cwd, relativeAssetsPath);
|
11 | const rcPath = path.join(cwd, '.koikirc');
|
12 | const rc = fs.existsSync(rcPath) ? fs.readJsonSync(rcPath) : {};
|
13 | const env = require('../bin/lib/env');
|
14 |
|
15 | const WebpackIsomorphicToolsPlugin = require('webpack-isomorphic-tools/plugin');
|
16 | const webpackIsomorphicToolsPlugin = new WebpackIsomorphicToolsPlugin(require('./webpack-isomorphic-tools'));
|
17 |
|
18 | module.exports = _.merge({
|
19 | devtool: 'source-map',
|
20 | context: cwd,
|
21 | entry: {
|
22 | 'main': [
|
23 | path.resolve(cwd, 'src/client.js')
|
24 | ]
|
25 | },
|
26 | output: {
|
27 | path: assetsPath,
|
28 | filename: '[name]-[chunkhash].js',
|
29 | chunkFilename: '[name]-[chunkhash].js',
|
30 | publicPath: '/dist/'
|
31 | },
|
32 | module: {
|
33 | rules: [
|
34 | { test: /\.jsx?$/, exclude: /node_modules/, use: [strip.loader('debug'), {
|
35 | loader: 'buble-loader',
|
36 | options: {
|
37 | objectAssign: 'Object.assign'
|
38 | }
|
39 | }]},
|
40 | { test: /\.css$/, use: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' }) },
|
41 | {
|
42 | test: /\.less$/,
|
43 | use: ExtractTextPlugin.extract({
|
44 | fallback: 'style-loader',
|
45 | use: [{
|
46 | loader: 'css-loader',
|
47 | options: {
|
48 | modules: true,
|
49 | importLoaders: 2,
|
50 | sourceMap: true
|
51 | }
|
52 | }, {
|
53 | loader: 'less-loader',
|
54 | options: {
|
55 | outputStyle: 'expanded',
|
56 | sourceMap: true,
|
57 | sourceMapContents: true
|
58 | }
|
59 | }]
|
60 | })
|
61 | },
|
62 | {
|
63 | test: /\.scss$/,
|
64 | use: ExtractTextPlugin.extract({
|
65 | fallback: 'style-loader',
|
66 | use: [{
|
67 | loader: 'css-loader',
|
68 | options: {
|
69 | modules: true,
|
70 | importLoaders: 2,
|
71 | sourceMap: true
|
72 | }
|
73 | }, {
|
74 | loader: 'sass-loader',
|
75 | options: {
|
76 | outputStyle: 'expanded',
|
77 | sourceMap: true,
|
78 | sourceMapContents: true
|
79 | }
|
80 | }]
|
81 | })
|
82 | },
|
83 | { test: /\.woff2?(\?v=\d+\.\d+\.\d+)?$/, use: [{
|
84 | loader: 'url-loader',
|
85 | options: {
|
86 | limit: 10000,
|
87 | mimetype: 'application/font-woff'
|
88 | }
|
89 | }]},
|
90 | { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, use: [{
|
91 | loader: 'url-loader',
|
92 | options: {
|
93 | limit: 10000,
|
94 | mimetype: 'application/octet-stream'
|
95 | }
|
96 | }]},
|
97 | { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, use: 'file-loader' },
|
98 | { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, use: [{
|
99 | loader: 'url-loader',
|
100 | options: {
|
101 | limit: 10000,
|
102 | mimetype: 'image/svg+xml'
|
103 | }
|
104 | }]},
|
105 | { test: webpackIsomorphicToolsPlugin.regular_expression('images'), use: 'url-loader' }
|
106 | ],
|
107 | },
|
108 | resolve: {
|
109 | modules: [
|
110 | path.join(cwd, 'src'),
|
111 | 'node_modules'
|
112 | ],
|
113 | extensions: ['.json', '.js', '.jsx'],
|
114 | },
|
115 | plugins: [
|
116 | new CleanPlugin([assetsPath], { root: cwd }),
|
117 |
|
118 |
|
119 | new ExtractTextPlugin({
|
120 | filename: '[name]-[chunkhash].css',
|
121 | allChunks: true
|
122 | }),
|
123 | new webpack.DefinePlugin({
|
124 | __CLIENT__: true,
|
125 | __SERVER__: false,
|
126 | __DEVELOPMENT__: false,
|
127 | 'process.env': env(),
|
128 | }),
|
129 |
|
130 |
|
131 | new webpack.IgnorePlugin(/\.\/dev/, /\/config$/),
|
132 |
|
133 | webpackIsomorphicToolsPlugin
|
134 | ],
|
135 | externals: {
|
136 | fs: '{}',
|
137 | express: '{}',
|
138 | passporter: '{}',
|
139 | passport: '{}'
|
140 | }
|
141 | }, rc.webpack && rc.webpack.prod ? rc.webpack.prod : {});
|