1
- 'use strict'
1
+ module . exports = language => ` 'use strict'
2
2
3
3
// Silence webpack2 deprecation warnings
4
4
// https://github.com/vuejs/vue-loader/issues/666
@@ -15,18 +15,15 @@ const addPlugins = webpack2Block.addPlugins
15
15
16
16
const babel = require('@webpack-blocks/babel6');
17
17
const 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
+ ` } const webpack = require('webpack');
20
20
const HtmlWebpackPlugin = require('html-webpack-plugin');
21
21
const CopyWebpackPlugin = require('copy-webpack-plugin');
22
+ const CleanWebpackPlugin = require('clean-webpack-plugin');
22
23
23
24
const path = require('path');
24
25
25
26
const 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 ,
30
27
// Instead of relying on a babelrc file to configure babel (or in package.json configs)
31
28
// We speficy here which presets to use. In the future this could be moved to it's own
32
29
// package as create-react-app does with their 'babel-preset-react-app module.
@@ -49,48 +46,44 @@ const babelConfig = {
49
46
]
50
47
}
51
48
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
60
62
}),
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', [
61
72
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()
92
77
})
93
78
])
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
+ ]
94
88
95
- return createConfig ( config )
96
- }
89
+ module.exports = createConfig(config)`
0 commit comments