npm install -g create-react-app
create-react-app hello-world
npm start
使用npm run eject将webpack配置导出
修改 webpack.config.dev.js 和 webpack.config-prod.js 配置文件
exclude: [ /\.html$/, /\.(js|jsx)$/, /\.(css|less)$/, //敲黑板,划重点 /\.json$/, /\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, ], { test: /\.(css|less)$/, //敲黑板,划重点 use: [ require.resolve(‘style-loader‘), { loader: require.resolve(‘css-loader‘), options: { importLoaders: 1, }, }, { loader: require.resolve(‘postcss-loader‘), options: { // Necessary for external CSS imports to work // https://github.com/facebookincubator/create-react-app/issues/2677 ident: ‘postcss‘, plugins: () => [ require(‘postcss-flexbugs-fixes‘), autoprefixer({ browsers: [ ‘>1%‘, ‘last 4 versions‘, ‘Firefox ESR‘, ‘not ie < 9‘, // React doesn‘t support IE8 anyway ], flexbox: ‘no-2009‘, }), ], }, }, //敲黑板,划重点 { loader: require.resolve(‘less-loader‘) // compiles Less to CSS } ], }
时间: 2024-11-05 16:04:26