Skip to content

Commit 07d1260

Browse files
committed
build: add standalone web dev mod
1 parent e8bdb74 commit 07d1260

File tree

5 files changed

+105
-48
lines changed

5 files changed

+105
-48
lines changed

.storybook/main.js

+3-48
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,11 @@
11
const path = require("path");
2-
const webpack = require("webpack");
2+
const { merge } = require('webpack-merge');
3+
const baseConf = require('../build/webpack.base');
34

45
module.exports = {
56
stories: ["../stories/**/*.stories.tsx"],
67
addons: ["@storybook/addon-actions", "@storybook/addon-links"],
78
webpackFinal: async (config) => {
8-
config.module.rules.push(
9-
{
10-
test: /\.(ts|tsx)$/,
11-
exclude: [
12-
path.resolve(__dirname, "../node_modules")
13-
],
14-
use: [
15-
{
16-
loader: require.resolve("ts-loader"),
17-
},
18-
// Optional
19-
{
20-
loader: require.resolve("react-docgen-typescript-loader"),
21-
},
22-
],
23-
},
24-
{
25-
test: /\.worker\.js$/,
26-
use: { loader: "worker-loader" },
27-
},
28-
{
29-
test: /\.scss$/,
30-
use: ["style-loader", "css-loader", "sass-loader"],
31-
include: path.resolve(__dirname, "../"),
32-
}
33-
);
34-
35-
config.node = {
36-
fs: "empty",
37-
module: "empty",
38-
};
39-
40-
config.plugins.push(
41-
new webpack.ContextReplacementPlugin(
42-
/monaco-editor(\\|\/)esm(\\|\/)vs(\\|\/)editor(\\|\/)common(\\|\/)services/,
43-
__dirname
44-
)
45-
);
46-
47-
config.resolve.alias = {
48-
"mo": path.resolve(__dirname, "../src"),
49-
"@stories": path.resolve(__dirname, "../stories"),
50-
};
51-
config.resolve.extensions.push(".ts", ".tsx", ".js", ".jsx", ".json");
52-
config.devtool = "cheap-module-eval-source-map";
53-
54-
return config;
9+
return merge(config, baseConf);
5510
},
5611
};

build/web.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const path = require('path');
2+
const { merge } = require('webpack-merge');
3+
const HtmlWebPackPlugin = require('html-webpack-plugin');
4+
const webpackConf = require('./webpack.base');
5+
6+
module.exports = function(env) {
7+
return merge(webpackConf, {
8+
mode: 'development',
9+
devServer: {
10+
progress: false,
11+
hot: true,
12+
},
13+
entry: {
14+
'app': path.resolve(__dirname, './web/app.js'),
15+
},
16+
module: {
17+
rules: [
18+
{
19+
test: /\.css$/,
20+
use: ['style-loader', 'css-loader'],
21+
},
22+
{
23+
test: /\.(jpg|png|gif|eot|woff|svg|ttf|woff2|gif|appcache|webp)(\?|$)/,
24+
use: ['file-loader'],
25+
},
26+
],
27+
},
28+
plugins: [
29+
new HtmlWebPackPlugin({
30+
template: path.resolve(__dirname, './web/index.html'),
31+
}),
32+
].filter(Boolean),
33+
});
34+
};

build/web/app.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
import * as React from 'react';
3+
import * as ReactDOM from 'react-dom';
4+
import { Workbench } from 'mo/workbench';
5+
import { MoleculeProvider } from 'mo/provider/molecule';
6+
7+
ReactDOM.render(
8+
<React.StrictMode>
9+
<MoleculeProvider>
10+
<Workbench />
11+
</MoleculeProvider>
12+
</React.StrictMode>,
13+
document.getElementById('root'),
14+
);

build/web/index.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Molecule Sample</title>
6+
</head>
7+
<body>
8+
<div id="root"></div>
9+
</body>
10+
</html>

build/webpack.base.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const path = require('path');
2+
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
3+
4+
module.exports = {
5+
devtool: 'cheap-module-eval-source-map',
6+
resolve: {
7+
extensions: ['.js', '.jsx', '.tsx', '.ts'],
8+
alias: {
9+
'mo': path.resolve(__dirname, '../src'),
10+
'@stories': path.resolve(__dirname, '../stories'),
11+
},
12+
},
13+
output: {
14+
globalObject: 'self',
15+
filename: '[name].bundle.js',
16+
path: path.resolve(__dirname, '../dist'),
17+
},
18+
module: {
19+
rules: [
20+
{
21+
test: /\.(js|jsx|tsx|ts)$/,
22+
exclude: /node_modules/,
23+
use: [
24+
{
25+
loader: require.resolve('ts-loader'),
26+
},
27+
// Optional
28+
{
29+
loader: require.resolve('react-docgen-typescript-loader'),
30+
},
31+
],
32+
},
33+
{
34+
test: /\.scss$/,
35+
use: ['style-loader', 'css-loader', 'sass-loader'],
36+
},
37+
],
38+
},
39+
plugins: [
40+
new MonacoWebpackPlugin({
41+
languages: ['html', 'typescript', 'javascript', 'css'],
42+
}),
43+
],
44+
};

0 commit comments

Comments
 (0)