Skip to content

Commit

Permalink
build: add standalone web dev mod
Browse files Browse the repository at this point in the history
  • Loading branch information
wewoor committed Oct 20, 2020
1 parent e8bdb74 commit 07d1260
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 48 deletions.
51 changes: 3 additions & 48 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,11 @@
const path = require("path");
const webpack = require("webpack");
const { merge } = require('webpack-merge');
const baseConf = require('../build/webpack.base');

module.exports = {
stories: ["../stories/**/*.stories.tsx"],
addons: ["@storybook/addon-actions", "@storybook/addon-links"],
webpackFinal: async (config) => {
config.module.rules.push(
{
test: /\.(ts|tsx)$/,
exclude: [
path.resolve(__dirname, "../node_modules")
],
use: [
{
loader: require.resolve("ts-loader"),
},
// Optional
{
loader: require.resolve("react-docgen-typescript-loader"),
},
],
},
{
test: /\.worker\.js$/,
use: { loader: "worker-loader" },
},
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader"],
include: path.resolve(__dirname, "../"),
}
);

config.node = {
fs: "empty",
module: "empty",
};

config.plugins.push(
new webpack.ContextReplacementPlugin(
/monaco-editor(\\|\/)esm(\\|\/)vs(\\|\/)editor(\\|\/)common(\\|\/)services/,
__dirname
)
);

config.resolve.alias = {
"mo": path.resolve(__dirname, "../src"),
"@stories": path.resolve(__dirname, "../stories"),
};
config.resolve.extensions.push(".ts", ".tsx", ".js", ".jsx", ".json");
config.devtool = "cheap-module-eval-source-map";

return config;
return merge(config, baseConf);
},
};
34 changes: 34 additions & 0 deletions build/web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const path = require('path');
const { merge } = require('webpack-merge');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const webpackConf = require('./webpack.base');

module.exports = function(env) {
return merge(webpackConf, {
mode: 'development',
devServer: {
progress: false,
hot: true,
},
entry: {
'app': path.resolve(__dirname, './web/app.js'),
},
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(jpg|png|gif|eot|woff|svg|ttf|woff2|gif|appcache|webp)(\?|$)/,
use: ['file-loader'],
},
],
},
plugins: [
new HtmlWebPackPlugin({
template: path.resolve(__dirname, './web/index.html'),
}),
].filter(Boolean),
});
};
14 changes: 14 additions & 0 deletions build/web/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Workbench } from 'mo/workbench';
import { MoleculeProvider } from 'mo/provider/molecule';

ReactDOM.render(
<React.StrictMode>
<MoleculeProvider>
<Workbench />
</MoleculeProvider>
</React.StrictMode>,
document.getElementById('root'),
);
10 changes: 10 additions & 0 deletions build/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Molecule Sample</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
44 changes: 44 additions & 0 deletions build/webpack.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const path = require('path');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');

module.exports = {
devtool: 'cheap-module-eval-source-map',
resolve: {
extensions: ['.js', '.jsx', '.tsx', '.ts'],
alias: {
'mo': path.resolve(__dirname, '../src'),
'@stories': path.resolve(__dirname, '../stories'),
},
},
output: {
globalObject: 'self',
filename: '[name].bundle.js',
path: path.resolve(__dirname, '../dist'),
},
module: {
rules: [
{
test: /\.(js|jsx|tsx|ts)$/,
exclude: /node_modules/,
use: [
{
loader: require.resolve('ts-loader'),
},
// Optional
{
loader: require.resolve('react-docgen-typescript-loader'),
},
],
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
],
},
plugins: [
new MonacoWebpackPlugin({
languages: ['html', 'typescript', 'javascript', 'css'],
}),
],
};

0 comments on commit 07d1260

Please sign in to comment.