1
- 'use strict'
2
-
1
+ module . exports = ( language , ejected = false ) => `'use strict'
3
2
// Silence webpack2 deprecation warnings
4
3
// https://github.com/vuejs/vue-loader/issues/666
5
4
process.noDeprecation = true
6
-
7
5
const webpack2Block = require('@webpack-blocks/webpack2');
8
6
const createConfig = webpack2Block.createConfig
9
7
const defineConstants = webpack2Block.defineConstants
@@ -12,21 +10,15 @@ const entryPoint = webpack2Block.entryPoint
12
10
const setOutput = webpack2Block.setOutput
13
11
const sourceMaps = webpack2Block.sourceMaps
14
12
const addPlugins = webpack2Block.addPlugins
15
-
16
13
const babel = require('@webpack-blocks/babel6');
17
14
const devServer = require('@webpack-blocks/dev-server2');
18
- const typescript = require ( '@webpack-blocks/typescript' ) ;
19
- const webpack = require ( 'webpack' ) ;
15
+ ${ language === 'javascript' ? '' : ` const typescript = require('@webpack-blocks/typescript');
16
+ ` } const webpack = require('webpack');
20
17
const HtmlWebpackPlugin = require('html-webpack-plugin');
21
18
const CopyWebpackPlugin = require('copy-webpack-plugin');
22
-
19
+ const CleanWebpackPlugin = require('clean-webpack-plugin');
23
20
const path = require('path');
24
-
25
21
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
22
// Instead of relying on a babelrc file to configure babel (or in package.json configs)
31
23
// We speficy here which presets to use. In the future this could be moved to it's own
32
24
// package as create-react-app does with their 'babel-preset-react-app module.
@@ -48,49 +40,44 @@ const babelConfig = {
48
40
['transform-object-rest-spread']
49
41
]
50
42
}
51
-
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
43
+ const config = [
44
+ entryPoint(path.join(process.cwd(), 'src', 'index.${ language === 'javascript' ? 'js' : 'ts' } ')),
45
+ setOutput(path.join(process.cwd(), 'build', 'bundle.[hash].js')),
46
+ babel(Object.assign({}, babelConfig, { cacheDirectory: true })),
47
+ defineConstants({
48
+ 'process.env.NODE_ENV': process.env.NODE_ENV
49
+ }),
50
+ addPlugins([
51
+ new HtmlWebpackPlugin({
52
+ template: 'public/index.html',
53
+ inject: true,
54
+ favicon: 'public/favicon.png',
55
+ hash: true
60
56
}),
57
+ new webpack.ProvidePlugin({
58
+ Snabbdom: 'snabbdom-pragma'
59
+ })
60
+ ]),
61
+ env('development', [
62
+ devServer({}, require.resolve('react-dev-utils/webpackHotDevClient')),
63
+ sourceMaps() //The default is cheap-module-source-map
64
+ ]),
65
+ env('production', [
61
66
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'
67
+ new webpack.optimize.UglifyJsPlugin(),
68
+ new CopyWebpackPlugin([{ from: 'public', to: '' }]),
69
+ new CleanWebpackPlugin([ path.join(process.cwd(), 'build') ], {
70
+ root: process.cwd()
92
71
})
93
72
])
94
-
95
- return createConfig ( config )
96
- }
73
+ ])${ language === 'javascript' ? '' : `,
74
+ typescript({${ ! ejected ? `
75
+ configFileName:path.join(__dirname, '..', 'configs', 'tsconfig.json'),` : '' }
76
+ useBabel: true,
77
+ babelOptions: babelConfig,
78
+ useCache: true,
79
+ cacheDirectory: 'node_modules/.cache/at-loader'
80
+ })` }
81
+ ]
82
+ module.exports = createConfig(config)
83
+ `
0 commit comments