1- 'use strict' 
1+ module . exports   =   language   =>   ` 'use strict'
22
33// Silence webpack2 deprecation warnings 
44// https://github.com/vuejs/vue-loader/issues/666 
@@ -15,18 +15,15 @@ const addPlugins = webpack2Block.addPlugins
1515
1616const babel = require('@webpack-blocks/babel6'); 
1717const devServer = require('@webpack-blocks/dev-server2'); 
18- const  typescript  =  require ( '@webpack-blocks/typescript' ) ; 
19- const  webpack  =  require ( 'webpack' ) ; 
18+ ${ language   ===   'javascript'  ?  ''  :  ` const typescript = require('@webpack-blocks/typescript');
19+ ` } 
2020const HtmlWebpackPlugin = require('html-webpack-plugin'); 
2121const CopyWebpackPlugin = require('copy-webpack-plugin'); 
22+ const CleanWebpackPlugin = require('clean-webpack-plugin'); 
2223
2324const path = require('path'); 
2425
2526const babelConfig = { 
26-   // This is a feature of `babel-loader` for webpack (not Babel itself). 
27-   // It enables caching results in ./node_modules/.cache/babel-loader/ 
28-   // directory for faster rebuilds. 
29-   cacheDirectory : true , 
3027  // Instead of relying on a babelrc file to configure babel (or in package.json configs) 
3128  // We speficy here which presets to use. In the future this could be moved to it's own 
3229  // package as create-react-app does with their 'babel-preset-react-app module. 
@@ -49,48 +46,44 @@ const babelConfig = {
4946  ] 
5047} 
5148
52- module . exports  =  function ( language )  { 
53-   const  ending  =  language  ===  'javascript'  ? '.js'  : '.ts' 
54-   const  baseConfig  =  [ 
55-     entryPoint ( path . join ( process . cwd ( ) ,  'src' ,  'index'  +  ending ) ) , 
56-     setOutput ( path . join ( process . cwd ( ) ,  'build' ,  'bundle.[hash].js' ) ) , 
57-     babel ( babelConfig ) , 
58-     defineConstants ( { 
59-       'process.env.NODE_ENV' : process . env . NODE_ENV 
49+ const config = [ 
50+   entryPoint(path.join(process.cwd(), 'src', 'index.${ language  ===  'javascript'  ? 'js'  : 'ts'  }  
51+   setOutput(path.join(process.cwd(), 'build', 'bundle.[hash].js')), 
52+   babel(Object.assign({}, babelConfig, { cacheDirectory: true })), 
53+   defineConstants({ 
54+     'process.env.NODE_ENV': process.env.NODE_ENV 
55+   }), 
56+   addPlugins([ 
57+     new HtmlWebpackPlugin({ 
58+       template: 'public/index.html', 
59+       inject: true, 
60+       favicon: 'public/favicon.png', 
61+       hash: true 
6062    }), 
63+     new webpack.ProvidePlugin({ 
64+       Snabbdom: 'snabbdom-pragma' 
65+     }) 
66+   ]), 
67+   env('development', [ 
68+     devServer({}, require.resolve('react-dev-utils/webpackHotDevClient')), 
69+     sourceMaps() //The default is cheap-module-source-map 
70+   ]), 
71+   env('production', [ 
6172    addPlugins([ 
62-         new  HtmlWebpackPlugin ( { 
63-           template : 'public/index.html' , 
64-           inject : true , 
65-           favicon : 'public/favicon.png' , 
66-           hash : true 
67-         } ) , 
68-         new  webpack . ProvidePlugin ( { 
69-           Snabbdom : 'snabbdom-pragma' 
70-         } ) 
71-     ] ) , 
72-     env ( 'development' ,  [ 
73-         devServer ( { } ,  require . resolve ( 'react-dev-utils/webpackHotDevClient' ) ) , 
74-         sourceMaps ( )  //The default is cheap-module-source-map 
75-     ] ) , 
76-     env ( 'production' ,  [ 
77-         addPlugins ( [ 
78-           new  webpack . optimize . UglifyJsPlugin ( ) , 
79-           new  CopyWebpackPlugin ( [ {  from : 'public' ,  to : ''  } ] ) 
80-         ] ) 
81-     ] ) 
82-   ] 
83- 
84-   const  config  =  language  ===  'javascript'  ? baseConfig  : baseConfig 
85-     . concat ( [ 
86-       typescript ( { 
87-         tsconfig : path . join ( __dirname ,  'tsconfig.json' ) , 
88-         useBabel : true , 
89-         babelOptions : babelConfig , 
90-         useCache : true , 
91-         cacheDirectory : 'node_modules/.cache/at-loader' 
73+       new webpack.optimize.UglifyJsPlugin(), 
74+       new CopyWebpackPlugin([{ from: 'public', to: '' }]), 
75+       new CleanWebpackPlugin([ path.join(process.cwd(), 'build') ], { 
76+         root: process.cwd() 
9277      }) 
9378    ]) 
79+   ])${ language  ===  'javascript'  ? ''  : `,  
80+   typescript({ 
81+     configFileName: path.join(__dirname, '..', 'configs', 'tsconfig.json'), 
82+     useBabel: true, 
83+     babelOptions: babelConfig, 
84+     useCache: true, 
85+     cacheDirectory: 'node_modules/.cache/at-loader' 
86+   })`  } 
87+ ] 
9488
95-   return  createConfig ( config ) 
96- } 
89+ module.exports = createConfig(config)` 
0 commit comments