@mpxjs/webpack-plugin 2.10.3-beta.7 → 2.10.3-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +71 -51
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1806,72 +1806,92 @@ try {
1806
1806
  normalModuleFactory.hooks.afterResolve.tap('MpxWebpackPlugin', ({ createData }) => {
1807
1807
  const { queryObj } = parseRequest(createData.request)
1808
1808
  const loaders = createData.loaders
1809
- if (queryObj.mpx && queryObj.mpx !== MPX_PROCESSED_FLAG) {
1810
- const type = queryObj.type
1809
+ const type = queryObj.type
1810
+ const mpxProcessFlag = queryObj.mpx && queryObj.mpx !== MPX_PROCESSED_FLAG
1811
+ const vueProcessFlag = queryObj.vue && queryObj.mpx !== MPX_PROCESSED_FLAG
1812
+ if (mpxProcessFlag || vueProcessFlag) {
1811
1813
  const extract = queryObj.extract
1812
-
1813
- if (type === 'styles') {
1814
- let insertBeforeIndex = -1
1815
- // 单次遍历收集所有索引
1814
+ if (type === 'styles' || type === 'style') {
1815
+ const loaderTypes = {
1816
+ 'node_modules/stylus-loader': -1,
1817
+ 'node_modules/sass-loader': -1,
1818
+ 'node_modules/less-loader': -1,
1819
+ 'node_modules/css-loader': -1
1820
+ }
1816
1821
  loaders.forEach((loader, index) => {
1817
1822
  const currentLoader = toPosix(loader.loader)
1818
- if (currentLoader.includes('node_modules/stylus-loader') || currentLoader.includes('node_modules/sass-loader') || currentLoader.includes('node_modules/less-loader')) {
1819
- insertBeforeIndex = index
1823
+ for (const key in loaderTypes) {
1824
+ if (currentLoader.includes(key)) {
1825
+ loaderTypes[key] = index
1826
+ break
1827
+ }
1820
1828
  }
1821
1829
  })
1830
+ const insertStripLoaders = (index) => {
1831
+ if (index !== -1) {
1832
+ loaders.splice(index, 0, { loader: styleStripConditionalPath, options: {id: 0} })
1833
+ loaders.splice(index + 2, 0, { loader: styleStripConditionalPath, options: {id: 1} })
1834
+ return true
1835
+ }
1836
+ return false
1837
+ }
1822
1838
 
1823
- if (insertBeforeIndex !== -1) {
1824
- loaders.splice(insertBeforeIndex, 0, { loader: styleStripConditionalPath })
1839
+ const priorities = ['node_modules/stylus-loader', 'node_modules/less-loader', 'node_modules/sass-loader', 'node_modules/css-loader']
1840
+ for (const loaderKey of priorities) {
1841
+ if (insertStripLoaders(loaderTypes[loaderKey])) {
1842
+ break
1843
+ }
1825
1844
  }
1826
- loaders.push({ loader: styleStripConditionalPath })
1827
1845
  }
1828
1846
 
1829
- switch (type) {
1830
- case 'styles':
1831
- case 'template': {
1832
- let insertBeforeIndex = -1
1833
- const info = typeLoaderProcessInfo[type]
1834
- loaders.forEach((loader, index) => {
1835
- const currentLoader = toPosix(loader.loader)
1836
- if (currentLoader.includes(info[0])) {
1837
- loader.loader = info[1]
1838
- insertBeforeIndex = index
1839
- } else if (currentLoader.includes(info[1])) {
1840
- insertBeforeIndex = index
1841
- }
1842
- })
1843
- if (insertBeforeIndex > -1) {
1844
- loaders.splice(insertBeforeIndex + 1, 0, {
1845
- loader: info[2]
1847
+ if (mpxProcessFlag) {
1848
+ switch (type) {
1849
+ case 'styles':
1850
+ case 'template': {
1851
+ let insertBeforeIndex = -1
1852
+ const info = typeLoaderProcessInfo[type]
1853
+ loaders.forEach((loader, index) => {
1854
+ const currentLoader = toPosix(loader.loader)
1855
+ if (currentLoader.includes(info[0])) {
1856
+ loader.loader = info[1]
1857
+ insertBeforeIndex = index
1858
+ } else if (currentLoader.includes(info[1])) {
1859
+ insertBeforeIndex = index
1860
+ }
1846
1861
  })
1862
+ if (insertBeforeIndex > -1) {
1863
+ loaders.splice(insertBeforeIndex + 1, 0, {
1864
+ loader: info[2]
1865
+ })
1866
+ }
1867
+ break
1847
1868
  }
1848
- break
1849
- }
1850
- case 'json':
1851
- if (queryObj.isTheme) {
1852
- loaders.unshift({
1853
- loader: jsonThemeCompilerPath
1854
- })
1855
- } else if (queryObj.isPlugin) {
1856
- loaders.unshift({
1857
- loader: jsonPluginCompilerPath
1858
- })
1859
- } else {
1869
+ case 'json':
1870
+ if (queryObj.isTheme) {
1871
+ loaders.unshift({
1872
+ loader: jsonThemeCompilerPath
1873
+ })
1874
+ } else if (queryObj.isPlugin) {
1875
+ loaders.unshift({
1876
+ loader: jsonPluginCompilerPath
1877
+ })
1878
+ } else {
1879
+ loaders.unshift({
1880
+ loader: jsonCompilerPath
1881
+ })
1882
+ }
1883
+ break
1884
+ case 'wxs':
1860
1885
  loaders.unshift({
1861
- loader: jsonCompilerPath
1886
+ loader: wxsLoaderPath
1862
1887
  })
1863
- }
1864
- break
1865
- case 'wxs':
1888
+ break
1889
+ }
1890
+ if (extract) {
1866
1891
  loaders.unshift({
1867
- loader: wxsLoaderPath
1892
+ loader: extractorPath
1868
1893
  })
1869
- break
1870
- }
1871
- if (extract) {
1872
- loaders.unshift({
1873
- loader: extractorPath
1874
- })
1894
+ }
1875
1895
  }
1876
1896
  createData.resource = addQuery(createData.resource, { mpx: MPX_PROCESSED_FLAG }, true)
1877
1897
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.3-beta.7",
3
+ "version": "2.10.3-beta.8",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"