Skip to content

Commit 93be209

Browse files
committed
Add new webpack config
1 parent 7932557 commit 93be209

File tree

6 files changed

+101
-318
lines changed

6 files changed

+101
-318
lines changed

packages/cycle-scripts/configs/javascript/webpack.config.dev.js

Lines changed: 0 additions & 103 deletions
This file was deleted.

packages/cycle-scripts/configs/javascript/webpack.config.prod.js

Lines changed: 0 additions & 92 deletions
This file was deleted.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
'use strict'
2+
3+
// Silence webpack2 deprecation warnings
4+
// https://github.com/vuejs/vue-loader/issues/666
5+
process.noDeprecation = true
6+
7+
const { createConfig, defineConstants, env, entryPoint, setOutput, sourceMaps, addPlugins } = require('@webpack-blocks/webpack2');
8+
const babel = require('@webpack-blocks/babel6');
9+
const devServer = require('@webpack-blocks/dev-server2');
10+
const postcss = require('@webpack-blocks/postcss');
11+
const sass = require('@webpack-blocks/sass');
12+
const typescript = require('@webpack-blocks/typescript');
13+
const tslint = require('@webpack-blocks/tslint');
14+
const extractText = require('@webpack-blocks/extract-text2');
15+
const autoprefixer = require('autoprefixer');
16+
const webpack = require('webpack');
17+
const HtmlWebpackPlugin = require('html-webpack-plugin');
18+
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
19+
const CopyWebpackPlugin = require('copy-webpack-plugin');
20+
const BabiliPlugin = require('babili-webpack-plugin');
21+
const path = require('path');
22+
23+
const babelConfig = {
24+
// This is a feature of `babel-loader` for webpack (not Babel itself).
25+
// It enables caching results in ./node_modules/.cache/babel-loader/
26+
// directory for faster rebuilds.
27+
cacheDirectory: true,
28+
// Instead of relying on a babelrc file to configure babel (or in package.json configs)
29+
// We speficy here which presets to use. In the future this could be moved to it's own
30+
// package as create-react-app does with their 'babel-preset-react-app module.
31+
// As uglify doesn't support es6 code yet, the uglify param will tell babel plugin to transpile to es5
32+
// in order for the output to be uglified.
33+
presets: [
34+
[ 'env', {
35+
'targets': {
36+
'browsers': ['last 2 versions'],
37+
uglify: true
38+
}
39+
}]
40+
],
41+
plugins: [
42+
// https://cycle.js.org/getting-started.html#getting-started-coding-consider-jsx
43+
// This allow us to use JSX to create virtual dom elements instead of Snabbdom helpers like div(), input(), ..
44+
['transform-react-jsx', { pragma: 'Snabbdom.createElement' }],
45+
// Allow Babel to transform rest properties for object destructuring assignment and spread properties for object literals.
46+
['transform-object-rest-spread']
47+
]
48+
}
49+
50+
module.exports = function(language) {
51+
const ending = language === 'javascript' ? 'js' : 'ts'
52+
const baseConfig = [
53+
entryPoint(path.join(process.cwd(), 'src', 'index' + ending)),
54+
setOutput(path.join(process.cwd(), 'build', 'bundle.[hash].js')),
55+
babel(),
56+
sass(),
57+
extractText('[name].[contenthash].css', 'text/x-sass'),
58+
postcss([
59+
autoprefixer({ browsers: ['last 2 versions'] })
60+
]),
61+
defineConstants({
62+
'process.env.NODE_ENV': process.env.NODE_ENV
63+
}),
64+
addPlugins([
65+
new HtmlWebpackPlugin({
66+
template: 'public/index.html',
67+
inject: true,
68+
favicon: 'public/favicon.png',
69+
hash: true
70+
}),
71+
new webpack.ProvidePlugin({
72+
Snabbdom: 'snabbdom-pragma'
73+
})
74+
]),
75+
env('development', [
76+
devServer({}, require.resolve('react-dev-utils/webpackHotDevClient')),
77+
sourceMaps()
78+
]),
79+
env('production', [
80+
addPlugins([
81+
new webpack.optimize.UglifyJsPlugin(),
82+
new CopyWebpackPlugin([{ from: 'public', to: '' }])
83+
])
84+
])
85+
]
86+
87+
const config = language === 'javascript' ? baseConfig : baseConfig
88+
.concat([
89+
typescript(),
90+
tslint()
91+
])
92+
93+
return createConfig(config)
94+
}

packages/cycle-scripts/configs/webpackDevServer.config.js

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)