通過react-app-rewired 重寫配置,訪問非根目錄

在項目根目錄下創建config-overrides.js文件

const { override, fixBabelImports } = require('customize-cra');
const path = require("path")

module.exports = override(
  fixBabelImports('import', {
    libraryName: 'antd-mobile',
    style: 'css',
  }),
  fixBabelImports('antd', {
    libraryDirectory: 'es',
    style: 'css',
  }),
  (config) => { 
  	//暴露webpack的配置 config ,evn
    const paths = require('react-scripts/config/paths');
    
    // 配置打包目錄輸出到dist/web 目錄中
    paths.appBuild = path.join(path.dirname(paths.appBuild), 'dist/web');
    config.output.path = paths.appBuild;
	
	// 配置訪問子目錄/web/
    paths.publicUrlOrPath = '/web/'
    config.output.publicPath = '/web/'
    return config
  }
);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章