1 Star 0 Fork 0

haol/scratch-gui

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
webpack.config.js 5.14 KB
一键复制 编辑 原始数据 按行查看 历史
haol 提交于 2024-10-21 09:28 . init
const path = require('path');
const webpack = require('webpack');
// Plugins
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ScratchWebpackConfigBuilder = require('scratch-webpack-configuration');
// const STATIC_PATH = process.env.STATIC_PATH || '/static';
const baseConfig = new ScratchWebpackConfigBuilder(
{
rootPath: path.resolve(__dirname),
enableReact: true,
shouldSplitChunks: true
})
.setTarget('browserslist')
.merge({
output: {
assetModuleFilename: 'static/assets/[name].[hash][ext][query]',
library: {
name: 'GUI',
type: 'umd2'
}
},
resolve: {
fallback: {
Buffer: require.resolve('buffer/'),
stream: require.resolve('stream-browserify')
}
},
optimization: {
runtimeChunk: 'single'
}
})
.addModuleRule({
test: /\.(svg|png|wav|mp3|gif|jpg)$/,
resourceQuery: /^$/, // reject any query string
type: 'asset' // let webpack decide on the best type of asset
})
.addPlugin(new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
}))
.addPlugin(new webpack.DefinePlugin({
'process.env.DEBUG': Boolean(process.env.DEBUG),
'process.env.GA_ID': `"${process.env.GA_ID || 'UA-000000-01'}"`,
'process.env.GTM_ENV_AUTH': `"${process.env.GTM_ENV_AUTH || ''}"`,
'process.env.GTM_ID': process.env.GTM_ID ? `"${process.env.GTM_ID}"` : null
}))
.addPlugin(new CopyWebpackPlugin({
patterns: [
{
from: 'node_modules/scratch-blocks/media',
to: 'static/blocks-media/default'
},
{
from: 'node_modules/scratch-blocks/media',
to: 'static/blocks-media/high-contrast'
},
{
// overwrite some of the default block media with high-contrast versions
// this entry must come after copying scratch-blocks/media into the high-contrast directory
from: 'src/lib/themes/high-contrast/blocks-media',
to: 'static/blocks-media/high-contrast',
force: true
},
{
context: 'node_modules/scratch-vm/dist/web',
from: 'extension-worker.{js,js.map}',
noErrorOnMissing: true
}
]
}));
if (!process.env.CI) {
baseConfig.addPlugin(new webpack.ProgressPlugin());
}
// build the shipping library in `dist/`
const distConfig = baseConfig.clone()
.merge({
entry: {
'scratch-gui': path.join(__dirname, 'src/index.js')
},
output: {
path: path.resolve(__dirname, 'dist')
}
})
.addPlugin(
new CopyWebpackPlugin({
patterns: [
{
from: 'src/lib/libraries/*.json',
to: 'libraries',
flatten: true
}
]
})
);
// build the examples and debugging tools in `build/`
const buildConfig = baseConfig.clone()
.enableDevServer(process.env.PORT || 8602)
.merge({
entry: {
gui: './src/playground/index.jsx',
blocksonly: './src/playground/blocks-only.jsx',
compatibilitytesting: './src/playground/compatibility-testing.jsx',
player: './src/playground/player.jsx'
},
output: {
path: path.resolve(__dirname, 'build')
}
})
.addPlugin(new HtmlWebpackPlugin({
chunks: ['gui'],
template: 'src/playground/index.ejs',
title: 'Scratch 3.0 GUI'
}))
.addPlugin(new HtmlWebpackPlugin({
chunks: ['blocksonly'],
filename: 'blocks-only.html',
template: 'src/playground/index.ejs',
title: 'Scratch 3.0 GUI: Blocks Only Example'
}))
.addPlugin(new HtmlWebpackPlugin({
chunks: ['compatibilitytesting'],
filename: 'compatibility-testing.html',
template: 'src/playground/index.ejs',
title: 'Scratch 3.0 GUI: Compatibility Testing'
}))
.addPlugin(new HtmlWebpackPlugin({
chunks: ['player'],
filename: 'player.html',
template: 'src/playground/index.ejs',
title: 'Scratch 3.0 GUI: Player Example'
}))
.addPlugin(new CopyWebpackPlugin({
patterns: [
{
from: 'static',
to: 'static'
},
{
from: 'extensions/**',
to: 'static',
context: 'src/examples'
}
]
}));
// Skip building `dist/` unless explicitly requested
// It roughly doubles build time and isn't needed for `scratch-gui` development
// If you need non-production `dist/` for local dev, such as for `scratch-www` work, you can run something like:
// `BUILD_MODE=dist npm run build`
const buildDist = process.env.NODE_ENV === 'production' || process.env.BUILD_MODE === 'dist';
module.exports = buildDist ?
[buildConfig.get(), distConfig.get()] :
buildConfig.get();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/haol/scratch-gui.git
git@gitee.com:haol/scratch-gui.git
haol
scratch-gui
scratch-gui
master

搜索帮助