Commit bfc3b458 authored by 邓晓峰's avatar 邓晓峰

fix: 修复esm编译

parent 71455426
Pipeline #48575 skipped with stages
...@@ -5,7 +5,7 @@ PROXY=/Cityinterface:http://192.168.12.116:8015;/PandaOMS:http://192.168.12.116: ...@@ -5,7 +5,7 @@ PROXY=/Cityinterface:http://192.168.12.116:8015;/PandaOMS:http://192.168.12.116:
# PROXY2 = test : http://localhost:8006/ # PROXY2 = test : http://localhost:8006/
# 本地应用启动的host域名 # 本地应用启动的host域名
HOST = 192.168.12.192 HOST = 127.0.0.1
# 本地应用启动的端口 # 本地应用启动的端口
PORT = 3001 PORT = 3001
...@@ -3,16 +3,39 @@ module.exports = { ...@@ -3,16 +3,39 @@ module.exports = {
[ [
'@babel/preset-env', '@babel/preset-env',
{ {
modules: false, 'exclude': [
'transform-typeof-symbol',
'transform-unicode-regex',
'transform-sticky-regex',
'transform-new-target',
'transform-modules-umd',
'transform-modules-systemjs',
'transform-modules-amd',
'transform-literals',
],
'modules': false,
}, },
], ],
'@babel/preset-react', ['@babel/preset-typescript'],
['@babel/preset-react'],
], ],
plugins: [ plugins: [
'styled-components', 'styled-components',
'@babel/plugin-proposal-class-properties', ['@babel/plugin-proposal-optional-chaining', { 'loose': false }],
['@babel/plugin-proposal-nullish-coalescing-operator', { 'loose': false }],
'@babel/plugin-syntax-top-level-await',
['@babel/plugin-transform-destructuring', { 'loose': false }],
['@babel/plugin-proposal-decorators', { 'legacy': true }],
['@babel/plugin-proposal-class-properties', { 'loose': true }],
'@babel/plugin-proposal-export-default-from',
['@babel/plugin-proposal-pipeline-operator', { 'proposal': 'minimal' }],
'@babel/plugin-proposal-do-expressions',
'@babel/plugin-proposal-function-bind',
'@babel/plugin-proposal-logical-assignment-operators',
'@babel/plugin-syntax-dynamic-import', '@babel/plugin-syntax-dynamic-import',
['import', { libraryName: 'antd', style: true }], ['babel-plugin-transform-react-remove-prop-types', { 'removeImport': true }],
['babel-plugin-react-require'],
['babel-plugin-import', { 'libraryName': 'antd', 'libraryDirectory': 'es', 'style': true }, 'antd'],
], ],
env: { env: {
production: { production: {
...@@ -21,14 +44,14 @@ module.exports = { ...@@ -21,14 +44,14 @@ module.exports = {
'lodash', 'lodash',
'transform-react-remove-prop-types', 'transform-react-remove-prop-types',
'@babel/plugin-transform-react-inline-elements', '@babel/plugin-transform-react-inline-elements',
'@babel/plugin-transform-react-constant-elements', '@babel/plugin-transform-react-constant-elements'
], ],
}, },
development: {
plugins: ['react-refresh/babel']
},
test: { test: {
plugins: [ plugins: ['@babel/plugin-transform-modules-commonjs', 'dynamic-import-node']
'@babel/plugin-transform-modules-commonjs',
'dynamic-import-node',
],
}, },
}, },
}; };
...@@ -3,6 +3,8 @@ const webpack = require('webpack'); ...@@ -3,6 +3,8 @@ const webpack = require('webpack');
const slash = require('slash2'); const slash = require('slash2');
const CopyPlugin = require('copy-webpack-plugin'); const CopyPlugin = require('copy-webpack-plugin');
const cesiumSource = './node_modules/cesium/Build/Cesium'; const cesiumSource = './node_modules/cesium/Build/Cesium';
const FastRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const nodeLibs = require('node-libs-browser');
console.log(); console.log();
module.exports = options => ({ module.exports = options => ({
mode: options.mode, mode: options.mode,
...@@ -22,10 +24,6 @@ module.exports = options => ({ ...@@ -22,10 +24,6 @@ module.exports = options => ({
// 允许Cesium兼容 webpack的require方式 // 允许Cesium兼容 webpack的require方式
toUrlUndefined: true, toUrlUndefined: true,
}, },
node: {
// 解决fs模块的问题(Resolve node module use of fs)
fs: 'empty',
},
module: { module: {
rules: [ rules: [
{ {
...@@ -33,11 +31,11 @@ module.exports = options => ({ ...@@ -33,11 +31,11 @@ module.exports = options => ({
exclude: /node_modules/, exclude: /node_modules/,
use: { use: {
loader: 'babel-loader', loader: 'babel-loader',
// options: options.babelQuery, options: options.babelQuery,
options: { // options: {
presets: ['@babel/preset-typescript'], // presets: ['@babel/preset-typescript'],
plugins: ['@babel/plugin-proposal-optional-chaining'], // plugins: ['@babel/plugin-proposal-optional-chaining'],
}, // },
}, },
}, },
{ {
...@@ -178,6 +176,12 @@ module.exports = options => ({ ...@@ -178,6 +176,12 @@ module.exports = options => ({
NODE_ENV: 'development', NODE_ENV: 'development',
}), }),
new webpack.ProvidePlugin({
process: nodeLibs.process
}),
new FastRefreshPlugin({
overlay: false
}),
new CopyPlugin([ new CopyPlugin([
{ {
from: path.resolve(process.cwd(), './public'), from: path.resolve(process.cwd(), './public'),
...@@ -212,6 +216,19 @@ module.exports = options => ({ ...@@ -212,6 +216,19 @@ module.exports = options => ({
'@': path.resolve(process.cwd(), './src'), '@': path.resolve(process.cwd(), './src'),
components: path.resolve(process.cwd(), './src/components'), components: path.resolve(process.cwd(), './src/components'),
cesium: path.resolve(process.cwd(), cesiumSource), cesium: path.resolve(process.cwd(), cesiumSource),
react: path.resolve(process.cwd(), './node_modules/react'),
},
fallback: {
...Object.keys(nodeLibs).reduce((memo, key) => {
if (nodeLibs[key]) {
memo[key] = nodeLibs[key];
} else {
memo[key] = false;
}
return memo;
}, {}),
http: false,
https: false,
}, },
}, },
devtool: options.devtool, devtool: options.devtool,
......
...@@ -36,10 +36,10 @@ module.exports = require('./webpack.base.babel')({ ...@@ -36,10 +36,10 @@ module.exports = require('./webpack.base.babel')({
inject: true, // Inject all files that are generated by webpack, e.g. bundle.js inject: true, // Inject all files that are generated by webpack, e.g. bundle.js
template: 'src/index.html', template: 'src/index.html',
}), }),
new CircularDependencyPlugin({ // new CircularDependencyPlugin({
exclude: /a\.js|node_modules/, // exclude node_modules // exclude: /a\.js|node_modules/, // exclude node_modules
failOnError: false, // show a warning when there is a circular dependency // failOnError: false, // show a warning when there is a circular dependency
}), // }),
], ],
devtool: 'cheap-module-source-map', devtool: 'cheap-module-source-map',
node: { node: {
......
This diff is collapsed.
...@@ -6,9 +6,9 @@ const { addProxyMiddleware } = require('../proxy'); ...@@ -6,9 +6,9 @@ const { addProxyMiddleware } = require('../proxy');
function createWebpackMiddleware(compiler, publicPath) { function createWebpackMiddleware(compiler, publicPath) {
return webpackDevMiddleware(compiler, { return webpackDevMiddleware(compiler, {
logLevel: 'warn', // logLevel: 'warn',
publicPath, publicPath,
silent: true, // silent: true,
stats: 'errors-only', stats: 'errors-only',
}); });
} }
...@@ -25,7 +25,7 @@ module.exports = function addDevMiddlewares(app, webpackConfig) { ...@@ -25,7 +25,7 @@ module.exports = function addDevMiddlewares(app, webpackConfig) {
addProxyMiddleware(app); addProxyMiddleware(app);
// Since webpackDevMiddleware uses memory-fs internally to store build // Since webpackDevMiddleware uses memory-fs internally to store build
// artifacts, we use it instead // artifacts, we use it instead
const fs = middleware.fileSystem; const fs = middleware.context.outputFileSystem;
app.get('*', (_req, res) => { app.get('*', (_req, res) => {
fs.readFile(path.join(compiler.outputPath, 'index.html'), (err, file) => { fs.readFile(path.join(compiler.outputPath, 'index.html'), (err, file) => {
......
/* eslint-disable */
import '!file-loader?name=[name].[ext]!./images/favicon.ico'; import '!file-loader?name=[name].[ext]!./images/favicon.ico';
import './global.less'; import './global.less';
import '@babel/polyfill'; import '@babel/polyfill';
...@@ -7,15 +8,13 @@ import 'sanitize.css/sanitize.css'; ...@@ -7,15 +8,13 @@ import 'sanitize.css/sanitize.css';
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import { ArcGISMap as MapComponent } from '@wisdom-map/arcgismap';
import { ConfigProvider } from 'antd'; import { ConfigProvider } from 'antd';
import zhCN from 'antd/es/locale/zh_CN'; import zhCN from 'antd/es/locale/zh_CN';
import { ConnectedRouter } from 'connected-react-router/immutable'; import { ConnectedRouter } from 'connected-react-router/immutable';
import Immutable from 'immutable'; import Immutable from 'immutable';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { PictureWallProvider } from '@/components/Upload/context';
import configureStore from './configureStore'; import configureStore from './configureStore';
import App from './containers/App'; import App from './containers/App';
import config from './routes/config'; import config from './routes/config';
...@@ -25,30 +24,30 @@ const initialState = Immutable.Map(); ...@@ -25,30 +24,30 @@ const initialState = Immutable.Map();
const store = configureStore(initialState, history); const store = configureStore(initialState, history);
const MOUNT_NODE = document.getElementById('app'); const MOUNT_NODE = document.getElementById('app');
const render = () => { const render = () => {
ReactDOM.render( ReactDOM.render(
<Provider store={store}> <Provider store = { store }>
<ConnectedRouter history={history}> <ConnectedRouter history = { history }>
<ConfigProvider locale={zhCN}> <ConfigProvider locale = { zhCN } >
{/* <PictureWallProvider> */} { /* <PictureWallProvider> */ }
<App routesConfig={config} /> <App routesConfig = { config }/>
{/* </PictureWallProvider> */} { /* </PictureWallProvider> */ }
</ConfigProvider> </ConfigProvider>
</ConnectedRouter> </ConnectedRouter>
</Provider>, </Provider>,
MOUNT_NODE, MOUNT_NODE,
); );
}; };
if (module.hot) { if (module.hot) {
module.hot.accept(['./containers/App'], () => { module.hot.accept(['./containers/App'], () => {
ReactDOM.unmountComponentAtNode(MOUNT_NODE); ReactDOM.unmountComponentAtNode(MOUNT_NODE);
render(); render();
}); });
} }
if (MOUNT_NODE) { if (MOUNT_NODE) {
render(); render();
} }
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
require('offline-plugin/runtime').install(); // eslint-disable-line global-require require('offline-plugin/runtime').install(); // eslint-disable-line global-require
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment