freeCodeCamp/client/webpack-workers.js

85 lines
2.4 KiB
JavaScript
Raw Normal View History

const { writeFileSync } = require('fs');
2018-04-06 13:51:52 +00:00
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
2018-04-06 13:51:52 +00:00
2018-09-12 08:41:27 +00:00
module.exports = (env = {}) => {
const __DEV__ = env.production !== true;
const staticPath = path.join(__dirname, './static/js');
const configPath = path.join(__dirname, '../config/client');
2018-09-12 08:41:27 +00:00
return {
cache: __DEV__ ? { type: 'filesystem' } : false,
2018-09-12 08:41:27 +00:00
mode: __DEV__ ? 'development' : 'production',
entry: {
'frame-runner': './src/client/frame-runner.ts',
'sass-compile': './src/client/workers/sass-compile.ts',
'test-evaluator': './src/client/workers/test-evaluator.ts'
},
2018-09-12 08:41:27 +00:00
devtool: __DEV__ ? 'inline-source-map' : 'source-map',
output: {
publicPath: '/js/',
filename: chunkData => {
// construct and output the filename here, so the client can use the
// json to find the file.
const filename = `${chunkData.chunk.name}-${chunkData.chunk.contentHash.javascript}`;
writeFileSync(
path.join(configPath, `${chunkData.chunk.name}.json`),
`{"filename": "${filename}"}`
);
return filename + '.js';
},
chunkFilename: '[name]-[contenthash].js',
path: staticPath
2018-09-12 08:41:27 +00:00
},
stats: {
// Display bailout reasons
optimizationBailout: true
},
module: {
rules: [
{
test: /\.(js|ts)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
babelrc: false,
presets: [
[
'@babel/preset-env',
{ modules: false, targets: '> 0.25%, not dead' }
],
'@babel/preset-typescript'
],
plugins: [
'@babel/plugin-transform-runtime',
'@babel/plugin-syntax-dynamic-import'
]
}
2018-09-12 08:41:27 +00:00
}
2018-04-06 13:51:52 +00:00
}
]
2018-12-28 07:49:53 +00:00
},
plugins: [
new CopyWebpackPlugin({
patterns: ['../node_modules/sass.js/dist/sass.sync.js']
}),
new webpack.ProvidePlugin({
process: 'process/browser'
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
})
],
resolve: {
fallback: {
buffer: require.resolve('buffer'),
util: false,
stream: false,
process: require.resolve('process/browser')
},
extensions: ['.js', '.ts']
}
2018-09-12 08:41:27 +00:00
};
2018-04-06 13:51:52 +00:00
};