Files
Hippy/framework/js/examples/hippy-react-demo/scripts/hippy-webpack.web.dev.js
T
chestershen 26e6434b75 feat(vue, react, debug-server, vue-loader, vue-css-loader): support HMR
- hippy-vue: ElementNode add repaintWithChildren API

- hippy-vue: support remove outdated style of HMR chunk

- hippy-vue-loader: support style hmr

- hippy-vue-css-loader: support remove outdated style of HMR chunk

- debug-server, vue-demo, react-demo, hippy-react: support hmr

- debug-server: add hippy-dev command
2021-12-28 22:31:37 +08:00

112 lines
3.2 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const ReactRefreshWebpackPlugin = require('@hippy/hippy-react-refresh-webpack-plugin');
const pkg = require('../package.json');
const platform = 'web';
module.exports = {
mode: 'development',
bail: true,
devServer: {
port: 38988,
hot: true,
liveReload: true,
},
entry: {
index: ['regenerator-runtime', path.resolve(pkg.main)],
},
output: {
filename: `[name].${platform}.js`,
path: path.resolve(`./dist/${platform}/`),
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
__PLATFORM__: JSON.stringify(platform),
}),
new HtmlWebpackPlugin({
title: pkg.name,
filename: `${pkg.name}.html`,
template: path.resolve(__dirname, './template.html'),
favouriteIcon: pkg.favicon || 'https://res.imtt.qq.com/hippydoc/img/hippy-logo.ico',
}),
new CaseSensitivePathsPlugin(),
new ReactRefreshWebpackPlugin(),
],
module: {
rules: [
{
test: /\.(jsx?)$/,
use: [
{
loader: 'babel-loader',
options: {
sourceType: 'unambiguous',
presets: [
'@babel/preset-react',
[
'@babel/preset-env',
{
targets: {
chrome: 57,
ios: 8,
},
},
],
],
plugins: [
['@babel/plugin-proposal-class-properties'],
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-transform-runtime', { regenerator: true }],
require.resolve('react-refresh/babel'),
],
},
},
],
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'assets/',
},
}],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
modules: [path.resolve(__dirname, '../node_modules')],
alias: (() => {
const aliases = {
'@hippy/react': '@hippy/react-web',
};
// If hippy-react-web was built exist then make a alias to @hippy/react
// Remove the section if you don't use it
const hippyReactPath = path.resolve(__dirname, '../../../packages/hippy-react-web');
if (fs.existsSync(path.resolve(hippyReactPath, 'dist/index.js'))) {
/* eslint-disable-next-line no-console */
console.warn(`* Using the @hippy/react in ${hippyReactPath}`);
aliases['@hippy/react'] = hippyReactPath;
} else {
/* eslint-disable-next-line no-console */
console.warn('* Using the @hippy/react defined in package.json');
}
return aliases;
})(),
},
};