2017-09-04 02:20:56 +00:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const webpackStream = require('webpack-stream');
|
|
|
|
const livereload = require('gulp-livereload');
|
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const errorHandler = require('./helpers/errorHandler');
|
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
|
|
|
|
|
|
|
const uiFolder = 'UI';
|
|
|
|
const root = path.join(__dirname, '..', 'src');
|
|
|
|
const isProduction = process.argv.indexOf('--production') > -1;
|
|
|
|
|
|
|
|
console.log('ROOT:', root);
|
|
|
|
console.log('isProduction:', isProduction);
|
|
|
|
|
2017-10-02 03:05:28 +00:00
|
|
|
const cssVarsFiles = [
|
2017-09-04 02:20:56 +00:00
|
|
|
'../src/Styles/Variables/colors',
|
|
|
|
'../src/Styles/Variables/dimensions',
|
|
|
|
'../src/Styles/Variables/fonts',
|
|
|
|
'../src/Styles/Variables/animations'
|
|
|
|
].map(require.resolve);
|
|
|
|
|
2017-10-02 03:05:28 +00:00
|
|
|
const extractCSSPlugin = new ExtractTextPlugin({
|
|
|
|
filename: path.join('_output', uiFolder, 'Content', 'styles.css'),
|
|
|
|
allChunks: true,
|
|
|
|
disable: false,
|
|
|
|
ignoreOrder: true
|
|
|
|
});
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
const config = {
|
|
|
|
devtool: '#source-map',
|
|
|
|
stats: {
|
|
|
|
children: false
|
|
|
|
},
|
|
|
|
watchOptions: {
|
|
|
|
ignored: /node_modules/
|
|
|
|
},
|
|
|
|
entry: {
|
|
|
|
preload: 'preload.js',
|
|
|
|
vendor: 'vendor.js',
|
|
|
|
index: 'index.js'
|
|
|
|
},
|
|
|
|
resolve: {
|
2017-10-02 03:05:28 +00:00
|
|
|
modules: [
|
2017-09-04 02:20:56 +00:00
|
|
|
root,
|
2017-10-02 03:05:28 +00:00
|
|
|
path.join(root, 'Shims'),
|
|
|
|
'node_modules'
|
2017-09-21 02:05:00 +00:00
|
|
|
],
|
|
|
|
alias: {
|
|
|
|
jquery: 'jquery/src/jquery'
|
|
|
|
}
|
2017-09-04 02:20:56 +00:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: path.join('_output', uiFolder, '[name].js'),
|
|
|
|
sourceMapFilename: '[file].map'
|
|
|
|
},
|
|
|
|
plugins: [
|
2017-10-02 03:05:28 +00:00
|
|
|
extractCSSPlugin,
|
2017-09-04 02:20:56 +00:00
|
|
|
new webpack.optimize.CommonsChunkPlugin({
|
|
|
|
name: 'vendor'
|
|
|
|
}),
|
2017-10-02 03:05:28 +00:00
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
__DEV__: !isProduction,
|
|
|
|
'process.env': {
|
|
|
|
NODE_ENV: isProduction ? JSON.stringify('production') : JSON.stringify('development')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
resolveLoader: {
|
2017-10-02 03:05:28 +00:00
|
|
|
modules: [
|
2017-09-04 02:20:56 +00:00
|
|
|
'node_modules',
|
2017-10-02 03:05:28 +00:00
|
|
|
'frontend/gulp/webpack/'
|
2017-09-04 02:20:56 +00:00
|
|
|
]
|
|
|
|
},
|
2017-10-02 03:05:28 +00:00
|
|
|
// TODO: Do we need this loader?
|
|
|
|
// eslint: {
|
|
|
|
// formatter: function(results) {
|
|
|
|
// return JSON.stringify(results);
|
|
|
|
// }
|
|
|
|
// },
|
2017-09-04 02:20:56 +00:00
|
|
|
module: {
|
2017-10-02 03:05:28 +00:00
|
|
|
rules: [
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
test: /\.js?$/,
|
|
|
|
exclude: /(node_modules|JsLibraries)/,
|
2017-10-02 03:05:28 +00:00
|
|
|
loader: 'babel-loader',
|
2017-09-04 02:20:56 +00:00
|
|
|
query: {
|
|
|
|
plugins: ['transform-class-properties'],
|
|
|
|
presets: ['es2015', 'decorators-legacy', 'react', 'stage-2'],
|
|
|
|
env: {
|
|
|
|
development: {
|
|
|
|
plugins: ['transform-react-jsx-source']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// CSS Modules
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
exclude: /(node_modules|globals.css)/,
|
2017-10-02 03:05:28 +00:00
|
|
|
use: extractCSSPlugin.extract({
|
|
|
|
fallback: 'style-loader',
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'css-variables-loader',
|
|
|
|
options: {
|
|
|
|
cssVarsFiles
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
modules: true,
|
|
|
|
importLoaders: 1,
|
|
|
|
localIdentName: '[name]-[local]-[hash:base64:5]',
|
|
|
|
sourceMap: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
config: {
|
|
|
|
ctx: {
|
|
|
|
cssVarsFiles
|
|
|
|
},
|
|
|
|
path: 'frontend/postcss.config.js'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2017-09-04 02:20:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Global styles
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
include: /(node_modules|globals.css)/,
|
2017-10-02 03:05:28 +00:00
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
{
|
|
|
|
loader: 'css-loader'
|
|
|
|
}
|
|
|
|
]
|
2017-09-04 02:20:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Fonts
|
|
|
|
{
|
|
|
|
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
2017-10-02 03:05:28 +00:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
limit: 10240,
|
|
|
|
mimetype: 'application/font-woff',
|
|
|
|
emitFile: false,
|
|
|
|
name: 'Content/Fonts/[name].[ext]'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2017-09-04 02:20:56 +00:00
|
|
|
},
|
2017-10-02 03:05:28 +00:00
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
test: /\.(ttf|eot|eot?#iefix|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
2017-10-02 03:05:28 +00:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
emitFile: false,
|
|
|
|
name: 'Content/Fonts/[name].[ext]'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
gulp.task('webpack', () => {
|
|
|
|
return gulp.src('index.js')
|
|
|
|
.pipe(webpackStream(config))
|
|
|
|
.pipe(gulp.dest(''));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('webpackWatch', () => {
|
|
|
|
config.watch = true;
|
|
|
|
return gulp.src('')
|
|
|
|
.pipe(webpackStream(config))
|
|
|
|
.on('error', errorHandler)
|
|
|
|
.pipe(gulp.dest(''))
|
|
|
|
.on('error', errorHandler)
|
|
|
|
.pipe(livereload())
|
|
|
|
.on('error', errorHandler);
|
|
|
|
});
|