@google/dscc-gen
Version:
Create component & connector projects with sane defaults.
63 lines (55 loc) • 1.59 kB
JavaScript
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const {getBuildableComponents} = require('@google/dscc-scripts/build/viz/util');
const components = getBuildableComponents();
const componentIndexToBuild = Number(process.env.WORKING_COMPONENT_INDEX) || 0;
const component = components[componentIndexToBuild];
console.log(`Building ${component.tsFile || component.jsFile}...`);
const cssFilePath = path.resolve(__dirname, 'src', component.cssFile || '');
const tsFilePath = path.resolve(__dirname, 'src', component.tsFile || '');
const plugins = [
// Add DSCC_IS_LOCAL definition
new webpack.DefinePlugin({
DSCC_IS_LOCAL: 'true',
}),
];
let body = '<script src="main.js"></script>';
if (fs.existsSync(cssFilePath)) {
body = body + '\n<link rel="stylesheet" href="index.css">';
plugins.push(new CopyWebpackPlugin([{from: cssFilePath, to: '.'}]));
}
const iframeHTML = `
<!doctype html>
<html><body>
${body}
</body></html>
`;
fs.writeFileSync(path.resolve(__dirname, 'dist', 'vizframe.html'), iframeHTML);
module.exports = [
{
mode: 'development',
entry: tsFilePath,
devServer: {
contentBase: './dist',
},
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
plugins: plugins,
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
},
];