1- 'use strict'
2-
1+ module . exports = ( language , ejected = false ) => `'use strict'
32// Silence webpack2 deprecation warnings
43// https://github.com/vuejs/vue-loader/issues/666
54process.noDeprecation = true
6-
75const webpack2Block = require('@webpack-blocks/webpack2');
86const createConfig = webpack2Block.createConfig
97const defineConstants = webpack2Block.defineConstants
@@ -12,21 +10,15 @@ const entryPoint = webpack2Block.entryPoint
1210const setOutput = webpack2Block.setOutput
1311const sourceMaps = webpack2Block.sourceMaps
1412const addPlugins = webpack2Block.addPlugins
15-
1613const babel = require('@webpack-blocks/babel6');
1714const 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');
2017const HtmlWebpackPlugin = require('html-webpack-plugin');
2118const CopyWebpackPlugin = require('copy-webpack-plugin');
22-
19+ const CleanWebpackPlugin = require('clean-webpack-plugin');
2320const path = require('path');
24-
2521const 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 ,
3022 // Instead of relying on a babelrc file to configure babel (or in package.json configs)
3123 // We speficy here which presets to use. In the future this could be moved to it's own
3224 // package as create-react-app does with their 'babel-preset-react-app module.
@@ -48,49 +40,44 @@ const babelConfig = {
4840 ['transform-object-rest-spread']
4941 ]
5042}
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
6056 }),
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', [
6166 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()
9271 })
9372 ])
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