@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.
- package/lib/index.js +71 -51
- 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
|
-
|
|
1810
|
-
|
|
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
|
-
|
|
1814
|
-
|
|
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
|
-
|
|
1819
|
-
|
|
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
|
-
|
|
1824
|
-
|
|
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
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
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
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
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:
|
|
1886
|
+
loader: wxsLoaderPath
|
|
1862
1887
|
})
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1888
|
+
break
|
|
1889
|
+
}
|
|
1890
|
+
if (extract) {
|
|
1866
1891
|
loaders.unshift({
|
|
1867
|
-
loader:
|
|
1892
|
+
loader: extractorPath
|
|
1868
1893
|
})
|
|
1869
|
-
|
|
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
|
}
|